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

Overlapping pattern/lookup combinations #179

Closed
flaeppe opened this issue Nov 4, 2021 · 3 comments · Fixed by #183
Closed

Overlapping pattern/lookup combinations #179

flaeppe opened this issue Nov 4, 2021 · 3 comments · Fixed by #183
Labels
enhancement New feature or request

Comments

@flaeppe
Copy link
Contributor

flaeppe commented Nov 4, 2021

I quite recently ran in to a typo which respx doesn't pick up on. It's probably not really respxs responsibility but thought perhaps it could deserve a warning? Or even better if it'd raise an error.

import httpx
import respx
mocker = respx.mock(base_url="http://some.where/", assert_all_called=False)
mocker.post(method__in=("GET", "PUT"), path="/here/")
with mocker:
    httpx.post("http://some.where/here/", json={"la": "la"})

Raises:

respx.models.AllMockedAssertionError: RESPX: <Request('POST', 'http://some.where/here/')> not mocked!

Choosing any of the methods POST, GET or PUT. The same error is raised since there's really nothing that could possibly match more than 1 method.

This is the constraint on the route:

<Route <Scheme eq 'http'> AND <Host eq 'some.where'> AND <Method eq 'POST'> AND <Method in ('GET', 'PUT')> AND <Path eq '/here/'>>
@lundberg
Copy link
Owner

lundberg commented Nov 8, 2021

Good catch @flaeppe, thanks!

This seems to be caused by the http method helper API, i.e. the .post(...) auto-adds the method pattern, and "collides" with the AND'ed predefined route's method__in pattern.

IMO a warning would be enough here, fired by the helper API. Let's start with that and maybe bump that to an exception in the future.

@lundberg
Copy link
Owner

lundberg commented Nov 8, 2021

I changed my mind 😉, it makes more sense to raise TypeError in this case.

Calling .post("https://foo.bar/", url="https://example.org/") would already fire a TypeError by python, due to the argument name colliding. So validating the lookups and fail likewise aligns better.

@flaeppe
Copy link
Contributor Author

flaeppe commented Nov 9, 2021

Nice! Sounds good

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

Successfully merging a pull request may close this issue.

2 participants