summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client
diff options
context:
space:
mode:
Diffstat (limited to 'testapi/testapi-client')
-rw-r--r--testapi/testapi-client/setup.cfg6
-rw-r--r--testapi/testapi-client/testapiclient/cli/scenarios.py107
-rw-r--r--testapi/testapi-client/testapiclient/tests/unit/test_scenario_version.py107
3 files changed, 220 insertions, 0 deletions
diff --git a/testapi/testapi-client/setup.cfg b/testapi/testapi-client/setup.cfg
index d4f8704..b975c15 100644
--- a/testapi/testapi-client/setup.cfg
+++ b/testapi/testapi-client/setup.cfg
@@ -42,6 +42,12 @@ testapi =
scenario installer delete = testapiclient.cli.scenarios:InstallerDelete
scenario installer put = testapiclient.cli.scenarios:InstallerPut
+ scenario version create = testapiclient.cli.scenarios:VersionCreate
+ scenario version delete = testapiclient.cli.scenarios:VersionDelete
+ scenario version put = testapiclient.cli.scenarios:VersionPut
+
+ scenario version owner put = testapiclient.cli.scenarios:VersionOwnerPut
+
[egg_info]
tag_build =
tag_date = 0
diff --git a/testapi/testapi-client/testapiclient/cli/scenarios.py b/testapi/testapi-client/testapiclient/cli/scenarios.py
index 3f70772..cb8f1f3 100644
--- a/testapi/testapi-client/testapiclient/cli/scenarios.py
+++ b/testapi/testapi-client/testapiclient/cli/scenarios.py
@@ -194,3 +194,110 @@ class InstallerPut(command.Command):
resources_url(
parsed_args.scenario_name,
'installers'), parsed_args.installer)
+
+
+class VersionCreate(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(VersionCreate, self).get_parser(prog_name)
+ parser.add_argument('--scenario-name',
+ required=True,
+ help='Create version under scenario name')
+ parser.add_argument('--installer',
+ required=True,
+ help='Create version under scenario name')
+ parser.add_argument('version',
+ type=json.loads,
+ help='version create request format :\n'
+ '\'[{"owner":(string),'
+ '"version": (string),'
+ '"projects": (array[ScenarioProject])'
+ '}]\',\n')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.app.client_manager.post(
+ urlparse.query_by(
+ resources_url(parsed_args.scenario_name, 'versions'),
+ 'installer',
+ parsed_args), parsed_args.version)
+
+
+class VersionDelete(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(VersionDelete, self).get_parser(prog_name)
+ parser.add_argument('--scenario-name',
+ required=True,
+ type=str,
+ help='Delete version by scenario name')
+ parser.add_argument('--installer',
+ required=True,
+ help='Create version under scenario name')
+ parser.add_argument('name',
+ nargs='+',
+ help='Delete version by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.app.client_manager.delete(
+ urlparse.query_by(
+ resources_url(parsed_args.scenario_name, 'versions'),
+ 'installer',
+ parsed_args), parsed_args.name)
+
+
+class VersionPut(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(VersionPut, self).get_parser(prog_name)
+ parser.add_argument('--scenario-name',
+ type=str,
+ required=True,
+ help='Update installer by scenario name')
+ parser.add_argument('--installer',
+ required=True,
+ help='Update version under installer name')
+ parser.add_argument('version',
+ type=json.loads,
+ help='version update request format :\n'
+ '\'[{"owner":(string),'
+ '"version": (string),'
+ '"projects": (array[ScenarioProject])'
+ '}]\',\n')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.app.client_manager.put(
+ urlparse.query_by(
+ resources_url(parsed_args.scenario_name, 'versions'),
+ 'installer',
+ parsed_args), parsed_args.version)
+
+
+class VersionOwnerPut(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(VersionOwnerPut, self).get_parser(prog_name)
+ parser.add_argument('--scenario-name',
+ type=str,
+ required=True,
+ help='Update version by scenario name')
+ parser.add_argument('--installer',
+ required=True,
+ help='Update version under scenario name')
+ parser.add_argument('--version',
+ required=True,
+ help='Update version under scenario name')
+ parser.add_argument('owner',
+ type=json.loads,
+ help='Intaller create request format :\n'
+ '\'{"owner": ""}\',\n')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.app.client_manager.put(
+ urlparse.query_by(
+ resources_url(parsed_args.scenario_name, 'owner'),
+ ['installer', 'version'],
+ parsed_args), parsed_args.owner)
diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_version.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_version.py
new file mode 100644
index 0000000..280e9a6
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_version.py
@@ -0,0 +1,107 @@
+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 VersionTest(utils.TestCommand):
+ def setUp(self):
+ super(VersionTest, self).setUp()
+ self.base_url = parse.urljoin(self.api_url, 'scenarios/{}/versions')
+ self.scenario_name = 's1'
+ self.version_json = {
+ 'projects': [],
+ 'version': 'test-version',
+ 'owner': 'test_owner'
+ }
+ self.version_string = json.dumps(self.version_json)
+
+
+class VersionCreateTest(VersionTest):
+
+ def setUp(self):
+ super(VersionCreateTest, self).setUp()
+
+ def test_create_success(self):
+ self.post_mock.return_value = fakes.FakeResponse(data=None)
+ version_create = scenarios.VersionCreate(self.app, mock.Mock())
+ args = [
+ '--scenario-name', 's1', '--installer', 'i1', self.version_string]
+ verifies = [
+ ('scenario_name', 's1'),
+ ('installer', 'i1'),
+ ('version', self.version_json)]
+ parsed_args = self.check_parser(version_create, args, verifies)
+ version_create.take_action(parsed_args)
+ self.post_mock.assert_called_once()
+
+
+class VersionDeleteTest(VersionTest):
+
+ def setUp(self):
+ super(VersionDeleteTest, self).setUp()
+
+ def test_delete_success(self):
+ self.delete_mock.return_value = fakes.FakeResponse(data=None)
+ version_delete = scenarios.VersionDelete(self.app, mock.Mock())
+ args = ['--scenario-name', 's1', '--installer', 'i1', 'def']
+ verifies = [
+ ('scenario_name', 's1'),
+ ('installer', 'i1'),
+ ('name', ['def'])]
+ parsed_args = self.check_parser(version_delete, args, verifies)
+ version_delete.take_action(parsed_args)
+ self.delete_mock.assert_called_once_with(
+ self.base_url.format(parsed_args.scenario_name) + '?installer=i1',
+ data=json.dumps(['def']),
+ headers=clientmanager.ClientManager.headers)
+
+
+class VersionPutTest(VersionTest):
+
+ def setUp(self):
+ super(VersionPutTest, self).setUp()
+
+ def test_put_success(self):
+ self.put_mock.return_value = fakes.FakeResponse(
+ data=None)
+ version_put = scenarios.VersionPut(self.app, mock.Mock())
+ args = [
+ '--scenario-name', 's1', '--installer', 'i1', self.version_string]
+ verifies = [
+ ('scenario_name', 's1'),
+ ('installer', 'i1'),
+ ('version', self.version_json)]
+ parsed_args = self.check_parser(version_put, args, verifies)
+ version_put.take_action(parsed_args)
+ self.put_mock.assert_called_once()
+
+
+class VersionOwnerPutTest(VersionTest):
+
+ def setUp(self):
+ super(VersionOwnerPutTest, self).setUp()
+
+ def test_put_success(self):
+ self.put_mock.return_value = fakes.FakeResponse(
+ data=None)
+ version_put = scenarios.VersionOwnerPut(self.app, mock.Mock())
+ version_owner = {
+ 'owner': 'test_owner'
+ }
+ args = [
+ '--scenario-name', 's1', '--installer', 'i1',
+ '--version', 'v1', json.dumps(version_owner)]
+ verifies = [
+ ('scenario_name', 's1'),
+ ('installer', 'i1'),
+ ('version', 'v1'),
+ ('owner', version_owner)]
+ parsed_args = self.check_parser(version_put, args, verifies)
+ version_put.take_action(parsed_args)
+ self.put_mock.assert_called_once()