summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-01-16 17:59:06 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-01-16 21:16:14 +0800
commitc4fe6bffd4c09a70f35a116919a6b0116a6e2a3c (patch)
treec9617b3673535644de6078625f01c886af2eb824 /utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
parent7af92e09cf13a7184b49ffebc32e274fe46f0faa (diff)
implement create scenario and add unittest
JIRA: RELENG-163 Change-Id: Id715a2e5de1022cfd0a745505771d250935541bd Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/tests/unit/test_base.py')
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/test_base.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
index ff1a1932c..9343ab2fb 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
@@ -47,11 +47,11 @@ class TestBase(AsyncHTTPTestCase):
return self.create_help(self.basePath, req, *args)
def create_help(self, uri, req, *args):
- if req:
- req = req.format()
+ if req and not isinstance(req, str):
+ req = json.dumps(req.format())
res = self.fetch(self._update_uri(uri, *args),
method='POST',
- body=json.dumps(req),
+ body=req if req else json.dumps(None),
headers=self.headers)
return self._get_return(res, self.create_res)
@@ -123,9 +123,17 @@ class TestBase(AsyncHTTPTestCase):
self.assertIn(self.basePath, body.href)
def assert_create_body(self, body, req=None, *args):
+ import inspect
if not req:
req = self.req_d
- new_args = args + tuple([req.name])
+ resource_name = ''
+ if inspect.isclass(req):
+ resource_name = req.name
+ elif isinstance(req, dict):
+ resource_name = req['name']
+ elif isinstance(req, str):
+ resource_name = json.loads(req)['name']
+ new_args = args + tuple([resource_name])
self.assertIn(self._get_uri(*new_args), body.href)
@staticmethod
@@ -134,3 +142,4 @@ class TestBase(AsyncHTTPTestCase):
fake_pymongo.projects.clear()
fake_pymongo.testcases.clear()
fake_pymongo.results.clear()
+ fake_pymongo.scenarios.clear()