Ensure consistent vars shell behavior across resources
This patch DRYs out the variables shell test cases even further to ensure the same pattern of behavior across all resources' variables shell implementations. Closes-Bug: 1670446 Change-Id: I69cc3ac025dfdcd0b0bbe2084125014cb7f659e9
This commit is contained in:
		@@ -17,6 +17,7 @@ import six
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from cratonclient.shell import main
 | 
					from cratonclient.shell import main
 | 
				
			||||||
from cratonclient.tests import base
 | 
					from cratonclient.tests import base
 | 
				
			||||||
 | 
					from cratonclient.v1 import variables
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ShellTestCase(base.TestCase):
 | 
					class ShellTestCase(base.TestCase):
 | 
				
			||||||
@@ -41,9 +42,11 @@ class VariablesTestCase(base.TestCase):
 | 
				
			|||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        """Basic set up for all tests in this suite."""
 | 
					        """Basic set up for all tests in this suite."""
 | 
				
			||||||
        super(VariablesTestCase, self).setUp()
 | 
					        super(VariablesTestCase, self).setUp()
 | 
				
			||||||
        self.resource_url = 'http://127.0.0.1/v1/hosts/1'
 | 
					        self.resources = '{}s'.format(self.resource)
 | 
				
			||||||
 | 
					        self.resource_url = 'http://127.0.0.1/v1/{}/{}' \
 | 
				
			||||||
 | 
					            .format(self.resources, self.resource_id)
 | 
				
			||||||
        self.variables_url = '{}/variables'.format(self.resource_url)
 | 
					        self.variables_url = '{}/variables'.format(self.resource_url)
 | 
				
			||||||
        self.test_args = Namespace(id=1, formatter=mock.Mock())
 | 
					        self.test_args = Namespace(id=self.resource_id, formatter=mock.Mock())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # NOTE(thomasem): Make all calls seem like they come from CLI args
 | 
					        # NOTE(thomasem): Make all calls seem like they come from CLI args
 | 
				
			||||||
        self.stdin_patcher = \
 | 
					        self.stdin_patcher = \
 | 
				
			||||||
@@ -59,7 +62,82 @@ class VariablesTestCase(base.TestCase):
 | 
				
			|||||||
        self.mock_delete_response = self.mock_session.delete.return_value
 | 
					        self.mock_delete_response = self.mock_session.delete.return_value
 | 
				
			||||||
        self.mock_delete_response.status_code = 204
 | 
					        self.mock_delete_response.status_code = 204
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # NOTE(thomasem): Mock out a client to assert craton Python API calls
 | 
				
			||||||
 | 
					        self.client = mock.Mock()
 | 
				
			||||||
 | 
					        mock_resource = \
 | 
				
			||||||
 | 
					            getattr(self.client, self.resources).get.return_value
 | 
				
			||||||
 | 
					        mock_resource.variables = variables.VariableManager(
 | 
				
			||||||
 | 
					            self.mock_session, self.resource_url
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def tearDown(self):
 | 
					    def tearDown(self):
 | 
				
			||||||
        """Clean up between tests."""
 | 
					        """Clean up between tests."""
 | 
				
			||||||
        super(VariablesTestCase, self).tearDown()
 | 
					        super(VariablesTestCase, self).tearDown()
 | 
				
			||||||
        self.stdin_patcher.stop()
 | 
					        self.stdin_patcher.stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _get_shell_func_for(self, suffix):
 | 
				
			||||||
 | 
					        return getattr(
 | 
				
			||||||
 | 
					            self.shell,
 | 
				
			||||||
 | 
					            'do_{}_vars_{}'.format(self.resource, suffix)
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_do_vars_get_gets_correct_resource(self):
 | 
				
			||||||
 | 
					        """Assert the proper resource is retrieved when calling get."""
 | 
				
			||||||
 | 
					        self.mock_get_response.json.return_value = \
 | 
				
			||||||
 | 
					            {"variables": {"foo": "bar"}}
 | 
				
			||||||
 | 
					        self._get_shell_func_for('get')(self.client, self.test_args)
 | 
				
			||||||
 | 
					        getattr(self.client, self.resources).get.assert_called_once_with(
 | 
				
			||||||
 | 
					            vars(self.test_args)['id'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_do_vars_delete_gets_correct_resource(self):
 | 
				
			||||||
 | 
					        """Assert the proper resource is retrieved when calling delete."""
 | 
				
			||||||
 | 
					        self.test_args.variables = ['foo', 'bar']
 | 
				
			||||||
 | 
					        self._get_shell_func_for('delete')(self.client, self.test_args)
 | 
				
			||||||
 | 
					        getattr(self.client, self.resources).get.assert_called_once_with(
 | 
				
			||||||
 | 
					            vars(self.test_args)['id'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_do_vars_update_gets_correct_resource(self):
 | 
				
			||||||
 | 
					        """Assert the proper resource 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self._get_shell_func_for('set')(self.client, self.test_args)
 | 
				
			||||||
 | 
					        getattr(self.client, self.resources).get.assert_called_once_with(
 | 
				
			||||||
 | 
					            vars(self.test_args)['id'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_do_vars_get_calls_session_get(self):
 | 
				
			||||||
 | 
					        """Assert the proper resource is retrieved when calling get."""
 | 
				
			||||||
 | 
					        self.mock_get_response.json.return_value = \
 | 
				
			||||||
 | 
					            {"variables": {"foo": "bar"}}
 | 
				
			||||||
 | 
					        self._get_shell_func_for('get')(self.client, self.test_args)
 | 
				
			||||||
 | 
					        self.mock_session.get.assert_called_once_with(self.variables_url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_do_vars_delete_calls_session_delete(self):
 | 
				
			||||||
 | 
					        """Verify that <resource>-vars-delete calls expected session.delete."""
 | 
				
			||||||
 | 
					        self.test_args.variables = ['foo', 'bar']
 | 
				
			||||||
 | 
					        self._get_shell_func_for('delete')(self.client, self.test_args)
 | 
				
			||||||
 | 
					        self.mock_session.delete.assert_called_once_with(
 | 
				
			||||||
 | 
					            self.variables_url,
 | 
				
			||||||
 | 
					            json=('foo', 'bar'),
 | 
				
			||||||
 | 
					            params={},
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_do_vars_update_calls_session_put(self):
 | 
				
			||||||
 | 
					        """Verify that <resource>-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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self._get_shell_func_for('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'}
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,6 @@ from cratonclient import exceptions as exc
 | 
				
			|||||||
from cratonclient.shell.v1 import cells_shell
 | 
					from cratonclient.shell.v1 import cells_shell
 | 
				
			||||||
from cratonclient.tests.integration.shell import base
 | 
					from cratonclient.tests.integration.shell import base
 | 
				
			||||||
from cratonclient.v1 import cells
 | 
					from cratonclient.v1 import cells
 | 
				
			||||||
from cratonclient.v1 import variables
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestCellsShell(base.ShellTestCase):
 | 
					class TestCellsShell(base.ShellTestCase):
 | 
				
			||||||
@@ -334,74 +333,6 @@ class TestCellsShell(base.ShellTestCase):
 | 
				
			|||||||
class TestCellsVarsShell(base.VariablesTestCase):
 | 
					class TestCellsVarsShell(base.VariablesTestCase):
 | 
				
			||||||
    """Test Cell Variable shell calls."""
 | 
					    """Test Cell Variable shell calls."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    resource = 'cell'
 | 
				
			||||||
        """Basic set up for all tests in this suite."""
 | 
					    resource_id = '1'
 | 
				
			||||||
        super(TestCellsVarsShell, self).setUp()
 | 
					    shell = cells_shell
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # 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'}
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ from testtools import matchers
 | 
				
			|||||||
from cratonclient.shell.v1 import clouds_shell
 | 
					from cratonclient.shell.v1 import clouds_shell
 | 
				
			||||||
from cratonclient.tests.integration.shell import base
 | 
					from cratonclient.tests.integration.shell import base
 | 
				
			||||||
from cratonclient.v1 import clouds
 | 
					from cratonclient.v1 import clouds
 | 
				
			||||||
from cratonclient.v1 import variables
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestCloudsShell(base.ShellTestCase):
 | 
					class TestCloudsShell(base.ShellTestCase):
 | 
				
			||||||
@@ -167,74 +166,6 @@ class TestCloudsShell(base.ShellTestCase):
 | 
				
			|||||||
class TestCloudsVarsShell(base.VariablesTestCase):
 | 
					class TestCloudsVarsShell(base.VariablesTestCase):
 | 
				
			||||||
    """Test Cloud Variable shell calls."""
 | 
					    """Test Cloud Variable shell calls."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    resource = 'cloud'
 | 
				
			||||||
        """Basic set up for all tests in this suite."""
 | 
					    resource_id = '1'
 | 
				
			||||||
        super(TestCloudsVarsShell, self).setUp()
 | 
					    shell = clouds_shell
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # 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'}
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,6 @@ from cratonclient import exceptions as exc
 | 
				
			|||||||
from cratonclient.shell.v1 import hosts_shell
 | 
					from cratonclient.shell.v1 import hosts_shell
 | 
				
			||||||
from cratonclient.tests.integration.shell import base
 | 
					from cratonclient.tests.integration.shell import base
 | 
				
			||||||
from cratonclient.v1 import hosts
 | 
					from cratonclient.v1 import hosts
 | 
				
			||||||
from cratonclient.v1 import variables
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestHostsShell(base.ShellTestCase):
 | 
					class TestHostsShell(base.ShellTestCase):
 | 
				
			||||||
@@ -395,74 +394,6 @@ class TestHostsShell(base.ShellTestCase):
 | 
				
			|||||||
class TestHostsVarsShell(base.VariablesTestCase):
 | 
					class TestHostsVarsShell(base.VariablesTestCase):
 | 
				
			||||||
    """Test Host Variable shell calls."""
 | 
					    """Test Host Variable shell calls."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    resource = 'host'
 | 
				
			||||||
        """Basic set up for all tests in this suite."""
 | 
					    resource_id = '1'
 | 
				
			||||||
        super(TestHostsVarsShell, self).setUp()
 | 
					    shell = hosts_shell
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # NOTE(thomasem): Mock out a client to assert craton Python API calls
 | 
					 | 
				
			||||||
        self.client = mock.Mock()
 | 
					 | 
				
			||||||
        self.mock_host_resource = self.client.hosts.get.return_value
 | 
					 | 
				
			||||||
        self.mock_host_resource.variables = variables.VariableManager(
 | 
					 | 
				
			||||||
            self.mock_session, self.resource_url
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_do_host_vars_get_gets_correct_host(self):
 | 
					 | 
				
			||||||
        """Assert the proper host is retrieved when calling get."""
 | 
					 | 
				
			||||||
        self.mock_get_response.json.return_value = \
 | 
					 | 
				
			||||||
            {"variables": {"foo": "bar"}}
 | 
					 | 
				
			||||||
        hosts_shell.do_host_vars_get(self.client, self.test_args)
 | 
					 | 
				
			||||||
        self.client.hosts.get.assert_called_once_with(
 | 
					 | 
				
			||||||
            vars(self.test_args)['id'])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_do_host_vars_delete_gets_correct_host(self):
 | 
					 | 
				
			||||||
        """Assert the proper host is retrieved when calling delete."""
 | 
					 | 
				
			||||||
        self.test_args.variables = ['foo', 'bar']
 | 
					 | 
				
			||||||
        hosts_shell.do_host_vars_delete(self.client, self.test_args)
 | 
					 | 
				
			||||||
        self.client.hosts.get.assert_called_once_with(
 | 
					 | 
				
			||||||
            vars(self.test_args)['id'])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_do_host_vars_update_gets_correct_host(self):
 | 
					 | 
				
			||||||
        """Assert the proper host 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
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        hosts_shell.do_host_vars_set(self.client, self.test_args)
 | 
					 | 
				
			||||||
        self.client.hosts.get.assert_called_once_with(
 | 
					 | 
				
			||||||
            vars(self.test_args)['id'])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_do_host_vars_get_calls_session_get(self):
 | 
					 | 
				
			||||||
        """Assert the proper host is retrieved when calling get."""
 | 
					 | 
				
			||||||
        self.mock_get_response.json.return_value = \
 | 
					 | 
				
			||||||
            {"variables": {"foo": "bar"}}
 | 
					 | 
				
			||||||
        hosts_shell.do_host_vars_get(self.client, self.test_args)
 | 
					 | 
				
			||||||
        self.mock_session.get.assert_called_once_with(self.variables_url)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_do_host_vars_delete_calls_session_delete(self):
 | 
					 | 
				
			||||||
        """Verify that do host-vars-delete calls expected session.delete."""
 | 
					 | 
				
			||||||
        self.test_args.variables = ['foo', 'bar']
 | 
					 | 
				
			||||||
        hosts_shell.do_host_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_host_vars_update_calls_session_put(self):
 | 
					 | 
				
			||||||
        """Verify that do host-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
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        hosts_shell.do_host_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'}
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,6 @@ from cratonclient import exceptions as exc
 | 
				
			|||||||
from cratonclient.shell.v1 import projects_shell
 | 
					from cratonclient.shell.v1 import projects_shell
 | 
				
			||||||
from cratonclient.tests.integration.shell import base
 | 
					from cratonclient.tests.integration.shell import base
 | 
				
			||||||
from cratonclient.v1 import projects
 | 
					from cratonclient.v1 import projects
 | 
				
			||||||
from cratonclient.v1 import variables
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestProjectsShell(base.ShellTestCase):
 | 
					class TestProjectsShell(base.ShellTestCase):
 | 
				
			||||||
@@ -196,74 +195,6 @@ class TestProjectsShell(base.ShellTestCase):
 | 
				
			|||||||
class TestProjectsVarsShell(base.VariablesTestCase):
 | 
					class TestProjectsVarsShell(base.VariablesTestCase):
 | 
				
			||||||
    """Test Project Variable shell calls."""
 | 
					    """Test Project Variable shell calls."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    resource = 'project'
 | 
				
			||||||
        """Basic set up for all tests in this suite."""
 | 
					    resource_id = 'c9f10eca-66ac-4c27-9c13-9d01e65f96b4'
 | 
				
			||||||
        super(TestProjectsVarsShell, self).setUp()
 | 
					    shell = projects_shell
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # 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'}
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ from testtools import matchers
 | 
				
			|||||||
from cratonclient.shell.v1 import regions_shell
 | 
					from cratonclient.shell.v1 import regions_shell
 | 
				
			||||||
from cratonclient.tests.integration.shell import base
 | 
					from cratonclient.tests.integration.shell import base
 | 
				
			||||||
from cratonclient.v1 import regions
 | 
					from cratonclient.v1 import regions
 | 
				
			||||||
from cratonclient.v1 import variables
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestRegionsShell(base.ShellTestCase):
 | 
					class TestRegionsShell(base.ShellTestCase):
 | 
				
			||||||
@@ -178,74 +177,6 @@ class TestRegionsShell(base.ShellTestCase):
 | 
				
			|||||||
class TestRegionsVarsShell(base.VariablesTestCase):
 | 
					class TestRegionsVarsShell(base.VariablesTestCase):
 | 
				
			||||||
    """Test Region Variable shell calls."""
 | 
					    """Test Region Variable shell calls."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    resource = 'region'
 | 
				
			||||||
        """Basic set up for all tests in this suite."""
 | 
					    resource_id = '1'
 | 
				
			||||||
        super(TestRegionsVarsShell, self).setUp()
 | 
					    shell = regions_shell
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # 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'}
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user