From 8ec6f1e7d682a56c122f930febb28da1575b8ff8 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Thu, 13 Jul 2017 20:09:10 +0800 Subject: 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 --- .../opnfv_testapi/tests/unit/resources/test_base.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'testapi/opnfv_testapi/tests/unit/resources/test_base.py') 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 -- cgit 1.2.3-korg