Help unit testing v3 multipart/form-data with "Missing boundary in multipart" #1964
Replies: 2 comments
-
Have not been able to get past this - and I am certainly not going to introduce the boundary strings in my test code. As a work around (which works for me) I have switched the API content from As I said, that is not fixing the problem - I would still like to know how to use the connexion test_client() to drive a |
Beta Was this translation helpful? Give feedback.
-
Hi @alanbchristie, The boundary parameter is required in the Eg. headers={"Content-Type": b"multipart/form-data; boundary=-"} Usually If really needed, you can force the test client to send data as res = app_client.post(
"/v1.0/multipart_form_json",
files={"file": b""}, # Force multipart/form-data content-type
data={"x": json.dumps({"name": "joe", "age": 20})},
) |
Beta Was this translation helpful? Give feedback.
-
I'm moving from connexion 2 to connexion 3 (
3.1.0
) and I have "Missing boundary in multipart" errors on my OpenAPI endpoints that expect "multipart/form-data".In v2 unit-testing (which uses
requests
) I didn't need to do anything special here but in v3 I seem to be frustrated at not being able to get past boundary exceptions in the client and the server. Here's my setup, where I'm using the connexion test_client() (which, in v3, useshttpx
rather thanrequests
): -The OpenAPI endpoint body definition
This is the endpoint body definition for a POST at
/asset
(descriptions have been removed to reduce space): -The unit test
Here an excerpt of a test using the above endpoint. The key elements here are the
headers
anddata
: -What happens?
Although this is modified for the v3 response (where
.json
in the response becomes.json()
) it's essentially the same code that tested the v2 implementation: -data
payloadAccept
andContent-Type
header valuesBut, when it's run I get a KeyError from the underlying
starlette/formparsers.py
module: -So there's a missing boundary.
Fine - but why is that my problem?
In the v2 implementation's Swagger the generated cURL looks like the following. It does not define a boundary either (here the actual URL replaced by
[...]
): -Beta Was this translation helpful? Give feedback.
All reactions