diff options
author | 2017-08-23 16:24:56 +0000 | |
---|---|---|
committer | 2017-08-23 16:24:56 +0000 | |
commit | 4a228ab09e59c5dfa004df0f54df7c20eba2bc0a (patch) | |
tree | 82f731fc296f5ec32caf3ad508a59b87d61f898e /functest/tests/unit/openstack/refstack_client/test_refstack_client.py | |
parent | 172b5709ede1f32b042de621b932f6162f2d89b9 (diff) | |
parent | 1b7322ab8290b55b1869ac913442070ebe6df2a5 (diff) |
Merge "Refactor resource creation and cleanup in Tempest"
Diffstat (limited to 'functest/tests/unit/openstack/refstack_client/test_refstack_client.py')
-rw-r--r-- | functest/tests/unit/openstack/refstack_client/test_refstack_client.py | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py index c5601075..5a201318 100644 --- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py +++ b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py @@ -12,9 +12,12 @@ import pkg_resources import unittest from functest.core import testcase -from functest.opnfv_tests.openstack.refstack_client import refstack_client +from functest.opnfv_tests.openstack.refstack_client.refstack_client import \ + RefstackClient, RefstackClientParser from functest.utils.constants import CONST +from snaps.openstack.os_credentials import OSCreds + class OSRefstackClientTesting(unittest.TestCase): @@ -25,34 +28,42 @@ class OSRefstackClientTesting(unittest.TestCase): 'functest', 'opnfv_tests/openstack/refstack_client/defcore.txt') def setUp(self): - self.defaultargs = {'config': self._config, - 'testlist': self._testlist} + self.default_args = {'config': self._config, + 'testlist': self._testlist} CONST.__setattr__('OS_AUTH_URL', 'https://ip:5000/v3') CONST.__setattr__('OS_INSECURE', 'true') - self.refstackclient = refstack_client.RefstackClient() + self.os_creds = OSCreds( + username='user', password='pass', + auth_url='http://foo.com:5000/v3', project_name='bar') + + def _create_client(self): + with mock.patch('snaps.openstack.tests.openstack_tests.' + 'get_credentials', return_value=self.os_creds): + return RefstackClient() def test_run_defcore_insecure(self): insecure = '-k' config = 'tempest.conf' testlist = 'testlist' + client = self._create_client() with mock.patch('functest.opnfv_tests.openstack.refstack_client.' 'refstack_client.ft_utils.execute_command') as m: cmd = ("refstack-client test {0} -c {1} -v --test-list {2}" .format(insecure, config, testlist)) - self.refstackclient.run_defcore(config, testlist) + client.run_defcore(config, testlist) m.assert_any_call(cmd) def test_run_defcore(self): CONST.__setattr__('OS_AUTH_URL', 'http://ip:5000/v3') - refstackclient = refstack_client.RefstackClient() insecure = '' config = 'tempest.conf' testlist = 'testlist' + client = self._create_client() with mock.patch('functest.opnfv_tests.openstack.refstack_client.' 'refstack_client.ft_utils.execute_command') as m: cmd = ("refstack-client test {0} -c {1} -v --test-list {2}" .format(insecure, config, testlist)) - refstackclient.run_defcore(config, testlist) + client.run_defcore(config, testlist) m.assert_any_call(cmd) @mock.patch('functest.opnfv_tests.openstack.refstack_client.' @@ -62,7 +73,7 @@ class OSRefstackClientTesting(unittest.TestCase): mock_logger_info): self.case_name = 'refstack_defcore' self.result = 0 - self.refstackclient.parse_refstack_result() + self._create_client().parse_refstack_result() mock_logger_info.assert_called_once_with( "Testcase %s success_rate is %s%%", self.case_name, self.result) @@ -82,10 +93,11 @@ class OSRefstackClientTesting(unittest.TestCase): "success": ['tempest.api.compute [18.464988s]'], "errors": ['tempest.api.volume [0.230334s]'], "skipped": ['tempest.api.network [1.265828s]']} + client = self._create_client() with mock.patch('__builtin__.open', mock.mock_open(read_data=log_file)): - self.refstackclient.parse_refstack_result() - self.assertEqual(self.refstackclient.details, self.details) + client.parse_refstack_result() + self.assertEqual(client.details, self.details) def _get_main_kwargs(self, key=None): kwargs = {'config': self._config, @@ -96,16 +108,18 @@ class OSRefstackClientTesting(unittest.TestCase): def _test_main(self, status, *args): kwargs = self._get_main_kwargs() - self.assertEqual(self.refstackclient.main(**kwargs), status) + client = self._create_client() + self.assertEqual(client.main(**kwargs), status) if len(args) > 0: args[0].assert_called_once_with( - refstack_client.RefstackClient.result_dir) + RefstackClient.result_dir) if len(args) > 1: args def _test_main_missing_keyword(self, key): kwargs = self._get_main_kwargs(key) - self.assertEqual(self.refstackclient.main(**kwargs), + client = self._create_client() + self.assertEqual(client.main(**kwargs), testcase.TestCase.EX_RUN_ERROR) def test_main_missing_conf(self): @@ -115,10 +129,10 @@ class OSRefstackClientTesting(unittest.TestCase): self._test_main_missing_keyword('testlist') def _test_argparser(self, arg, value): - self.defaultargs[arg] = value - parser = refstack_client.RefstackClientParser() + self.default_args[arg] = value + parser = RefstackClientParser() self.assertEqual(parser.parse_args(["--{}={}".format(arg, value)]), - self.defaultargs) + self.default_args) def test_argparser_conf(self): self._test_argparser('config', self._config) @@ -127,13 +141,13 @@ class OSRefstackClientTesting(unittest.TestCase): self._test_argparser('testlist', self._testlist) def test_argparser_multiple_args(self): - self.defaultargs['config'] = self._config - self.defaultargs['testlist'] = self._testlist - parser = refstack_client.RefstackClientParser() + self.default_args['config'] = self._config + self.default_args['testlist'] = self._testlist + parser = RefstackClientParser() self.assertEqual(parser.parse_args( ["--config={}".format(self._config), "--testlist={}".format(self._testlist) - ]), self.defaultargs) + ]), self.default_args) if __name__ == "__main__": |