X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Ftests%2Funit%2Ftest_base.py;h=a6e733914f1fdee4270d64ee5fdcd993eec0760e;hb=29e0b0ea6b5555045a7aad07d6c070967fbee355;hp=84d611bf096cbdf634227b0eca38e8cc70074b44;hpb=88c250214b1b340db72e7e1799883330aeee37fa;p=releng.git 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 84d611bf0..a6e733914 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py @@ -7,19 +7,21 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import json +from os import path +import mock from tornado import testing -from tornado import web -import fake_pymongo +from opnfv_testapi.cmd import server from opnfv_testapi.resources import models -from opnfv_testapi.router import url_mappings +from opnfv_testapi.tests.unit import fake_pymongo class TestBase(testing.AsyncHTTPTestCase): headers = {'Content-Type': 'application/json; charset=UTF-8'} def setUp(self): + self._patch_server() self.basePath = '' self.create_res = models.CreateResponse self.get_res = None @@ -30,12 +32,24 @@ class TestBase(testing.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 web.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)