diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-07-13 20:09:10 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-07-20 15:18:08 +0800 |
commit | 8ec6f1e7d682a56c122f930febb28da1575b8ff8 (patch) | |
tree | 5881548d80d23caf66bab8e6ea810cd1884dbc54 /testapi/opnfv_testapi/tests/unit/resources/test_base.py | |
parent | cf402a2a6888ade5c57165dc978a59d2330307a7 (diff) |
decouple the mutual-dependence of config.py and server.py
Currently server.py relies on CONF while starting the service, and
config.py's config_fie is set in server.py, which is wrongly bi-depended
this patch aims to let Config parse the sys.argv personally,
just as oslo.config do, so that decouple the mutual-dependency
Change-Id: I46887d122a98d478caebe9eeb7ab038941ce1f6b
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi/tests/unit/resources/test_base.py')
-rw-r--r-- | testapi/opnfv_testapi/tests/unit/resources/test_base.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/resources/test_base.py b/testapi/opnfv_testapi/tests/unit/resources/test_base.py index 6e4d454..67831f5 100644 --- a/testapi/opnfv_testapi/tests/unit/resources/test_base.py +++ b/testapi/opnfv_testapi/tests/unit/resources/test_base.py @@ -12,13 +12,9 @@ from os import path import mock from tornado import testing -from opnfv_testapi.common import config from opnfv_testapi.resources import models from opnfv_testapi.tests.unit import fake_pymongo -config.Config.CONFIG = path.join(path.dirname(__file__), - '../../../../etc/config.ini') - class TestBase(testing.AsyncHTTPTestCase): headers = {'Content-Type': 'application/json; charset=UTF-8'} @@ -37,17 +33,22 @@ class TestBase(testing.AsyncHTTPTestCase): def tearDown(self): self.db_patcher.stop() + self.config_patcher.stop() def _patch_server(self): - from opnfv_testapi.cmd import server - server.parse_config([ - '--config-file', - path.join(path.dirname(__file__), path.pardir, 'common/normal.ini') - ]) + import argparse + config = path.join(path.dirname(__file__), '../common/normal.ini') + self.config_patcher = mock.patch( + 'argparse.ArgumentParser.parse_known_args', + return_value=(argparse.Namespace(config_file=config), None)) self.db_patcher = mock.patch('opnfv_testapi.cmd.server.get_db', self._fake_pymongo) + self.config_patcher.start() self.db_patcher.start() + def set_config_file(self): + self.config_file = 'normal.ini' + @staticmethod def _fake_pymongo(): return fake_pymongo |