From d9950c167886a2df6684de313d95f5aa3f8d89ed Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Thu, 17 Aug 2017 18:43:56 +0800 Subject: update customs in scenario 1) post to add one or multiple test cases 2) update to substitute all the test cases 3) delete with body to delete one or multiple test cases 4) to facilitate the process and response body usually useless, if update success all updates(scores/trust_indicators/customs), return 200 with no response body Change-Id: I5148f172989fa8e0e70ffed92ee383c0520dbb41 Signed-off-by: SerenaFeng --- .../tests/unit/resources/test_base.py | 33 ++++++++++++++----- .../tests/unit/resources/test_scenario.py | 38 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-) (limited to 'utils/test/testapi/opnfv_testapi/tests/unit/resources') diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py index aa6b83544..77a8d18c1 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py @@ -92,21 +92,35 @@ class TestBase(testing.AsyncHTTPTestCase): headers=self.headers) return self._get_return(res, self.list_res) - def update(self, new=None, *args): - if new: + def update_direct_url(self, url, new=None): + if new and hasattr(new, 'format'): new = new.format() - res = self.fetch(self._get_uri(*args), + res = self.fetch(url, method='PUT', body=json.dumps(new), headers=self.headers) return self._get_return(res, self.update_res) - def delete(self, *args): - res = self.fetch(self._get_uri(*args), - method='DELETE', - headers=self.headers) + def update(self, new=None, *args): + return self.update_direct_url(self._get_uri(*args), new) + + def delete_direct_url(self, url, body): + if body: + res = self.fetch(url, + method='DELETE', + body=json.dumps(body), + headers=self.headers, + allow_nonstandard_methods=True) + else: + res = self.fetch(url, + method='DELETE', + headers=self.headers) + return res.code, res.body + def delete(self, *args): + return self.delete_direct_url(self._get_uri(*args), None) + @staticmethod def _get_valid_args(*args): new_args = tuple(['%s' % arg for arg in args if arg is not None]) @@ -132,7 +146,10 @@ class TestBase(testing.AsyncHTTPTestCase): def _get_return(self, res, cls): code = res.code body = res.body - return code, self._get_return_body(code, body, cls) + if body: + return code, self._get_return_body(code, body, cls) + else: + return code, None @staticmethod def _get_return_body(code, body, cls): 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 0558ea30d..ba45f4bf8 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 @@ -200,9 +200,47 @@ class TestScenarioUpdate(TestScenarioBase): return add, scenario + @update_partial('_add', '_success') + def test_addCustoms(self, scenario): + add = ['odl', 'parser', 'vping_ssh'] + projects = scenario['installers'][0]['versions'][0]['projects'] + functest = filter(lambda f: f['project'] == 'functest', projects)[0] + functest['customs'] = list(set(functest['customs'] + add)) + self.update_url = '{}/customs?{}'.format(self.scenario_url, + self.locate_project) + return add, scenario + + @update_partial('_update', '_success') + def test_updateCustoms(self, scenario): + news = ['odl', 'parser', 'vping_ssh'] + projects = scenario['installers'][0]['versions'][0]['projects'] + functest = filter(lambda f: f['project'] == 'functest', projects)[0] + functest['customs'] = news + self.update_url = '{}/customs?{}'.format(self.scenario_url, + self.locate_project) + + return news, scenario + + @update_partial('_delete', '_success') + def test_deleteCustoms(self, scenario): + obsoletes = ['vping_ssh'] + projects = scenario['installers'][0]['versions'][0]['projects'] + functest = filter(lambda f: f['project'] == 'functest', projects)[0] + functest['customs'] = ['healthcheck'] + self.update_url = '{}/customs?{}'.format(self.scenario_url, + self.locate_project) + + return obsoletes, scenario + def _add(self, update_req, new_scenario): return self.post_direct_url(self.update_url, update_req) + def _update(self, update_req, new_scenario): + return self.update_direct_url(self.update_url, update_req) + + def _delete(self, update_req, new_scenario): + return self.delete_direct_url(self.update_url, update_req) + def _success(self, status, new_scenario): self.assertEqual(status, httplib.OK) self._get_and_assert(new_scenario.get('name'), new_scenario) -- cgit 1.2.3-korg