diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2018-03-23 08:09:30 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-03-23 08:09:30 +0000 |
commit | 4d8c8a8c8294f502fbc55bcde4033f19ddbeeea7 (patch) | |
tree | 9d52b2318c61cae8e6411c9217d6da499e697595 /testapi/testapi-client/testapiclient/tests/unit | |
parent | 1495e74a8ddc4d64cf302c6f9a9898c38069eba2 (diff) | |
parent | e5e56ebd95f24b337ec2b7140bb477c749459573 (diff) |
Merge "Add installers CRUD in testapiclient"
Diffstat (limited to 'testapi/testapi-client/testapiclient/tests/unit')
3 files changed, 80 insertions, 5 deletions
diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario.py index 2458d2b..b14cf04 100644 --- a/testapi/testapi-client/testapiclient/tests/unit/test_scenario.py +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario.py @@ -45,11 +45,6 @@ class ScenarioGetTest(ScenarioTest): args[0], self.base_url + '?version=v1&name=s1&installer=i1&project=p1') - def assert_url(self, actual_url, expected_url): - actual_parsed = parse.parse_qs(parse.urlparse(actual_url).query) - expected_parsed = parse.parse_qs(parse.urlparse(expected_url).query) - assert actual_parsed == expected_parsed - def test_get_all(self): self.get_mock.return_value = fk.FakeResponse(data=self.scenarios_rsp) scenario_get = scenarios.ScenarioGet(self.app, mock.Mock()) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_installer.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_installer.py new file mode 100644 index 0000000..2246a59 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_installer.py @@ -0,0 +1,74 @@ +import json + +from mock import mock +from six.moves.urllib import parse + +from testapiclient.cli import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class InstallerTest(utils.TestCommand): + def setUp(self): + super(InstallerTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'scenarios/{}/installers') + self.scenario_name = 's1' + self.installer_json = { + 'versions': [], + 'installer': 'test-installer', + } + self.installer_string = json.dumps(self.installer_json) + + +class InstallerCreateTest(InstallerTest): + + def setUp(self): + super(InstallerCreateTest, self).setUp() + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse(data=None) + installer_create = scenarios.InstallerCreate(self.app, mock.Mock()) + args = ['--scenario-name', 's1', self.installer_string] + verifies = [ + ('scenario_name', 's1'), + ('installer', self.installer_json)] + parsed_args = self.check_parser(installer_create, args, verifies) + installer_create.take_action(parsed_args) + self.post_mock.assert_called_once() + + +class InstallerDeleteTest(InstallerTest): + + def setUp(self): + super(InstallerDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse(data=None) + installer_delete = scenarios.InstallerDelete(self.app, mock.Mock()) + args = ['--scenario-name', 's1', 'def'] + verifies = [('scenario_name', 's1'), ('name', ['def'])] + parsed_args = self.check_parser(installer_delete, args, verifies) + installer_delete.take_action(parsed_args) + self.delete_mock.assert_called_once_with( + self.base_url.format(parsed_args.scenario_name), + data=json.dumps(['def']), + headers=clientmanager.ClientManager.headers) + + +class InstallerPutTest(InstallerTest): + + def setUp(self): + super(InstallerPutTest, self).setUp() + + def test_put_success(self): + self.put_mock.return_value = fakes.FakeResponse( + data=None) + installer_put = scenarios.InstallerPut(self.app, mock.Mock()) + args = ['--scenario-name', 's1', self.installer_string] + verifies = [ + ('scenario_name', 's1'), + ('installer', self.installer_json)] + parsed_args = self.check_parser(installer_put, args, verifies) + installer_put.take_action(parsed_args) + self.put_mock.assert_called_once() diff --git a/testapi/testapi-client/testapiclient/tests/unit/utils.py b/testapi/testapi-client/testapiclient/tests/unit/utils.py index 20f9a47..21f98c4 100644 --- a/testapi/testapi-client/testapiclient/tests/unit/utils.py +++ b/testapi/testapi-client/testapiclient/tests/unit/utils.py @@ -1,6 +1,7 @@ import httplib from mock import mock +from six.moves.urllib import parse import testtools from testapiclient.tests.unit import fakes @@ -50,3 +51,8 @@ class TestCommand(testtools.TestCase): self.assertIn(attr, parsed_args) self.assertEqual(value, getattr(parsed_args, attr)) return parsed_args + + def assert_url(self, actual_url, expected_url): + actual_parsed = parse.parse_qs(parse.urlparse(actual_url).query) + expected_parsed = parse.parse_qs(parse.urlparse(expected_url).query) + assert actual_parsed == expected_parsed |