Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ignoring query param order if the same parameter is provided more than once #156

Open
victor-h-costa opened this issue Sep 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@victor-h-costa
Copy link

As a question/feature request:

In some cases I usually convert an iterable to a set to avoid duplicates, like for example:

response = httpx.AsyncClient().get(
    "http://localhost:1111/videos",
    params={
        "field": list(set([1, 2, 2]))
    }
)

Which is difficult to test with pytest_httpx since the order of the query parameter field isn't known and doesn't really matter.

Is it possible to add new argument to HTTPXMock.add_response to ignore query param order if the same parameter is provided more than once?

# **Suggestion 1**
httpx_mock.add_response(
    method="GET",
    url="http://localhost:1111/videos?field=1&field=2",
    status_code=200,
    ignore_query_param_value_order=True,
)

# **Suggestion 2**
httpx_mock.add_response(
    method="GET",
    url="http://localhost:1111/videos?field=1&field=2",
    status_code=200,
    ignore_query_param_value_order=["field"],
)

Thanks

@Colin-b Colin-b added the question Further information is requested label Sep 23, 2024
@Colin-b
Copy link
Owner

Colin-b commented Sep 23, 2024

Hello @victor-h-costa

Order of parameters potentially matters in the API you are reaching out.
This looks however like a valid use case but I don't know when and how I will tackle this.

In the meantime, you have the 2 possible solutions:

  • Use a regex as matching URL (can be quite complex to read)
  • Use an ordered list when you send your parameters (requires to change your code for testing purpose)

@Colin-b Colin-b added enhancement New feature or request and removed question Further information is requested labels Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants