vinissimus / async-asgi-testclient

A framework-agnostic library for testing ASGI web applications
MIT License
160 stars 20 forks source link

No way to add multiple files with the same name #37

Open Alerion opened 3 years ago

Alerion commented 3 years ago

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

masipcat commented 3 years ago

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")])
)
Alerion commented 3 years ago

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")),
        ])
    )