Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 93beb4b

Browse files
committed
Test the HTTP20Response trailers implementation.
1 parent c4b6363 commit 93beb4b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/test_hyper.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,23 @@ def test_fileno_not_implemented(self):
18741874
with pytest.raises(NotImplementedError):
18751875
resp.fileno()
18761876

1877+
def test_trailers_are_read(self):
1878+
trailers = [('a', 'b'), ('c', 'd')]
1879+
stream = DummyStream(b'', trailers=trailers)
1880+
resp = HTTP20Response([(':status', '200')], stream)
1881+
1882+
# Cast to dict in both places because we roundtrip through a dict
1883+
# anyway.
1884+
assert dict(resp.gettrailers()) == dict(trailers)
1885+
assert resp.gettrailer('a') == 'b'
1886+
assert resp.gettrailer('c') == 'd'
1887+
1888+
def test_gettrailer_defaults_correctly(self):
1889+
resp = HTTP20Response([(':status', '200')], DummyStream(b''))
1890+
1891+
assert resp.gettrailer('a') is None
1892+
assert resp.gettrailer('a', 'b') == 'b'
1893+
18771894

18781895
class TestHTTP20Adapter(object):
18791896
def test_adapter_reuses_connections(self):
@@ -1953,11 +1970,15 @@ def close(self):
19531970
pass
19541971

19551972
class DummyStream(object):
1956-
def __init__(self, data):
1973+
def __init__(self, data, trailers=None):
19571974
self.data = data
19581975
self.closed = False
19591976
self.response_headers = {}
19601977
self._remote_closed = False
1978+
self.trailers = trailers
1979+
1980+
if self.trailers is None:
1981+
self.trailers = []
19611982

19621983
def _read(self, *args, **kwargs):
19631984
try:
@@ -1978,3 +1999,6 @@ def close(self):
19781999
self.closed = True
19792000
else:
19802001
assert False
2002+
2003+
def gettrailers(self):
2004+
return self.trailers

0 commit comments

Comments
 (0)