diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-01-16 17:59:06 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-01-16 21:16:14 +0800 |
commit | 16d5fe234367a75a52dc33dae012df4f1098ae0b (patch) | |
tree | c06f0f97c3b1b6aaa0f4857d2f6f1c477f8c5801 /testapi/opnfv_testapi/tests/unit/test_base.py | |
parent | 43092f3b023fa82c93ce2cbd6e0ca5bc16da5bf1 (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 'testapi/opnfv_testapi/tests/unit/test_base.py')
-rw-r--r-- | testapi/opnfv_testapi/tests/unit/test_base.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/test_base.py b/testapi/opnfv_testapi/tests/unit/test_base.py index ff1a193..9343ab2 100644 --- a/testapi/opnfv_testapi/tests/unit/test_base.py +++ b/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() |