('versions', 'post'): self._update_requests_add_versions,
('versions', 'put'): self._update_requests_update_versions,
('versions', 'delete'): self._update_requests_delete_versions,
+ ('installers', 'post'): self._update_requests_add_installers,
+ ('installers', 'put'): self._update_requests_update_installers,
+ ('installers', 'delete'): self._update_requests_delete_installers,
}
updates[(item, action)](self.data)
def _update_requests_delete_versions(self, installer):
installer.versions = self._remove_versions(installer.versions)
+ def _update_requests_add_installers(self, scenario):
+ scenario.installers = self._update_with_body(models.ScenarioInstaller,
+ 'installer',
+ scenario.installers)
+
+ def _update_requests_update_installers(self, scenario):
+ scenario.installers = self._update_with_body(models.ScenarioInstaller,
+ 'installer',
+ list())
+
+ def _update_requests_delete_installers(self, scenario):
+ scenario.installers = self._remove_installers(scenario.installers)
+
def _update_with_body(self, clazz, field, withs):
exists = list()
malformat = list()
def _filter_installers(self, installers):
return self._filter('installer', installers)
+ def _remove_installers(self, installers):
+ return self._remove('installer', installers)
+
def _filter_versions(self, versions):
return self._filter('version', versions)
'delete',
locators={'scenario': scenario,
'installer': None})
+
+
+class ScenarioInstallersHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addInstallersUnderScenario")
+ def post(self, scenario):
+ """
+ @description: add installers to scenario
+ @notes: add one or multiple installers
+ POST /api/v1/scenarios/<scenario_name>/installers
+ @param body: installers to be added
+ @type body: C{list} of L{ScenarioInstaller}
+ @in body: body
+ @return 200: installers are added.
+ @raise 400: bad schema
+ @raise 409: conflict, installer already exists
+ @raise 404: scenario not exist
+ """
+ self.do_update('installers',
+ 'post',
+ locators={'scenario': scenario})
+
+ @swagger.operation(nickname="updateInstallersUnderScenario")
+ def put(self, scenario):
+ """
+ @description: replace all installers
+ @notes: substitute all installers as a totality
+ PUT /api/v1/scenarios/<scenario_name>/installers
+ @param body: new installers
+ @type body: C{list} of L{ScenarioInstaller}
+ @in body: body
+ @return 200: replace versions success.
+ @raise 400: bad schema
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('installers',
+ 'put',
+ locators={'scenario': scenario})
+
+ @swagger.operation(nickname="deleteInstallersUnderScenario")
+ def delete(self, scenario):
+ """
+ @description: delete one or multiple installers
+ @notes: delete one or multiple installers
+ DELETE /api/v1/scenarios/<scenario_name>/installers
+ @param body: installers(names) to be deleted
+ @type body: C{list} of L{string}
+ @in body: body
+ @return 200: delete versions success.
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('installers',
+ 'delete',
+ locators={'scenario': scenario})
scenario_handlers.ScenarioOwnerHandler),
(r"/api/v1/scenarios/([^/]+)/versions",
scenario_handlers.ScenarioVersionsHandler),
+ (r"/api/v1/scenarios/([^/]+)/installers",
+ scenario_handlers.ScenarioInstallersHandler),
# static path
(r'/(.*\.(css|png|gif|js|html|json|map|woff2|woff|ttf))',
def update_url_fixture(item):
def _update_url_fixture(xstep):
def wrapper(self, *args, **kwargs):
+ self.update_url = '{}/{}'.format(self.scenario_url, item)
locator = None
if item in ['projects', 'owner']:
locator = 'installer={}&version={}'.format(
locator = 'installer={}'.format(
self.installer)
- self.update_url = '{}/{}?{}'.format(self.scenario_url,
- item,
- locator)
+ if locator:
+ self.update_url = '{}?{}'.format(self.update_url, locator)
+
xstep(self, *args, **kwargs)
return wrapper
return _update_url_fixture
@update_url_fixture('projects')
@update_partial('_update', '_conflict')
def test_updateProjects_duplicated(self):
- update1 = models.ScenarioProject(project='qtip').format()
- update2 = models.ScenarioProject(project='qtip').format()
- return [update1, update2]
+ update = models.ScenarioProject(project='qtip').format()
+ return [update, update]
@update_url_fixture('projects')
@update_partial('_update', '_bad_request')
@update_url_fixture('versions')
@update_partial('_update', '_conflict')
def test_updateVersions_duplicated(self):
- update1 = models.ScenarioVersion(version='euphrates').format()
- update2 = models.ScenarioVersion(version='euphrates').format()
- return [update1, update2]
+ update = models.ScenarioVersion(version='euphrates').format()
+ return [update, update]
@update_url_fixture('versions')
@update_partial('_update', '_bad_request')
versions)
return deletes
+ @update_url_fixture('installers')
+ @update_partial('_add', '_success')
+ def test_addInstallers_succ(self):
+ add = models.ScenarioInstaller(installer='daisy').format()
+ self.req_d['installers'].append(add)
+ return [add]
+
+ @update_url_fixture('installers')
+ @update_partial('_add', '_conflict')
+ def test_addInstallers_already_exist(self):
+ add = models.ScenarioInstaller(installer='apex').format()
+ return [add]
+
+ @update_url_fixture('installers')
+ @update_partial('_add', '_bad_request')
+ def test_addInstallers_bad_schema(self):
+ add = models.ScenarioInstaller(installer='daisy').format()
+ add['not_exist'] = 'not_exist'
+ return [add]
+
+ @update_url_fixture('installers')
+ @update_partial('_update', '_success')
+ def test_updateInstallers_succ(self):
+ update = models.ScenarioInstaller(installer='daisy').format()
+ self.req_d['installers'] = [update]
+ return [update]
+
+ @update_url_fixture('installers')
+ @update_partial('_update', '_conflict')
+ def test_updateInstallers_duplicated(self):
+ update = models.ScenarioInstaller(installer='daisy').format()
+ return [update, update]
+
+ @update_url_fixture('installers')
+ @update_partial('_update', '_bad_request')
+ def test_updateInstallers_bad_schema(self):
+ update = models.ScenarioInstaller(installer='daisy').format()
+ update['not_exist'] = 'not_exist'
+ return [update]
+
+ @update_url_fixture('installers')
+ @update_partial('_delete', '_success')
+ def test_deleteInstallers(self):
+ deletes = ['apex']
+ installers = self.req_d['installers']
+ self.req_d['installers'] = filter(
+ lambda f: f['installer'] != 'apex',
+ installers)
+ return deletes
+
def _add(self, update_req):
return self.post_direct_url(self.update_url, update_req)