vinissimus / async-asgi-testclient

A framework-agnostic library for testing ASGI web applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No way to add multiple files with the same name

Alerion opened this issue · comments

Allow using a tuple for files argument to pass few files with the same name.

This is required to test these endpoints https://fastapi.tiangolo.com/tutorial/request-files/#multiple-file-uploads

Example for requests module: https://stackoverflow.com/a/20769921

If you want to the change, feel free to open a PR. Otherwise, maybe I can take a look in the following days.

As a workaround, I think using a multidict should work:

from multidict import CIMultiDict  # already installed with async-asgi-testclient

resp = await client.post(
    "/upload",
    files=CIMultiDict([("file", "DATA"), ("file", "MORE DATA")])
)

Thank you for response. This works good for me. So you can just add an example to documentation.

    response = await app_client.post_and_check(
        url,
        files=CIMultiDict([
            ("doc_id", doc_id),
            ("language_code", "en"),
            ("files", ("file1.png", file1, "image/png")),
            ("files", ("file2.jpg", file2, "image/jpeg")),
        ])
    )