summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/tests/unit/resources/test_base.py
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
commit2a2585dd89fe1c642c892ea12c52bf4119c4c93e (patch)
tree63f47198130df1293c123862c4dce06ff3b5f283 /testapi/opnfv_testapi/tests/unit/resources/test_base.py
parent017153393c1055608d33dd3169b02469e29191b7 (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 'testapi/opnfv_testapi/tests/unit/resources/test_base.py')
-rw-r--r--testapi/opnfv_testapi/tests/unit/resources/test_base.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/resources/test_base.py b/testapi/opnfv_testapi/tests/unit/resources/test_base.py
index aa6b835..77a8d18 100644
--- a/testapi/opnfv_testapi/tests/unit/resources/test_base.py
+++ b/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):