Skip to content

Cannot match empty query parameters #778

@markhobson

Description

@markhobson

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': ''}

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions