Module: check_mk
Branch: master
Commit: a5ae42ea0f5cefee6499f87771539b31d43c68f7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a5ae42ea0f5cef…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Mon Sep 24 09:53:35 2018 +0200
Test read bulk contexts
Change-Id: I6a02904ca2da8240b7d5f5dc5275e0f2f967fa07
---
cmk/notification_plugins/utils.py | 5 ++++-
tests/unit/cmk/notifications/test_utils.py | 6 ++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/cmk/notification_plugins/utils.py b/cmk/notification_plugins/utils.py
index 573529b..3b43029 100644
--- a/cmk/notification_plugins/utils.py
+++ b/cmk/notification_plugins/utils.py
@@ -38,6 +38,7 @@ except ImportError:
from cmk_base.notify import find_wato_folder
+
def collect_context():
# type: () -> Dict
return {
@@ -145,6 +146,7 @@ def send_mail_sendmail(m, target, from_address):
sys.stdout.write("Spooled mail to local mail transmission agent\n")
return 0
+
def read_bulk_contexts():
parameters = {}
contexts = []
@@ -161,7 +163,7 @@ def read_bulk_contexts():
try:
key, value = line.split("=", 1)
value = value.replace("\1", "\n")
- except:
+ except ValueError:
sys.stderr.write("Invalid line '%s' in bulked notification
context\n" % line)
continue
@@ -172,6 +174,7 @@ def read_bulk_contexts():
return parameters, contexts
+
def get_bulk_notification_subject(contexts, hosts):
hosts = list(hosts)
bulk_subject = None
diff --git a/tests/unit/cmk/notifications/test_utils.py
b/tests/unit/cmk/notifications/test_utils.py
index b221455..cbc54e2 100644
--- a/tests/unit/cmk/notifications/test_utils.py
+++ b/tests/unit/cmk/notifications/test_utils.py
@@ -54,3 +54,9 @@ SERVICENOTESURL=localhost
])
def test_substitute_context(context, template, result):
assert result == utils.substitute_context(template, context)
+
+
+def test_read_bulk_contents(monkeypatch, capsys):
+ monkeypatch.setattr('sys.stdin', ('key=val', '\n',
'key2=val2', 'a comment'))
+ assert utils.read_bulk_contexts() == ({'key': 'val'},
[{'key2': 'val2'}])
+ assert capsys.readouterr().err == "Invalid line 'a comment' in bulked
notification context\n"