Module: check_mk
Branch: master
Commit: e26282f8699b8fe8a02b0342bd844b308d8319b7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e26282f8699b8f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 13 20:10:40 2019 +0100
Add fixture to initialize GUI config for tests
Change-Id: Ia247ef3c5da99e6794862726d665c37d44f72e06
---
tests/unit/cmk/gui/conftest.py | 23 ++++++++++++++++++++--
tests/unit/cmk/gui/watolib/test_host_attributes.py | 9 ++++++---
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/tests/unit/cmk/gui/conftest.py b/tests/unit/cmk/gui/conftest.py
index ef74c4d..6f049a9 100644
--- a/tests/unit/cmk/gui/conftest.py
+++ b/tests/unit/cmk/gui/conftest.py
@@ -1,7 +1,12 @@
-import pytest
-import _pytest
+# pylint: disable=redefined-outer-name
+
+import pytest # type: ignore
+import _pytest # type: ignore
from werkzeug.test import create_environ
+from pathlib2 import Path
+import cmk.utils.log
+import cmk.utils.paths
import cmk.gui.config as config
import cmk.gui.htmllib as htmllib
from cmk.gui.http import Request, Response
@@ -28,3 +33,17 @@ def register_builtin_html():
yield
html.finalize()
html.unset_current()
+
+
+(a)pytest.fixture()
+def load_config(register_builtin_html):
+ old_root_log_level = cmk.utils.log.logger.getEffectiveLevel()
+
+ multisite_mk = Path(cmk.utils.paths.default_config_dir) / "multisite.mk"
+ multisite_mk.parent.mkdir(parents=True, exist_ok=True) # pylint: disable=no-member
+ multisite_mk.touch() # pylint: disable=no-member
+ config.initialize()
+
+ yield
+
+ cmk.utils.log.logger.setLevel(old_root_log_level)
diff --git a/tests/unit/cmk/gui/watolib/test_host_attributes.py
b/tests/unit/cmk/gui/watolib/test_host_attributes.py
index e9befa6..54f632b 100644
--- a/tests/unit/cmk/gui/watolib/test_host_attributes.py
+++ b/tests/unit/cmk/gui/watolib/test_host_attributes.py
@@ -367,13 +367,14 @@ def test_custom_host_attribute_transform(old, new):
assert transformed_attributes[0]["topic"] == new
+(a)pytest.mark.usefixtures("load_plugins"gins", "load_config")
@pytest.mark.parametrize("for_what", [
"host",
"cluster",
"host_search",
"bulk",
])
-def test_host_attribute_topics(load_plugins, for_what):
+def test_host_attribute_topics(for_what):
assert attrs.get_sorted_host_attribute_topics(for_what=for_what) == [
("basic", u"Basic settings"),
("address", u'Address'),
@@ -383,7 +384,8 @@ def test_host_attribute_topics(load_plugins, for_what):
]
-def test_host_attribute_topics_for_folders(load_plugins):
+(a)pytest.mark.usefixtures("load_plugins"gins", "load_config")
+def test_host_attribute_topics_for_folders():
assert attrs.get_sorted_host_attribute_topics("folder") == [
("basic", u"Basic settings"),
('address', u'Address'),
@@ -394,6 +396,7 @@ def test_host_attribute_topics_for_folders(load_plugins):
]
+(a)pytest.mark.usefixtures("load_plugins"gins", "load_config")
@pytest.mark.parametrize("for_what", [
"host",
"cluster",
@@ -401,7 +404,7 @@ def test_host_attribute_topics_for_folders(load_plugins):
"host_search",
"bulk",
])
-def test_host_attributes(load_plugins, for_what):
+def test_host_attributes(for_what):
topics = {
"basic": [
'contactgroups',