Module: check_mk
Branch: master
Commit: dc96d0e7c593216ea8ffb5a4ed0e5d8f024e78ba
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc96d0e7c59321…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat Aug 11 19:06:30 2018 +0200
Add some unit tests for SiteContext()
Change-Id: Ia4a43509d9257b3a53b028d8860e8d05b40eb3f7
---
tests/unit/omdlib/test_site_context.py | 42 ++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/tests/unit/omdlib/test_site_context.py
b/tests/unit/omdlib/test_site_context.py
new file mode 100644
index 0000000..acf3098
--- /dev/null
+++ b/tests/unit/omdlib/test_site_context.py
@@ -0,0 +1,42 @@
+import os
+
+import omdlib.main
+
+def test_root_context():
+ site = omdlib.main.RootContext()
+ assert site.name == None
+ assert site.dir == "/"
+
+
+def test_site_context(monkeypatch):
+ site = omdlib.main.SiteContext("dingeling")
+ assert site.name == "dingeling"
+ assert site.dir == "/omd/sites/dingeling"
+ assert site.tmp_dir == "/omd/sites/dingeling/tmp"
+
+
+def test_site_context_version(monkeypatch):
+ site = omdlib.main.SiteContext("dingeling")
+ monkeypatch.setattr(os, "readlink", lambda x:
"../2018.08.11.cee")
+ assert site.version == "2018.08.11.cee"
+
+
+def test_site_context_exists(monkeypatch):
+ monkeypatch.setattr(os.path, "exists", lambda p: p ==
"/omd/sites/dingeling")
+
+ site = omdlib.main.SiteContext("dingeling")
+ assert site.exists()
+
+ site = omdlib.main.SiteContext("dingelang")
+ assert not site.exists()
+
+
+def test_site_context_is_empty(monkeypatch):
+ monkeypatch.setattr(os, "listdir", lambda p:
+ [] if p == "/omd/sites/dingeling" else ["abc",
"version"])
+
+ site = omdlib.main.SiteContext("dingeling")
+ assert site.is_empty()
+
+ site = omdlib.main.SiteContext("dingelang")
+ assert not site.is_empty()