summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
diff options
context:
space:
mode:
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.py36
1 files changed, 25 insertions, 11 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 fc780e44c..b955f4a5a 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
@@ -7,21 +7,23 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import json
+from os import path
-from tornado.web import Application
-from tornado.testing import AsyncHTTPTestCase
+import mock
+from tornado import testing
-from opnfv_testapi.router import url_mappings
-from opnfv_testapi.resources.models import CreateResponse
import fake_pymongo
+from opnfv_testapi.cmd import server
+from opnfv_testapi.resources import models
-class TestBase(AsyncHTTPTestCase):
+class TestBase(testing.AsyncHTTPTestCase):
headers = {'Content-Type': 'application/json; charset=UTF-8'}
def setUp(self):
+ self._patch_server()
self.basePath = ''
- self.create_res = CreateResponse
+ self.create_res = models.CreateResponse
self.get_res = None
self.list_res = None
self.update_res = None
@@ -30,12 +32,24 @@ class TestBase(AsyncHTTPTestCase):
self.addCleanup(self._clear)
super(TestBase, self).setUp()
+ def tearDown(self):
+ self.db_patcher.stop()
+
+ def _patch_server(self):
+ server.parse_config([
+ '--config-file',
+ path.join(path.dirname(__file__), 'common/normal.ini')
+ ])
+ self.db_patcher = mock.patch('opnfv_testapi.cmd.server.get_db',
+ self._fake_pymongo)
+ self.db_patcher.start()
+
+ @staticmethod
+ def _fake_pymongo():
+ return fake_pymongo
+
def get_app(self):
- return Application(
- url_mappings.mappings,
- db=fake_pymongo,
- debug=True,
- )
+ return server.make_app()
def create_d(self, *args):
return self.create(self.req_d, *args)