Module: check_mk
Branch: master
Commit: eceeb822761ca483a0bcc9be744b4a35dacde493
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eceeb822761ca4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat May 4 15:15:49 2019 +0200
Cleanup unit test omd_site mocking
Change-Id: I667a0dc308054239abede1cd38ec4f69d8532090
---
cmk/gui/config.py | 5 +++--
cmk/gui/plugins/wato/notifications.py | 19 ++++++++-----------
tests/unit/cmk/gui/conftest.py | 4 ----
tests/unit/conftest.py | 6 ++++++
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/cmk/gui/config.py b/cmk/gui/config.py
index 2d27b4e..d8f2be5 100644
--- a/cmk/gui/config.py
+++ b/cmk/gui/config.py
@@ -33,6 +33,7 @@ from typing import Callable, Union, Tuple, Dict # pylint:
disable=unused-import
import six
from pathlib2 import Path
+import cmk
import cmk.gui.utils as utils
import cmk.gui.tags
import cmk.gui.i18n
@@ -1082,11 +1083,11 @@ def extend_user_modified_tag_groups(host_tags):
def omd_site():
- return os.environ["OMD_SITE"]
+ return cmk.omd_site()
def url_prefix():
- return "/%s/" % omd_site()
+ return "/%s/" % cmk.omd_site()
use_siteicons = False
diff --git a/cmk/gui/plugins/wato/notifications.py
b/cmk/gui/plugins/wato/notifications.py
index d46a622..840268d 100644
--- a/cmk/gui/plugins/wato/notifications.py
+++ b/cmk/gui/plugins/wato/notifications.py
@@ -85,6 +85,10 @@ def transform_forth_html_mail_url_prefix(p):
return ("manual", v)
+def local_site_url():
+ return "http://" + socket.gethostname() + "/" + config.omd_site()
+ "check_mk/",
+
+
@notification_parameter_registry.register
class NotificationParameterMail(NotificationParameter):
@property
@@ -276,9 +280,7 @@ class NotificationParameterSlack(NotificationParameter):
regex_error=_("The URL must begin with
<tt>http</tt> or "
"<tt>https</tt> and end
with <tt>/check_mk/</tt>."),
size=64,
- default_value="http://" +
socket.gethostname() + "/" +
- (config.omd_site() and config.omd_site() +
"/" or
- "") + "check_mk/",
+ default_value=local_site_url,
)),
],
),
@@ -344,9 +346,7 @@ class NotificationParameterVictorOPS(NotificationParameter):
regex_error=_("The URL must begin with
<tt>http</tt> or "
"<tt>https</tt> and end
with <tt>/check_mk/</tt>."),
size=64,
- default_value="http://" +
socket.gethostname() + "/" +
- (config.omd_site() and config.omd_site() +
"/" or
- "") + "check_mk/",
+ default_value=local_site_url,
)),
],
),
@@ -404,9 +404,7 @@ class NotificationParameterPagerDuty(NotificationParameter):
regex_error=_("The URL must begin with
<tt>http</tt> or "
"<tt>https</tt> and end
with <tt>/check_mk/</tt>."),
size=64,
- default_value="http://" +
socket.gethostname() + "/" +
- (config.omd_site() and config.omd_site() +
"/" or
- "") + "check_mk/",
+ default_value=local_site_url,
)),
],
),
@@ -1058,8 +1056,7 @@ class NotificationParameterPushover(NotificationParameter):
regex_error=_("The URL must begin with
<tt>http</tt> or "
"<tt>https</tt> and end with
<tt>/check_mk/</tt>."),
size=64,
- default_value="http://" + socket.gethostname() +
"/" +
- (config.omd_site() and config.omd_site() + "/" or
"") + "check_mk/",
+ default_value=local_site_url,
)),
(
"proxy_url",
diff --git a/tests/unit/cmk/gui/conftest.py b/tests/unit/cmk/gui/conftest.py
index 636150a..2fa1b29 100644
--- a/tests/unit/cmk/gui/conftest.py
+++ b/tests/unit/cmk/gui/conftest.py
@@ -1,7 +1,6 @@
# pylint: disable=redefined-outer-name
import pytest # type: ignore
-import _pytest # type: ignore
from werkzeug.test import create_environ
from pathlib2 import Path
@@ -12,9 +11,6 @@ import cmk.gui.htmllib as htmllib
from cmk.gui.http import Request, Response
from cmk.gui.globals import html, current_app
-monkeypatch = _pytest.monkeypatch.MonkeyPatch()
-monkeypatch.setattr(config, "omd_site", lambda: "NO_SITE")
-
# TODO: Better make our application available?
class DummyApplication(object):
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index 81f51ba..290d9c9 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -1,5 +1,11 @@
import socket
import pytest # type: ignore
+import cmk
+
+
+(a)pytest.fixture(autouse=True)
+def patch_omd_site(monkeypatch):
+ monkeypatch.setattr(cmk, "omd_site", lambda: "NO_SITE")
# Unit tests should not be executed in site.