qs and query in request_history are converted to lowercase
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
requests-mock |
Fix Released
|
Low
|
Jamie Lennox |
Bug Description
# Hi, I have noticed that qs and query in the requests_history seem to be converted to lowercase ...
# The following test fails.
# Using requests-mock 1.0.0
import unittest
import requests
import requests_mock
class TestRequestsMoc
def setUp(self):
self.site = 'http://
self.key = 'cursorMark'
self.value = 'AoEpVkRCREIxQTE2'
def test_request_
with requests_
)
def test_request_
with requests_
)
if __name__ == '__main__':
unittest.main()
# > $ python atest.py
# FF
# =======
# FAIL: test_request_
# -------
# Traceback (most recent call last):
# File "atest.py", line 21, in test_request_
# {self.key: [self.value]}
# AssertionError: {'cursormark': ['aoepvkrcreixq
# - {'cursormark': ['aoepvkrcreixq
# + {'cursorMark': ['AoEpVkRCREIxQ
# =======
# FAIL: test_request_
# -------
# Traceback (most recent call last):
# File "atest.py", line 30, in test_request_
# '{}={}'
# AssertionError: 'cursormark=
# -------
# Ran 2 tests in 0.011s
# FAILED (failures=2)
Changed in requests-mock: | |
importance: | Undecided → Low |
status: | New → Confirmed |
Changed in requests-mock: | |
milestone: | none → 1.1 |
So i confirmed this is the case, but i'll need to have a think what to do about it. It seems to be the result of using functions intended for the server side on the client side.
requests-mock uses the standard urllib.parse_qs [1] function for creating this dictionary. Ideally this would be a CaseInsensitiveDict like requests uses for headers. Changing this would be backwards incompatible, though we could figure out a way to expose it.
I'm guessing that the reason parse_qs converts it to lowercase is because these parts of uris are expected to be case insensitive and represented as lower case [2] but i'm certainly not an expert in this area and would be happy to be informed here.
There's nothing from urllib3 that can help, but i've confirmed that if we use the following methods from uritools [3] we get case sensitive results:
uritools. urisplit( m.last_ request. url).getquery( ) urisplit( m.last_ request. url).getquerydi ct()
uritools.
however doing a straw poll on my current fedora machine this is not packaged in the repos so i'm not sure i would want a dependency like that.
Any other suggestions are welcome.
[1] https:/ /github. com/openstack/ requests- mock/blob/ 780eb4b4fe25ddd b802b5bfb39f846 d7fa60ea9a/ requests_ mock/adapter. py#L76- L80 tools.ietf. org/html/ rfc3986# section- 6.2.2.1 pythonhosted. org/uritools
[2] http://
[3] http://