mirror of
https://github.com/Kozea/Radicale.git
synced 2025-07-02 16:58:30 +00:00
Tests: Simplify HTTP status check
This commit is contained in:
parent
c6462a253a
commit
88ff1b4c28
4 changed files with 71 additions and 92 deletions
|
@ -97,7 +97,8 @@ class TestBaseServerRequests(BaseTest):
|
|||
super().teardown()
|
||||
|
||||
def request(self, method: str, path: str, data: Optional[str] = None,
|
||||
**kwargs) -> Tuple[int, Dict[str, str], str]:
|
||||
check: Optional[int] = None, **kwargs
|
||||
) -> Tuple[int, Dict[str, str], str]:
|
||||
"""Send a request."""
|
||||
login = kwargs.pop("login", None)
|
||||
if login is not None and not isinstance(login, str):
|
||||
|
@ -128,6 +129,8 @@ class TestBaseServerRequests(BaseTest):
|
|||
with self.opener.open(req) as f:
|
||||
return f.getcode(), dict(f.info()), f.read().decode()
|
||||
except HTTPError as e:
|
||||
assert check is None or e.code == check, "%d != %d" % (e.code,
|
||||
check)
|
||||
return e.code, dict(e.headers), e.read().decode()
|
||||
except URLError as e:
|
||||
if not isinstance(e.reason, ConnectionRefusedError):
|
||||
|
@ -209,8 +212,7 @@ class TestBaseServerRequests(BaseTest):
|
|||
env={**os.environ, "PYTHONPATH": os.pathsep.join(sys.path)})
|
||||
try:
|
||||
status, headers, _ = self.request(
|
||||
"GET", "/", is_alive_fn=lambda: p.poll() is None)
|
||||
self._check_status(status, 302)
|
||||
"GET", "/", check=302, is_alive_fn=lambda: p.poll() is None)
|
||||
for key in self.configuration.options("headers"):
|
||||
assert headers.get(key) == self.configuration.get(
|
||||
"headers", key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue