Adds remaining shell tests for variables

This patch includes the shell integration tests
for remaining Resources' variables implementation

Change-Id: I44dc2c3463715321f70bb48514a70906d0c864ec
Closes-Bug: 1659110
This commit is contained in:
Thomas Maddox 2017-03-06 16:37:52 +00:00
parent 0ad237ed60
commit e1f554595e
4 changed files with 308 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from cratonclient import exceptions as exc
from cratonclient.shell.v1 import cells_shell
from cratonclient.tests.integration.shell import base
from cratonclient.v1 import cells
from cratonclient.v1 import variables
class TestCellsShell(base.ShellTestCase):
@ -328,3 +329,79 @@ class TestCellsShell(base.ShellTestCase):
test_args = Namespace(id=1, region=1)
cells_shell.do_cell_delete(client, test_args)
mock_delete.assert_called_once_with(vars(test_args)['id'])
class TestCellsVarsShell(base.VariablesTestCase):
"""Test Cell Variable shell calls."""
def setUp(self):
"""Basic set up for all tests in this suite."""
super(TestCellsVarsShell, self).setUp()
# NOTE(thomasem): Mock out a client to assert craton Python API calls
self.client = mock.Mock()
self.mock_cell_resource = self.client.cells.get.return_value
self.mock_cell_resource.variables = variables.VariableManager(
self.mock_session, self.resource_url
)
def test_do_cell_vars_get_gets_correct_cell(self):
"""Assert the proper cell is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
cells_shell.do_cell_vars_get(self.client, self.test_args)
self.client.cells.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_cell_vars_delete_gets_correct_cell(self):
"""Assert the proper cell is retrieved when calling delete."""
self.test_args.variables = ['foo', 'bar']
cells_shell.do_cell_vars_delete(self.client, self.test_args)
self.client.cells.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_cell_vars_update_gets_correct_cell(self):
"""Assert the proper cell is retrieved when calling update."""
self.test_args.variables = ['foo=', 'bar=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
cells_shell.do_cell_vars_set(self.client, self.test_args)
self.client.cells.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_cell_vars_get_calls_session_get(self):
"""Assert the proper cell is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
cells_shell.do_cell_vars_get(self.client, self.test_args)
self.mock_session.get.assert_called_once_with(self.variables_url)
def test_do_cell_vars_delete_calls_session_delete(self):
"""Verify that do cell-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo', 'bar']
cells_shell.do_cell_vars_delete(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('foo', 'bar'),
params={},
)
def test_do_cell_vars_update_calls_session_put(self):
"""Verify that do cell-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo=baz', 'bar=boo', 'test=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
cells_shell.do_cell_vars_set(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('test',),
params={},
)
self.mock_session.put.assert_called_once_with(
self.variables_url,
json={'foo': 'baz', 'bar': 'boo'}
)

View File

@ -19,6 +19,7 @@ from testtools import matchers
from cratonclient.shell.v1 import clouds_shell
from cratonclient.tests.integration.shell import base
from cratonclient.v1 import clouds
from cratonclient.v1 import variables
class TestCloudsShell(base.ShellTestCase):
@ -161,3 +162,79 @@ class TestCloudsShell(base.ShellTestCase):
formatter=mock.Mock())
clouds_shell.do_cloud_update(client, invalid_input)
mock_update.assert_called_once_with(1, name='mock_cloud')
class TestCloudsVarsShell(base.VariablesTestCase):
"""Test Cloud Variable shell calls."""
def setUp(self):
"""Basic set up for all tests in this suite."""
super(TestCloudsVarsShell, self).setUp()
# NOTE(thomasem): Mock out a client to assert craton Python API calls
self.client = mock.Mock()
self.mock_cloud_resource = self.client.clouds.get.return_value
self.mock_cloud_resource.variables = variables.VariableManager(
self.mock_session, self.resource_url
)
def test_do_cloud_vars_get_gets_correct_cloud(self):
"""Assert the proper cloud is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
clouds_shell.do_cloud_vars_get(self.client, self.test_args)
self.client.clouds.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_cloud_vars_delete_gets_correct_cloud(self):
"""Assert the proper cloud is retrieved when calling delete."""
self.test_args.variables = ['foo', 'bar']
clouds_shell.do_cloud_vars_delete(self.client, self.test_args)
self.client.clouds.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_cloud_vars_update_gets_correct_cloud(self):
"""Assert the proper cloud is retrieved when calling update."""
self.test_args.variables = ['foo=', 'bar=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
clouds_shell.do_cloud_vars_set(self.client, self.test_args)
self.client.clouds.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_cloud_vars_get_calls_session_get(self):
"""Assert the proper cloud is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
clouds_shell.do_cloud_vars_get(self.client, self.test_args)
self.mock_session.get.assert_called_once_with(self.variables_url)
def test_do_cloud_vars_delete_calls_session_delete(self):
"""Verify that do cloud-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo', 'bar']
clouds_shell.do_cloud_vars_delete(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('foo', 'bar'),
params={},
)
def test_do_cloud_vars_update_calls_session_put(self):
"""Verify that do cloud-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo=baz', 'bar=boo', 'test=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
clouds_shell.do_cloud_vars_set(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('test',),
params={},
)
self.mock_session.put.assert_called_once_with(
self.variables_url,
json={'foo': 'baz', 'bar': 'boo'}
)

View File

@ -22,6 +22,7 @@ from cratonclient import exceptions as exc
from cratonclient.shell.v1 import projects_shell
from cratonclient.tests.integration.shell import base
from cratonclient.v1 import projects
from cratonclient.v1 import variables
class TestProjectsShell(base.ShellTestCase):
@ -190,3 +191,79 @@ class TestProjectsShell(base.ShellTestCase):
test_args = Namespace(id=1, region=1)
projects_shell.do_project_delete(client, test_args)
mock_delete.assert_called_once_with(vars(test_args)['id'])
class TestProjectsVarsShell(base.VariablesTestCase):
"""Test Project Variable shell calls."""
def setUp(self):
"""Basic set up for all tests in this suite."""
super(TestProjectsVarsShell, self).setUp()
# NOTE(thomasem): Mock out a client to assert craton Python API calls
self.client = mock.Mock()
self.mock_project_resource = self.client.projects.get.return_value
self.mock_project_resource.variables = variables.VariableManager(
self.mock_session, self.resource_url
)
def test_do_project_vars_get_gets_correct_project(self):
"""Assert the proper project is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
projects_shell.do_project_vars_get(self.client, self.test_args)
self.client.projects.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_project_vars_delete_gets_correct_project(self):
"""Assert the proper project is retrieved when calling delete."""
self.test_args.variables = ['foo', 'bar']
projects_shell.do_project_vars_delete(self.client, self.test_args)
self.client.projects.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_project_vars_update_gets_correct_project(self):
"""Assert the proper project is retrieved when calling update."""
self.test_args.variables = ['foo=', 'bar=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
projects_shell.do_project_vars_set(self.client, self.test_args)
self.client.projects.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_project_vars_get_calls_session_get(self):
"""Assert the proper project is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
projects_shell.do_project_vars_get(self.client, self.test_args)
self.mock_session.get.assert_called_once_with(self.variables_url)
def test_do_project_vars_delete_calls_session_delete(self):
"""Verify that do project-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo', 'bar']
projects_shell.do_project_vars_delete(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('foo', 'bar'),
params={},
)
def test_do_project_vars_update_calls_session_put(self):
"""Verify that do project-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo=baz', 'bar=boo', 'test=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
projects_shell.do_project_vars_set(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('test',),
params={},
)
self.mock_session.put.assert_called_once_with(
self.variables_url,
json={'foo': 'baz', 'bar': 'boo'}
)

View File

@ -19,6 +19,7 @@ from testtools import matchers
from cratonclient.shell.v1 import regions_shell
from cratonclient.tests.integration.shell import base
from cratonclient.v1 import regions
from cratonclient.v1 import variables
class TestRegionsShell(base.ShellTestCase):
@ -172,3 +173,79 @@ class TestRegionsShell(base.ShellTestCase):
autopaginate=False,
)
mock_list.reset_mock()
class TestRegionsVarsShell(base.VariablesTestCase):
"""Test Region Variable shell calls."""
def setUp(self):
"""Basic set up for all tests in this suite."""
super(TestRegionsVarsShell, self).setUp()
# NOTE(thomasem): Mock out a client to assert craton Python API calls
self.client = mock.Mock()
self.mock_region_resource = self.client.regions.get.return_value
self.mock_region_resource.variables = variables.VariableManager(
self.mock_session, self.resource_url
)
def test_do_region_vars_get_gets_correct_region(self):
"""Assert the proper region is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
regions_shell.do_region_vars_get(self.client, self.test_args)
self.client.regions.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_region_vars_delete_gets_correct_region(self):
"""Assert the proper region is retrieved when calling delete."""
self.test_args.variables = ['foo', 'bar']
regions_shell.do_region_vars_delete(self.client, self.test_args)
self.client.regions.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_region_vars_update_gets_correct_region(self):
"""Assert the proper region is retrieved when calling update."""
self.test_args.variables = ['foo=', 'bar=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
regions_shell.do_region_vars_set(self.client, self.test_args)
self.client.regions.get.assert_called_once_with(
vars(self.test_args)['id'])
def test_do_region_vars_get_calls_session_get(self):
"""Assert the proper region is retrieved when calling get."""
self.mock_get_response.json.return_value = \
{"variables": {"foo": "bar"}}
regions_shell.do_region_vars_get(self.client, self.test_args)
self.mock_session.get.assert_called_once_with(self.variables_url)
def test_do_region_vars_delete_calls_session_delete(self):
"""Verify that do region-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo', 'bar']
regions_shell.do_region_vars_delete(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('foo', 'bar'),
params={},
)
def test_do_region_vars_update_calls_session_put(self):
"""Verify that do region-vars-delete calls expected session.delete."""
self.test_args.variables = ['foo=baz', 'bar=boo', 'test=']
mock_resp_json = {"variables": {"foo": "bar"}}
self.mock_get_response.json.return_value = mock_resp_json
self.mock_put_response.json.return_value = mock_resp_json
regions_shell.do_region_vars_set(self.client, self.test_args)
self.mock_session.delete.assert_called_once_with(
self.variables_url,
json=('test',),
params={},
)
self.mock_session.put.assert_called_once_with(
self.variables_url,
json={'foo': 'baz', 'bar': 'boo'}
)