|
2 | 2 | from json import dumps
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from urllib3 import encode_multipart_formdata |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class BaseTestFalconProject:
|
@@ -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 | assert response.status_code == 201
|
293 | 294 | assert not response.content
|
294 | 295 |
|
| 296 | + @pytest.mark.xfail( |
| 297 | + reason="falcon multipart form serialization unsupported", |
| 298 | + strict=True, |
| 299 | + ) |
| 300 | + def test_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 | + assert response.status_code == 200 |
| 332 | + |
295 | 333 |
|
296 | 334 | class TestPetDetailResource:
|
297 | 335 | def test_get_server_invalid(self, client):
|
|
0 commit comments