Module: check_mk
Branch: master
Commit: 78850a561e226fcdfc0a3154b94ec671361d18ba
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=78850a561e226f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 18 09:18:21 2017 +0200
New tests to verify create_folders parameter of the add_host API call
Change-Id: I737c1abdc904bbd1cbb8e5ec2aebb9805f7ec1f8
---
tests/testlib/__init__.py | 14 ++++++++------
tests/web/test_webapi.py | 24 ++++++++++++++++++++++++
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index fa7480e..9f53180 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -913,21 +913,23 @@ class CMKWebSession(WebSession):
return response["result"]
- def add_host(self, hostname, folder="/", attributes=None):
+ def add_host(self, hostname, folder="/", attributes=None,
create_folders=True, expect_error=False):
result = self._api_request("webapi.py?action=add_host", {
"request": json.dumps({
- "hostname" : hostname,
- "folder" : folder,
- "attributes" : attributes or {},
+ "hostname" : hostname,
+ "folder" : folder,
+ "attributes" : attributes or {},
+ "create_folders" : create_folders,
}),
- })
+ }, expect_error=expect_error)
assert result == None
host = self.get_host(hostname)
+ print host
assert host["hostname"] == hostname
- assert host["path"] == ""
+ assert host["path"] == folder
assert host["attributes"] == attributes
diff --git a/tests/web/test_webapi.py b/tests/web/test_webapi.py
index 7b67637..7d0d79b 100644
--- a/tests/web/test_webapi.py
+++ b/tests/web/test_webapi.py
@@ -22,6 +22,30 @@ def test_add_host(web):
web.delete_host("test-host")
+def test_add_host_folder_create(web):
+ web.add_host("test-host", attributes={
+ "ipaddress": "127.0.0.1",
+ },
+ create_folders=True,
+ folder="asd/eee",
+ )
+
+ web.delete_host("test-host")
+
+
+def test_add_host_no_folder_create(web):
+ with pytest.raises(APIError) as e:
+ web.add_host("test-host", attributes={
+ "ipaddress": "127.0.0.1",
+ },
+ create_folders=False,
+ folder="eins/zwei",
+ expect_error=True,
+ )
+
+ assert "Folder not existing" in "%s" % e
+
+
def test_get_all_hosts_basic(web):
try:
web.add_host("test-host-list", attributes={