Module: check_mk
Branch: master
Commit: 32e3fdee3836e6664f534e950b487544d4e30da0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=32e3fdee3836e6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Sep 6 17:07:23 2016 +0200
tests: updated crawler to recent web test api changes
---
tests/testlib/__init__.py | 5 ++++-
tests/web/test_crawl.py | 13 +++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 183c30c..c3a66e8 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -417,7 +417,7 @@ class WebSession(requests.Session):
# There might be other resources like iframe, audio, ... but we don't care
about them
for img_url in self._find_resource_urls("img", "src", soup):
- assert not img_url.startswith("/")
+ assert not img_url.startswith("/"), "%s starts with /" %
img_url
req = self.get(base_url + "/" + img_url, proto=parsed_url.scheme,
verify=False)
mime_type = self._get_mime_type(req)
@@ -481,6 +481,9 @@ class CMKWebSession(WebSession):
# Computes a full URL inkl. http://... from a URL starting with the path.
def url(self, proto, path):
+ assert not path.startswith("http")
+ assert "://" not in path
+
# In case no path component is in URL, add the path to the
"/[site]/check_mk"
if "/" not in urlparse(path).path:
path = "/%s/check_mk/%s" % (self.site.id, path)
diff --git a/tests/web/test_crawl.py b/tests/web/test_crawl.py
index 2ff7639..7d09f93 100644
--- a/tests/web/test_crawl.py
+++ b/tests/web/test_crawl.py
@@ -32,6 +32,14 @@ class Url(object):
return "check_mk/" + self.url.split("/check_mk/", 1)[1]
+ # Strip proto and host
+ def url_without_host(self):
+ parsed = list(urlsplit(self.url))
+ parsed[0] = None
+ parsed[1] = None
+ return urlunsplit(parsed)
+
+
class Worker(threading.Thread):
def __init__(self, num, crawler):
@@ -74,7 +82,8 @@ class Worker(threading.Thread):
started = time.time()
try:
- response = self.crawler.client.get(url.url)
+ #print url.url_without_host()
+ response = self.crawler.client.get(url.url_without_host())
except AssertionError, e:
if "This view can only be used in mobile mode" in "%s" %
e:
return
@@ -274,7 +283,7 @@ class TestCrawler(object):
self.load_stats()
- self.todo.put(Url(site.url))
+ self.todo.put(Url("/%s/check_mk/" % site.id))
self.crawl()