Skip to content

Commit

Permalink
Merge pull request #315 from AdamWill/old-urllib3
Browse files Browse the repository at this point in the history
Handle bugs in older urllib3 versions in one of the tests
  • Loading branch information
gabrielfalcao committed Sep 9, 2018
2 parents 0d53619 + 5d2f8d9 commit 6b80921
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion httpretty/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,12 @@ def record_request(request, uri, headers):
'response': {
'status': response.status,
'body': decode_utf8(response.data),
'headers': dict(response.headers)
# urllib3 1.10 had a bug if you just did:
# dict(response.headers)
# which would cause all the values to become lists
# with the header name as the first item and the
# true value as the second item. Workaround that
'headers': dict(response.headers.items())
}
})
cls.enable()
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,11 @@ def test_recording_calls(port):
response['response'].should.have.key("status").being.equal(200)
response['response'].should.have.key("body").being.an(text_type)
response['response'].should.have.key("headers").being.a(dict)
# older urllib3 had a bug where header keys were lower-cased:
# https://github.com/shazow/urllib3/issues/236
# cope with that
if 'server' in response['response']["headers"]:
response['response']["headers"]["Server"] = response['response']["headers"].pop("server")
response['response']["headers"].should.have.key("Server").being.equal("TornadoServer/" + tornado_version)

# And When I playback the previously recorded calls
Expand Down

0 comments on commit 6b80921

Please sign in to comment.