summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/tests/unit/resources
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-08-17 18:43:56 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-08-18 15:41:25 +0800
commitd9950c167886a2df6684de313d95f5aa3f8d89ed (patch)
treef1ca0afdd35b333af44c5b837eb19db10b855557 /utils/test/testapi/opnfv_testapi/tests/unit/resources
parent1fce3258fae5cf6a99af93b6ea026fec4d839cd6 (diff)
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 <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/tests/unit/resources')
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py33
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py38
2 files changed, 63 insertions, 8 deletions
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)