Skip to content

files pattern not handling str and io.BytesIO #261

@pierremonico

Description

@pierremonico

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions