Module: check_mk
Branch: master
Commit: 5e7c71360f1d1f7211c6c04a53934cb9db73a143
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5e7c71360f1d1f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 29 10:13:18 2016 +0200
Started adding test for API calls
---
tests/testlib/__init__.py | 28 ++++++++++++++++++++++++++++
tests/web/test_wato_webapi.py | 15 +++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 3d9c599..9bf649d 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -10,6 +10,10 @@ import requests
import pipes
import subprocess
+try:
+ import simplejson as json
+except ImportError:
+ import json
def repo_path():
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
@@ -339,6 +343,30 @@ class WebSession(requests.Session):
assert "action=\"login.py\"" in r.text
+ #
+ # Web-API for managing hosts, services etc.
+ #
+
+ def _api_request(self, url, data):
+ req = self.post(url, data)
+ response = json.loads(req.text)
+
+ assert response["result_code"] == 0, \
+ "An error occured: %s" % response["result"]
+
+ return response["result"]
+
+
+ def add_host(self, hostname, folder="/", attributes=None):
+ result = self._api_request(self.url + "webapi.py?action=add_host", {
+ "request": json.dumps({
+ "hostname" : hostname,
+ "attributes" : attributes or {},
+ }),
+ })
+
+ assert result["result"] == None
+
@pytest.fixture(scope="module")
def web(site):
diff --git a/tests/web/test_wato_webapi.py b/tests/web/test_wato_webapi.py
new file mode 100644
index 0000000..c49490f
--- /dev/null
+++ b/tests/web/test_wato_webapi.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+import pytest
+from testlib import site, web
+
+def test_01_global_settings(site, web):
+ r = web.get(site.url + "wato.py")
+ assert "Global Settings" in r.text
+
+
+def test_02_add_host(web):
+ web.add_host("test-host", attributes={
+ "ipaddress": "127.0.0.1",
+ })