summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/tests
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-05-12 17:02:35 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-05-12 17:07:47 +0800
commite401fd7efbf74c7cdc5334c380c79b45ad9271e0 (patch)
treec94c4147b3ee71479abbec8be7165367734a4781 /testapi/opnfv_testapi/tests
parent909be5b53a6141f84480dc29eb5dbfffe5c35fad (diff)
refactor config parser to facilitate adding new configs
refactor hardcoded config.py to facilitate adding new configurations come along with web portal and Authentication features Change-Id: Ibc16166ade0d6e730bb4c9d81e9b9bc9b297faa1 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi/tests')
-rw-r--r--testapi/opnfv_testapi/tests/unit/common/test_config.py32
1 files changed, 6 insertions, 26 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/common/test_config.py b/testapi/opnfv_testapi/tests/unit/common/test_config.py
index aaff6bb..446b944 100644
--- a/testapi/opnfv_testapi/tests/unit/common/test_config.py
+++ b/testapi/opnfv_testapi/tests/unit/common/test_config.py
@@ -1,36 +1,16 @@
-import ConfigParser
import os
-import pytest
-
from opnfv_testapi.common import config
-@pytest.fixture()
-def config_dir():
- return os.path.dirname(__file__)
-
-
-@pytest.mark.parametrize('exception, config_file, excepted', [
- (config.ParseError, None, '/etc/opnfv_testapi/config.ini not found'),
- (ConfigParser.NoSectionError, 'nosection.ini', 'No section:'),
- (config.ParseError, 'noparam.ini', 'No parameter:'),
- (config.ParseError, 'notint.ini', 'Not int:'),
- (config.ParseError, 'notboolean.ini', 'Not boolean:')])
-def pytest_config_exceptions(config_dir, exception, config_file, excepted):
- file = '{}/{}'.format(config_dir, config_file) if config_file else None
- with pytest.raises(exception) as error:
- config.APIConfig().parse(file)
- assert excepted in str(error.value)
-
-
def test_config_success():
- config_dir = os.path.join(os.path.dirname(__file__),
- '../../../../etc/config.ini')
- conf = config.APIConfig().parse(config_dir)
+ config_file = os.path.join(os.path.dirname(__file__),
+ '../../../../etc/config.ini')
+ config.Config.CONFIG = config_file
+ conf = config.Config()
assert conf.mongo_url == 'mongodb://127.0.0.1:27017/'
assert conf.mongo_dbname == 'test_results_collection'
assert conf.api_port == 8000
- assert conf.api_debug_on is True
- assert conf.api_authenticate_on is False
+ assert conf.api_debug is True
+ assert conf.api_authenticate is False
assert conf.swagger_base_url == 'http://localhost:8000'