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

Commit a7900d2

Browse files
committed
Test HTTP11Connection is context manager.
1 parent a044072 commit a7900d2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/test_integration_http11.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,52 @@ def socket_handler(listener):
165165
assert r.headers[b'content-length'] == [b'15']
166166

167167
assert r.read() == b'hellotherehello'
168+
169+
def test_connection_context_manager(self):
170+
self.set_up()
171+
172+
send_event = threading.Event()
173+
174+
def socket_handler(listener):
175+
sock = listener.accept()[0]
176+
177+
# We should get the initial request.
178+
data = b''
179+
while not data.endswith(b'\r\n\r\n'):
180+
data += sock.recv(65535)
181+
182+
send_event.wait()
183+
184+
# We need to send back a response.
185+
resp = (
186+
b'HTTP/1.1 200 OK\r\n'
187+
b'Server: socket-level-server\r\n'
188+
b'Content-Length: 15\r\n'
189+
b'\r\n'
190+
)
191+
sock.send(resp)
192+
193+
chunks = [
194+
b'hello',
195+
b'there',
196+
b'hello',
197+
]
198+
199+
for chunk in chunks:
200+
sock.send(chunk)
201+
202+
sock.close()
203+
204+
self._start_server(socket_handler)
205+
with self.get_connection() as c:
206+
c.request('GET', '/')
207+
send_event.set()
208+
r = c.get_response()
209+
data = r.read()
210+
211+
assert r.status == 200
212+
assert r.reason == b'OK'
213+
assert len(r.headers) == 2
214+
assert data == b'hellotherehello'
215+
216+
assert c._sock is None

0 commit comments

Comments
 (0)