2018-01-08 14:35:54 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""!
|
|
|
|
|
____ ____ ______ __ __ __ _____
|
|
|
|
|
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
|
|
|
|
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
|
|
|
|
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
|
|
|
|
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
|
|
|
|
German BOS Information Script
|
|
|
|
|
by Bastian Schroll
|
|
|
|
|
|
|
|
|
|
@file: test_config.py
|
|
|
|
|
@date: 08.01.2017
|
|
|
|
|
@author: Bastian Schroll
|
2018-01-08 23:41:33 +01:00
|
|
|
@description: Unittests for BOSWatch. File must be _run as "pytest" unittest
|
2018-01-08 14:35:54 +01:00
|
|
|
"""
|
2018-01-12 07:48:27 +01:00
|
|
|
import logging
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
from boswatch.utils import paths
|
|
|
|
|
from boswatch.config import Config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Test_Config:
|
|
|
|
|
"""!Unittests for the config"""
|
|
|
|
|
|
2018-01-12 07:48:27 +01:00
|
|
|
def setup_method(self, method):
|
|
|
|
|
logging.debug("[TEST] %s.%s" % (type(self).__name__, method.__name__))
|
|
|
|
|
|
2018-01-08 14:35:54 +01:00
|
|
|
def test_loadLocalConfig(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!load a local config file"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini")
|
2018-01-08 14:35:54 +01:00
|
|
|
assert bwConfig._config is not None
|
|
|
|
|
|
|
|
|
|
def test_getLocalConfig(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!get values from local config file"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini")
|
2018-01-11 12:59:53 +01:00
|
|
|
assert bwConfig.getInt("test", "one") == 1
|
|
|
|
|
assert bwConfig.getBool("test", "one") is True
|
|
|
|
|
assert bwConfig.getStr("test", "two") == "two"
|
|
|
|
|
assert bwConfig.getStr("testcase", "test") == "ok"
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
def test_getLocalConfigFailed(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!fail while get values from local config file"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini")
|
2018-01-11 12:59:53 +01:00
|
|
|
assert bwConfig.getStr("test", "abc") == "None"
|
|
|
|
|
assert bwConfig.getStr("abc", "test") == "None"
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
def test_shareConfig(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!load local config file and share it"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini", "test_shareConfig")
|
|
|
|
|
assert bwConfig._sharePoints["test_shareConfig"] is not None
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
def test_shareConfigUsed(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!load local config file and tr to share it twice with same name"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig1 = Config()
|
|
|
|
|
bwConfig1.loadConfigFile(paths.TEST_PATH + "test.ini", "test_shareConfigUsed")
|
|
|
|
|
assert bwConfig1._sharePoints["test_shareConfigUsed"] is not None
|
|
|
|
|
bwConfig2 = Config()
|
|
|
|
|
bwConfig2.loadConfigFile(paths.TEST_PATH + "test.ini")
|
2018-01-10 13:06:18 +01:00
|
|
|
assert not bwConfig2._shareConfig("test_shareConfigUsed")
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
def test_getNotSetSharedConfig(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!try to get values from shared config where not exists"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini")
|
2018-01-11 12:59:53 +01:00
|
|
|
assert bwConfig.getInt("test", "one") == 1
|
|
|
|
|
assert bwConfig.getInt("test", "one", "NotSetSharedConfig") == 0
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
def test_getSharedConfig(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!get values from shared config file"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig1 = Config()
|
|
|
|
|
bwConfig1.loadConfigFile(paths.TEST_PATH + "test.ini", "test_getSharedConfig")
|
|
|
|
|
assert bwConfig1._sharePoints["test_getSharedConfig"] is not None
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
bwConfig2 = Config()
|
2018-01-11 12:59:53 +01:00
|
|
|
assert bwConfig2.getStr("test", "one") == "None"
|
|
|
|
|
assert bwConfig2.getInt("test", "one", "test_getSharedConfig") == 1
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
def test_getSharedConfigFailed(self):
|
2018-01-08 14:40:29 +01:00
|
|
|
"""!fail while get values from shared config file"""
|
2018-01-08 19:57:15 +01:00
|
|
|
bwConfig1 = Config()
|
|
|
|
|
bwConfig1.loadConfigFile(paths.TEST_PATH + "test.ini", "test_getSharedConfigFailed")
|
|
|
|
|
assert bwConfig1._sharePoints["test_getSharedConfigFailed"] is not None
|
2018-01-08 14:35:54 +01:00
|
|
|
|
|
|
|
|
bwConfig2 = Config()
|
2018-01-11 12:59:53 +01:00
|
|
|
assert bwConfig2.getStr("test", "abc", "test_getSharedConfigFailed") == "None"
|
|
|
|
|
assert bwConfig2.getStr("abc", "test", "test_getSharedConfigFailed") == "None"
|
2018-01-12 19:39:11 +01:00
|
|
|
|
|
|
|
|
def test_getDataTypes(self):
|
|
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini")
|
|
|
|
|
assert bwConfig.getStr("testcase", "test") == "ok"
|
|
|
|
|
assert bwConfig.getInt("test", "one") == 1
|
|
|
|
|
assert bwConfig.getInt("boolTest", "three") == 0
|
|
|
|
|
assert bwConfig.getBool("boolTest", "one")
|
|
|
|
|
assert bwConfig.getBool("boolTest", "two")
|
|
|
|
|
assert not bwConfig.getBool("boolTest", "three")
|
|
|
|
|
assert not bwConfig.getBool("boolTest", "four")
|
|
|
|
|
|
|
|
|
|
def test_getAllSharepoints(self):
|
|
|
|
|
bwConfig = Config()
|
|
|
|
|
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini", "test_shareConfig")
|
|
|
|
|
assert bwConfig.getAllSharepoints() is not None
|