From 9e67d0cb981b25b26d2720f1e749628b040eb51b Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Wed, 18 May 2016 13:32:50 +0800 Subject: add pod related unittests in testAPI unittest for create/get/list pod in testAPI project JIRA: FUNCTEST-252 Signed-off-by: SerenaFeng Change-Id: Ifedb4715abffda20c93284ef58cd93f584879af8 Signed-off-by: SerenaFeng --- .../result_collection_api/tests/unit/test_base.py | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'utils/test/result_collection_api/tests/unit/test_base.py') diff --git a/utils/test/result_collection_api/tests/unit/test_base.py b/utils/test/result_collection_api/tests/unit/test_base.py index b72436eb0..98190fb94 100644 --- a/utils/test/result_collection_api/tests/unit/test_base.py +++ b/utils/test/result_collection_api/tests/unit/test_base.py @@ -1,3 +1,4 @@ +import json from tornado.web import Application from tornado.testing import AsyncHTTPTestCase @@ -7,6 +8,12 @@ import fake_pymongo class TestBase(AsyncHTTPTestCase): + headers = {'Content-Type': 'application/json; charset=UTF-8'} + + def setUp(self): + self.addCleanup(self._clear) + super(TestBase, self).setUp() + def get_app(self): return Application( [ @@ -28,9 +35,20 @@ class TestBase(AsyncHTTPTestCase): debug=True, ) - def tearDown(self): - yield fake_pymongo.pod.remove() - yield fake_pymongo.test_projects.remove() - yield fake_pymongo.test_cases.remove() - yield fake_pymongo.test_results.remove() - super(TestBase, self).tearDown() + def create(self, uri, body=None): + return self.fetch(uri, + method='POST', + body=json.dumps(body), + headers=self.headers) + + def get(self, uri): + return self.fetch(uri, + method='GET', + headers=self.headers) + + @staticmethod + def _clear(): + fake_pymongo.pod.clear() + fake_pymongo.test_projects.clear() + fake_pymongo.test_cases.clear() + fake_pymongo.test_results.clear() -- cgit 1.2.3-korg