diff options
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/tests/unit/resources')
3 files changed, 19 insertions, 18 deletions
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py index 6e4d454de..67831f508 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py +++ b/utils/test/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 diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py index f199bc7d5..1e83ed308 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py @@ -61,9 +61,9 @@ class TestResultBase(base.TestBase): self.scenario = 'odl-l2' self.criteria = 'passed' self.trust_indicator = result_models.TI(0.7) - self.start_date = "2016-05-23 07:16:09.477097" - self.stop_date = "2016-05-23 07:16:19.477097" - self.update_date = "2016-05-24 07:16:19.477097" + self.start_date = str(datetime.now()) + self.stop_date = str(datetime.now() + timedelta(minutes=1)) + self.update_date = str(datetime.now() + timedelta(days=1)) self.update_step = -0.05 super(TestResultBase, self).setUp() self.details = Details(timestart='0', duration='9s', status='OK') @@ -275,7 +275,7 @@ class TestResultGet(TestResultBase): @executor.query(httplib.OK, '_query_period_one', 1) def test_queryPeriodSuccess(self): - return self._set_query('period=11') + return self._set_query('period=5') @executor.query(httplib.BAD_REQUEST, message.must_int('last')) def test_queryLastNotInt(self): @@ -306,7 +306,7 @@ class TestResultGet(TestResultBase): 'scenario', 'trust_indicator', 'criteria', - 'period=11') + 'period=5') @executor.query(httplib.OK, '_query_success', 0) def test_notFound(self): @@ -324,10 +324,10 @@ class TestResultGet(TestResultBase): @executor.query(httplib.OK, '_query_success', 1) def test_filterErrorStartdate(self): self._create_error_start_date(None) - # self._create_error_start_date('None') + self._create_error_start_date('None') self._create_error_start_date('null') self._create_error_start_date('') - return self._set_query('period=11') + return self._set_query('period=5') def _query_success(self, body, number): self.assertEqual(number, len(body.results)) @@ -338,7 +338,7 @@ class TestResultGet(TestResultBase): def _query_period_one(self, body, number): self.assertEqual(number, len(body.results)) - self.assert_res(body.results[0], self.req_10d_before) + self.assert_res(body.results[0], self.req_d) def _create_error_start_date(self, start_date): req = copy.deepcopy(self.req_d) diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py index b4ba88742..940e256c6 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py @@ -10,7 +10,6 @@ from tornado import web from opnfv_testapi.common import message from opnfv_testapi.resources import project_models -from opnfv_testapi.router import url_mappings from opnfv_testapi.tests.unit import executor from opnfv_testapi.tests.unit import fake_pymongo from opnfv_testapi.tests.unit.resources import test_base as base @@ -18,6 +17,7 @@ from opnfv_testapi.tests.unit.resources import test_base as base class TestToken(base.TestBase): def get_app(self): + from opnfv_testapi.router import url_mappings return web.Application( url_mappings.mappings, db=fake_pymongo, |