Further improve flaky header tests

This commit is contained in:
Andrew Godwin 2018-02-01 21:18:13 -08:00
parent db68c43de1
commit 0572b1dbcd
2 changed files with 3 additions and 3 deletions

View File

@ -16,7 +16,7 @@ class TestHTTPResponse(DaphneTestCase):
Lowercases and sorts headers, and strips transfer-encoding ones.
"""
return sorted([
(name.lower(), value)
(name.lower(), value.strip())
for name, value in headers
if name.lower() != "transfer-encoding"
])

View File

@ -52,7 +52,7 @@ class TestWebsocket(DaphneTestCase):
# {name: [value1, value2, ...]} and check if they're equal.
transformed_scope_headers = collections.defaultdict(list)
for name, value in scope["headers"]:
transformed_scope_headers[name] = []
transformed_scope_headers.setdefault(name, [])
# Make sure to split out any headers collapsed with commas
for bit in value.split(b","):
if bit.strip():
@ -61,8 +61,8 @@ class TestWebsocket(DaphneTestCase):
for name, value in (headers or []):
expected_name = name.lower().strip().encode("ascii")
expected_value = value.strip().encode("ascii")
transformed_request_headers[expected_name] = []
# Make sure to split out any headers collapsed with commas
transformed_request_headers.setdefault(expected_name, [])
for bit in expected_value.split(b","):
if bit.strip():
transformed_request_headers[expected_name].append(bit.strip())