|
2 | 2 | fromjsonimportdumps |
3 | 3 |
|
4 | 4 | importpytest |
| 5 | +fromurllib3importencode_multipart_formdata |
5 | 6 |
|
6 | 7 |
|
7 | 8 | classBaseTestFalconProject: |
@@ -204,7 +205,7 @@ def test_post_media_type_invalid(self, client): |
204 | 205 | "title": ( |
205 | 206 | "Content for the following mimetype not found: " |
206 | 207 | f"{content_type}. " |
207 | | -"Valid mimetypes: ['application/json', 'application/x-www-form-urlencoded', 'text/plain']" |
| 208 | +"Valid mimetypes: ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain']" |
208 | 209 | ), |
209 | 210 | } |
210 | 211 | ] |
@@ -292,6 +293,43 @@ def test_post_valid(self, client, data_json): |
292 | 293 | assertresponse.status_code==201 |
293 | 294 | assertnotresponse.content |
294 | 295 |
|
| 296 | +@pytest.mark.xfail( |
| 297 | +reason="falcon multipart form serialization unsupported", |
| 298 | +strict=True, |
| 299 | + ) |
| 300 | +deftest_post_multipart_valid(self,client,data_gif): |
| 301 | +cookies= {"user":1} |
| 302 | +auth="authuser" |
| 303 | +fields= { |
| 304 | +"name":"Cat", |
| 305 | +"address": ( |
| 306 | +"aaddress.json", |
| 307 | +dumps(dict(city="Warsaw")), |
| 308 | +"application/json", |
| 309 | + ), |
| 310 | +"photo": ( |
| 311 | +"photo.jpg", |
| 312 | +data_gif, |
| 313 | +"image/jpeg", |
| 314 | + ), |
| 315 | + } |
| 316 | +body,content_type_header=encode_multipart_formdata(fields) |
| 317 | +headers= { |
| 318 | +"Authorization":f"Basic{auth}", |
| 319 | +"Content-Type":content_type_header, |
| 320 | + } |
| 321 | + |
| 322 | +response=client.simulate_post( |
| 323 | +"/v1/pets", |
| 324 | +host="staging.gigantic-server.com", |
| 325 | +headers=headers, |
| 326 | +body=body, |
| 327 | +cookies=cookies, |
| 328 | +protocol="https", |
| 329 | + ) |
| 330 | + |
| 331 | +assertresponse.status_code==200 |
| 332 | + |
295 | 333 |
|
296 | 334 | classTestPetDetailResource: |
297 | 335 | deftest_get_server_invalid(self,client): |
|