You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code fails when attempting to begin the request:
Traceback (most recent call last):
File "test_http_client.py", line 35, in send_fake_put_request
connection.endheaders()
File "/usr/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/usr/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/usr/lib/python3.7/http/client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
The HTTPretty library evidently has not intercepted the HTTPConnection calls that send the HTTP request. This seems to be a failure to mock the request correctly.
The text was updated successfully, but these errors were encountered:
bignose-debian
changed the title
Fails to mock request sent with HTTPConnection
Fails to match hostname with different case
Jan 19, 2019
This is caused by the domain match logic: It fails to ignore letter case for hostnames.
The following test case, added to tests/unit/test_httpretty.py, demonstrates the problem:
deftest_match_http_address_should_ignore_hostname_case():
"HTTPretty.match_http_address should ignore case of hostname."for (register_hostname, match_hostname) in [
('foo.example.com', 'foo.example.com'),
('FOO.example.COM', 'foo.example.com'),
('foo.EXAMPLE.com', 'foo.example.com'),
('fOo.eXaMpLe.com', 'foo.example.com'),
('foo.example.com', 'FOO.example.COM'),
('foo.example.com', 'foo.EXAMPLE.com'),
('foo.example.com', 'fOo.eXaMpLe.com'),
]:
HTTPretty.register_uri(
HTTPretty.GET,
"http://{hostname}/".format(hostname=register_hostname),
body="yay",
)
assertHTTPretty.match_http_address(match_hostname, 80)
The current HTTPretty.match_http_address function fails that test because it incorrectly considers hostnames with different letter case to be different hostnames.
A request sent with Python's
http.client.HTTPConnection
is not mocked by HTTPretty.(Python version 3.7.2; HTTPretty version 0.9.5)
Example (fragment; see the attached file for a full working example):
test_http_client.py.txt
The code fails when attempting to begin the request:
The HTTPretty library evidently has not intercepted the HTTPConnection calls that send the HTTP request. This seems to be a failure to mock the request correctly.
The text was updated successfully, but these errors were encountered: