None type doesn't work in data matching as of v0.21.0
slingshotvfx opened this issue · comments
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 ""
Thanks, hopefully a simple fix
@slingshotvfx please try #259 and see if it solves your issue
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!
@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.