From d36c8831a33f0c91d5eec8817ba835393406d6bd Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Mon, 21 Aug 2017 17:27:52 +0800 Subject: change scenario owner 1 bugfix owner must be explicit in ScenarioVersion model 2 change owner of scenario 3. usage: PUT /api/v1/scenarios//owner? \ installer=& \ version= body: new owner Change-Id: I261468cd8445030b61e37e0f804b699d6205bdb0 Signed-off-by: SerenaFeng --- .../opnfv_testapi/resources/scenario_handlers.py | 36 ++++++++++++++++++++++ .../opnfv_testapi/resources/scenario_models.py | 7 +++-- .../testapi/opnfv_testapi/router/url_mappings.py | 3 +- .../tests/unit/resources/test_scenario.py | 9 +++++- 4 files changed, 51 insertions(+), 4 deletions(-) (limited to 'utils/test') diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py index 09cce7bc5..bd06400b4 100644 --- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py @@ -146,6 +146,7 @@ class ScenarioUpdater(object): ('projects', 'post'): self._update_requests_add_projects, ('projects', 'put'): self._update_requests_update_projects, ('projects', 'delete'): self._update_requests_delete_projects, + ('owner', 'put'): self._update_requests_change_owner, } updates[(item, action)](self.data) @@ -251,6 +252,11 @@ class ScenarioUpdater(object): def _update_requests_delete_projects(self, version): version.projects = self._remove_projects(version.projects) + @iter_installers + @iter_versions + def _update_requests_change_owner(self, version): + version.owner = self.body + def _filter_installers(self, installers): return self._filter('installer', installers) @@ -566,3 +572,33 @@ class ScenarioProjectsHandler(GenericScenarioUpdateHandler): locators={'scenario': scenario, 'installer': None, 'version': None}) + + +class ScenarioOwnerHandler(GenericScenarioUpdateHandler): + @swagger.operation(nickname="changeScenarioOwner") + def put(self, scenario): + """ + @description: change scenario owner + @notes: substitute all projects, delete existed ones with new provides + PUT /api/v1/scenarios//owner? \ + installer=& \ + version= + @param body: new owner + @type body: L{string} + @in body: body + @param installer: installer type + @type installer: L{string} + @in installer: query + @required installer: True + @param version: version + @type version: L{string} + @in version: query + @required version: True + @return 200: change owner success. + @raise 404: scenario/installer/version not existed + """ + self.do_update('owner', + 'put', + locators={'scenario': scenario, + 'installer': None, + 'version': None}) diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py index 9f5a07434..7d0770759 100644 --- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py @@ -74,7 +74,8 @@ class ScenarioVersion(models.ModelBase): @property projects: @ptype projects: C{list} of L{ScenarioProject} """ - def __init__(self, version=None, projects=None): + def __init__(self, owner=None, version=None, projects=None): + self.owner = owner self.version = version self.projects = list_default(projects) @@ -83,7 +84,9 @@ class ScenarioVersion(models.ModelBase): return {'projects': ScenarioProject} def __eq__(self, other): - return [self.version == other.version and self._projects_eq(other)] + return [self.version == other.version and + self.owner == other.owner and + self._projects_eq(other)] def __ne__(self, other): return not self.__eq__(other) diff --git a/utils/test/testapi/opnfv_testapi/router/url_mappings.py b/utils/test/testapi/opnfv_testapi/router/url_mappings.py index dc3b656a5..9c9556c6b 100644 --- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py +++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py @@ -60,9 +60,10 @@ mappings = [ scenario_handlers.ScenarioTIsHandler), (r"/api/v1/scenarios/([^/]+)/customs", scenario_handlers.ScenarioCustomsHandler), - (r"/api/v1/scenarios/([^/]+)/projects", scenario_handlers.ScenarioProjectsHandler), + (r"/api/v1/scenarios/([^/]+)/owner", + scenario_handlers.ScenarioOwnerHandler), # static path (r'/(.*\.(css|png|gif|js|html|json|map|woff2|woff|ttf))', diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py index 8c54e7d74..466caaf13 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py @@ -172,7 +172,7 @@ class TestScenarioUpdate(TestScenarioBase): def _update_url_fixture(xstep): def wrapper(self, *args, **kwargs): locator = None - if item == 'projects': + if item in ['projects', 'owner']: locator = 'installer={}&version={}'.format( self.installer, self.version) @@ -294,6 +294,13 @@ class TestScenarioUpdate(TestScenarioBase): projects) return deletes, scenario + @update_url_fixture('owner') + @update_partial('_update', '_success') + def test_changeOwner(self, scenario): + new_owner = 'new_owner' + scenario['installers'][0]['versions'][0]['owner'] = 'www' + return new_owner, scenario + def _add(self, update_req, new_scenario): return self.post_direct_url(self.update_url, update_req) -- cgit 1.2.3-korg