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

None type doesn't work in data matching as of v0.21.0 #258

Closed
slingshotvfx opened this issue Mar 23, 2024 · 5 comments · Fixed by #259
Closed

None type doesn't work in data matching as of v0.21.0 #258

slingshotvfx opened this issue Mar 23, 2024 · 5 comments · Fixed by #259

Comments

@slingshotvfx
Copy link

slingshotvfx commented Mar 23, 2024

As of the latest version v0.21.0, None values in data lookups don't work:

import httpx
import respx


@respx.mock
def test():
    data = {"test": None}

    respx.post("http://test.com", data=data).respond()

    response = httpx.post("http://test.com", data=data)

    assert response.status_code == 200


if __name__ == "__main__":
    test()

output:

respx.models.AllMockedAssertionError: RESPX: <Request('POST', 'http://test.com/')> not mocked!

This test passes successfully in v0.20.2

The following do work:

    data = {"test": ""}
    respx.post("http://test.com", data=data).respond()
    response = httpx.post("http://test.com", data=data)
    respx.post("http://test.com", data={"test": ""}).respond()
    response = httpx.post("http://test.com", data={"test": None})

So there's just a bug somewhere translating None to ""

@lundberg
Copy link
Owner

Thanks, hopefully a simple fix

@lundberg
Copy link
Owner

@slingshotvfx please try #259 and see if it solves your issue

@pierremonico
Copy link

Not sure if it's related but I also encounter issues when I run (as a unittest.TestCase method):

    @respx.mock
    def test_file_upload(self):

        FILE_DATA = {
            "upload": ("image/png", io.BytesIO(b"some image content"), "image/png")
        }

        respx.patch("https://api.example.com/endpoint/123", files=FILE_DATA)

        httpx.patch("https://api.example.com/endpoint/123", files=FILE_DATA)

This raises:

raise AllMockedAssertionError(f"RESPX: {request!r} not mocked!")
respx.models.AllMockedAssertionError: RESPX: <Request('PATCH', 'https://api.example.com/endpoint/123')> not mocked!

@lundberg
Copy link
Owner

@pierremonico this is not related and is certainly a bug in the new files pattern feature that was added in 0.21.0.

Please open a new issue with your test example. My bet is that the pattern doesn't handle BytesIO, which should be a simple fix.

@slingshotvfx
Copy link
Author

@lundberg #259 fixes my issue. Thanks for looking into it!

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

Successfully merging a pull request may close this issue.

3 participants