Describe the bug
The matcher query_param_matcher cannot match query parameters that have an empty string value.
Additional context
This is because RequestsMock._parse_request_params calls parse_qsl with the default argument keep_blank_values=False:
|
for key, val in groupby(parse_qsl(urlsplit(url).query), lambda kv: kv[0]): |
This should be configurable, similar to allow_blank in urlencoded_params_matcher (see #533).
Version of responses
0.25.8
Steps to Reproduce
import responses
import requests
from responses import matchers
@responses.activate
def test_empty_query_param():
responses.get("http://example.com/foo", match=[matchers.query_param_matcher({"bar": ""})], json={})
response = requests.get("http://example.com/foo?bar=")
assert response.status_code == 200
Expected Result
The test passes.
Actual Result
The test fails:
E requests.exceptions.ConnectionError: Connection refused by Responses - the call doesn't match any registered mock.
E
E Request:
E - GET http://example.com/foo?bar=
E
E Available matches:
E - GET http://example.com/foo Parameters do not match. {} doesn't match {'bar': ''}
Describe the bug
The matcher
query_param_matchercannot match query parameters that have an empty string value.Additional context
This is because
RequestsMock._parse_request_paramscallsparse_qslwith the default argumentkeep_blank_values=False:responses/responses/__init__.py
Line 1054 in cdd104d
This should be configurable, similar to
allow_blankinurlencoded_params_matcher(see #533).Version of
responses0.25.8
Steps to Reproduce
Expected Result
The test passes.
Actual Result
The test fails: