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

files pattern not handling str and io.BytesIO #261

Closed
pierremonico opened this issue Mar 27, 2024 · 3 comments · Fixed by #260
Closed

files pattern not handling str and io.BytesIO #261

pierremonico opened this issue Mar 27, 2024 · 3 comments · Fixed by #260

Comments

@pierremonico
Copy link

When using the files parameter in a helper (http) function, both str and io.BytesIO payloads are not deemed equal and raise an error.

Input

str payload

@respx.mock
def test_file_str_payload():
    FILE_DATA = {"upload": ("image/png", "str", "image/png")}

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

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

io.BytesIO payload

@respx.mock
def test_file_bytesio_payload():
    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)

Output

Error raised

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

pierremonico commented Mar 27, 2024

Addressed by #260 after I intruded #258 but wanted to provide clearer context.

@lundberg
Copy link
Owner

Thanks @pierremonico.

If you haven't already, please try #260 on your own code to rule out any new bugs.

@pierremonico
Copy link
Author

I've tested #260 within my codebase and all my expected tests worked. I've also added one containing a str payload and that worked too.

For reference, I've installed the fix from #260 within my environment running the following commands at the root of my project (with the virtual environment in which respx was currently installed activated):

git clone [email protected]:lundberg/respx.git
cd respx 
git checkout fix/files-pattern-io
pip install .
cd ..
rm -rf respx

I believe you can pip install referencing a git repo/branch directly but this seemed safer.

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.

2 participants