Module: check_mk
Branch: master
Commit: 7a0a7df9bae175008c9026b257bb7fc7a6dedcb1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7a0a7df9bae175…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 18 21:17:03 2017 +0200
Use site python for integration tests
Change-Id: Id774a51401d68d809bf85bef36517cdb91cbd323
---
tests/Makefile | 12 +----------
tests/pylint/Makefile | 2 +-
tests/pylint/requirements.txt | 2 ++
tests/requirements.txt | 9 ++++++++
tests/testlib/__init__.py | 20 +++++++++++++++---
tests/web/conftest.py | 49 +++++++++++++++++++++++++++++++++++++++++++
tests/web/test_backup.py | 24 +++++++++++++++++++++
tests/web/test_escaping.py | 5 -----
8 files changed, 103 insertions(+), 20 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index a6055f2..b94e7cc 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -47,17 +47,7 @@ test-bandit-ci:
setup:
sudo apt-get install \
python-pip \
- python-lxml \
- python-enchant \
- python-lockfile \
chrpath
sudo pip install --upgrade pip
- sudo pip install --upgrade \
- pytest \
- requests \
- beautifulsoup4 \
- pytest-stepwise \
- dill \
- html5lib \
- bandit
+ sudo pip install --upgrade -r requirements.txt
$(MAKE) -C pylint setup
diff --git a/tests/pylint/Makefile b/tests/pylint/Makefile
index fcedd33..9572d61 100644
--- a/tests/pylint/Makefile
+++ b/tests/pylint/Makefile
@@ -2,6 +2,6 @@ help:
@echo "see make in tests/ directory"
setup:
- sudo pip install --upgrade pylint==1.6.4
+ sudo pip install --upgrade -r requirements.txt
sudo apt-get install \
enchant
diff --git a/tests/pylint/requirements.txt b/tests/pylint/requirements.txt
new file mode 100644
index 0000000..9a91342
--- /dev/null
+++ b/tests/pylint/requirements.txt
@@ -0,0 +1,2 @@
+pylint==1.6.4
+pyenchant
diff --git a/tests/requirements.txt b/tests/requirements.txt
new file mode 100644
index 0000000..b6156ae
--- /dev/null
+++ b/tests/requirements.txt
@@ -0,0 +1,9 @@
+pytest
+requests
+beautifulsoup4
+pytest-stepwise
+dill
+html5lib
+bandit
+lockfile
+lxml
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index e49ded7..6298c5d 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -371,11 +371,13 @@ class Site(object):
assert exit_code == 0
assert os.path.exists("/omd/sites/%s" % self.id)
+ self._enable_mod_python_debug()
+
+ self._install_test_python_modules()
+
if self.update_with_git:
self._update_with_f12_files()
- self._enable_mod_python_debug()
-
# When using the Git version, the original version files will be
# replaced by the .f12 scripts. When tests are running in parallel
@@ -481,6 +483,18 @@ class Site(object):
"PythonHandler index\n PythonDebug On"))
+ def _install_test_python_modules(self):
+ for file_name in os.listdir("/usr/local/lib/python2.7/dist-packages"):
+ target_path = self.path("local/lib/python/"+file_name)
+ if not os.path.exists(target_path):
+ assert os.system("sudo ln -s
/usr/local/lib/python2.7/dist-packages/%s %s" %
+ (file_name, target_path)) >> 8 == 0
+ #assert self.execute(["pip", "install",
+ # "-r", os.path.join(cmk_path(), "tests",
"requirements.txt"),
+ # "-r", os.path.join(cmk_path(), "tests",
"pylint", "requirements.txt"),
+ # ]).wait() == 0
+
+
def rm_if_not_reusing(self):
if not self.reuse:
self.rm()
@@ -626,7 +640,7 @@ class Site(object):
if "WORKSPACE" in os.environ:
env_var_str = "WORKSPACE='%s' " %
os.environ["WORKSPACE"]
- cmd = env_var_str + subprocess.list2cmdline(sys.argv + [ cmk_path() +
"/tests" ])
+ cmd = env_var_str + subprocess.list2cmdline(["python"] + sys.argv + [
cmk_path() + "/tests" ])
args = [ "/usr/bin/sudo", "--", "/bin/su",
"-l", self.id, "-c", cmd ]
return subprocess.call(args)
diff --git a/tests/web/conftest.py b/tests/web/conftest.py
index 82f8066..31bf9e1 100644
--- a/tests/web/conftest.py
+++ b/tests/web/conftest.py
@@ -1,4 +1,5 @@
import __builtin__
+import sys
import _pytest
import testlib
import cmk
@@ -10,3 +11,51 @@ monkeypatch.syspath_prepend("%s/web/htdocs" %
(testlib.cmk_path()))
# Fake the localization wrapper _(...)
monkeypatch.setattr(__builtin__, "_", lambda x: x, raising=False)
+
+# Fake mod_python.apache to make html_mod_python.py stuff importable
+class FakeModPythonUnderscoreApache(object):
+ # These are all fake values!
+ SERVER_RETURN = None
+ AP_CONN_UNKNOWN = None
+ AP_CONN_CLOSE = None
+ AP_CONN_KEEPALIVE = None
+ APR_NOFILE = None
+ APR_REG = None
+ APR_DIR = None
+ APR_CHR = None
+ APR_BLK = None
+ APR_PIPE = None
+ APR_LNK = None
+ APR_SOCK = None
+ APR_UNKFILE = None
+
+ def parse_qs(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def parse_qsl(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def table(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def log_error(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def config_tree(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def server_root(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def mpm_query(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def exists_config_define(self, *args, **kwargs):
+ raise NotImplemented()
+
+ def stat(self, *args, **kwargs):
+ raise NotImplemented()
+
+
+monkeypatch.setitem(sys.modules, "_apache", FakeModPythonUnderscoreApache())
+
diff --git a/tests/web/test_backup.py b/tests/web/test_backup.py
new file mode 100644
index 0000000..df977fe
--- /dev/null
+++ b/tests/web/test_backup.py
@@ -0,0 +1,24 @@
+# encoding: utf-8
+
+def test_backup_key_create_web(site, monkeypatch):
+ if site.file_exists("etc/check_mk/backup_keys.mk"):
+ site.delete_file("etc/check_mk/backup_keys.mk")
+
+ import wato
+ mode = wato.ModeBackupEditKey()
+
+ try:
+ # First create a backup key
+ key_dict = mode._create_key({
+ "alias": u"älias",
+ "passphrase": "passphra$e",
+ })
+
+ assert site.file_exists("etc/check_mk/backup_keys.mk")
+
+ # Then test key existance
+ test_mode = wato.ModeBackupEditKey()
+ keys = test_mode.load()
+ assert len(keys) == 1
+ finally:
+ site.delete_file("etc/check_mk/backup_keys.mk")
diff --git a/tests/web/test_escaping.py b/tests/web/test_escaping.py
index 2078d91..50ecdbf 100644
--- a/tests/web/test_escaping.py
+++ b/tests/web/test_escaping.py
@@ -2,11 +2,6 @@
# call using
# > py.test -s -k test_HTML_generator.py
-# enable imports from web directory
-from testlib import cmk_path
-import sys
-sys.path.insert(0, "%s/web/htdocs" % cmk_path())
-
# external imports
import re