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

Quoted params fail #209

Closed
dpManuqb opened this issue Aug 2, 2022 · 2 comments
Closed

Quoted params fail #209

dpManuqb opened this issue Aug 2, 2022 · 2 comments

Comments

@dpManuqb
Copy link

dpManuqb commented Aug 2, 2022

When I try an url with query quoted parameters, respx does not match the mocked url and raises "RESPX ... not mocked!"

from httpx import AsyncClient, Response
from urllib.parse import quote
import respx
import asyncio

@respx.mock
async def main():
    quoted_param = quote("""{"name": "something"}""")
    mock = respx.get(
        host="test", path="/path", params={"filter": quoted_param}).mock(
            return_value=Response(json={"nice": "job"}, status_code=200))

    print((await AsyncClient().get(url=f'http://test/path?filter={quoted_param}')).json())

if(__name__ == "__main__"):
    asyncio.run(main())
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1751, in get
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/site-packages/respx/mocks.py", line 188, in amock
    response = await cls._send_async_request(
  File "/usr/local/lib/python3.9/site-packages/respx/mocks.py", line 222, in _send_async_request
    httpx_response = await cls.async_handler(httpx_request)
  File "/usr/local/lib/python3.9/site-packages/respx/mocks.py", line 134, in async_handler
    raise assertion_error
  File "/usr/local/lib/python3.9/site-packages/respx/mocks.py", line 127, in async_handler
    httpx_response = await router.async_handler(httpx_request)
  File "/usr/local/lib/python3.9/site-packages/respx/router.py", line 319, in async_handler
    resolved = await self.aresolve(request)
  File "/usr/local/lib/python3.9/site-packages/respx/router.py", line 306, in aresolve
    break
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 126, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.9/site-packages/respx/router.py", line 251, in resolver
    raise AllMockedAssertionError(f"RESPX: {request!r} not mocked!")
respx.models.AllMockedAssertionError: RESPX: <Request('GET', 'http://test/path?filter=%7B%22name%22%3A%20%22something%22%7D')> not mocked!
@dpManuqb
Copy link
Author

dpManuqb commented Aug 3, 2022

Solved, shouldn't quote if you add params in params parameter, it already quotes it

Change quoted_param = quote("""{"name": "something"}""") to quoted_param = """{"name": "something"}""" and it works

@dpManuqb dpManuqb closed this as completed Aug 3, 2022
@lundberg
Copy link
Owner

lundberg commented Aug 3, 2022

Was writing the same answer atm 😂 ... i.e. the params kwarg should not be quoted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants