Module: check_mk
Branch: master
Commit: ce4f4052662b6a6f84c61c5ef889e1af025b80b2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ce4f4052662b6a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Aug 29 14:27:03 2016 +0200
Not following redirects in case of expecting a redirect
---
tests/testlib/__init__.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index ce2bdee..183c30c 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -320,12 +320,16 @@ class WebSession(requests.Session):
return self._request("post", *args, **kwargs)
- def _request(self, method, path, proto="http", expected_code=200,
expect_redirect=None, allow_errors=False, add_transid=False, **kwargs):
+ def _request(self, method, path, proto="http", expected_code=200,
expect_redirect=None,
+ allow_errors=False, add_transid=False, **kwargs):
url = self.url(proto, path)
if add_transid:
url = self._add_transid(url)
+ if expect_redirect:
+ kwargs["allow_redirects"] = False
+
if method == "post":
response = super(WebSession, self).post(url, **kwargs)
else:
@@ -358,10 +362,12 @@ class WebSession(requests.Session):
mime_type = self._get_mime_type(response)
-
if expect_redirect:
expected_code, redirect_target = expect_redirect
- assert response.headers["Location"] == redirect_target
+ assert response.headers["Location"] == redirect_target, \
+ "Expected %d redirect to %s but got this location: %s" % \
+ (expected_code, redirect_target,
+ response.headers.get('Location', "None"))
assert response.status_code == expected_code, \
"Got invalid status code (%d != %d) for URL %s (Location: %s)" % \