Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/chunk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,32 @@ def test_get_text():
[mock.call(b"Host: "), mock.call(b"wifitest.adafruit.com"),]
)
assert r.text == str(text, "utf-8")


def test_close_flush():
"""Test that a chunked response can be closed even when the request contents were not accessed."""
pool = mocket.MocketPool()
pool.getaddrinfo.return_value = ((None, None, None, None, (ip, 80)),)
c = _chunk(text, 33)
print(c)
sock = mocket.Mocket(headers + c)
pool.socket.return_value = sock

s = adafruit_requests.Session(pool)
r = s.get("http://" + host + path)

sock.connect.assert_called_once_with((ip, 80))

sock.send.assert_has_calls(
[
mock.call(b"GET"),
mock.call(b" /"),
mock.call(b"testwifi/index.html"),
mock.call(b" HTTP/1.1\r\n"),
]
)
sock.send.assert_has_calls(
[mock.call(b"Host: "), mock.call(b"wifitest.adafruit.com"),]
)

r.close()
26 changes: 26 additions & 0 deletions tests/protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,29 @@ def test_get_http_text():
[mock.call(b"Host: "), mock.call(b"wifitest.adafruit.com"),]
)
assert r.text == str(text, "utf-8")


def test_get_close():
"""Test that a response can be closed without the contents being accessed."""
pool = mocket.MocketPool()
pool.getaddrinfo.return_value = ((None, None, None, None, (ip, 80)),)
sock = mocket.Mocket(response)
pool.socket.return_value = sock

s = adafruit_requests.Session(pool)
r = s.get("http://" + host + path)

sock.connect.assert_called_once_with((ip, 80))

sock.send.assert_has_calls(
[
mock.call(b"GET"),
mock.call(b" /"),
mock.call(b"testwifi/index.html"),
mock.call(b" HTTP/1.1\r\n"),
]
)
sock.send.assert_has_calls(
[mock.call(b"Host: "), mock.call(b"wifitest.adafruit.com"),]
)
r.close()