userver: samples/multipart_service/tests/test_multipart.py
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
samples/multipart_service/tests/test_multipart.py
1# /// [Functional test]
2import json
3
4import aiohttp
5
6
7async def test_ok(service_client, load_binary):
8 form_data = aiohttp.FormData()
9
10 # Uploading file
11 image = load_binary('logo_in_circle.png')
12 form_data.add_field('profileImage', image, filename='logo_in_circle.png')
13
14 # Adding JSON payload
15 address = {'street': '3, Garden St', 'city': 'Hillsbery, UT'}
16 form_data.add_field(
17 'address', json.dumps(address), content_type='application/json',
18 )
19
20 # Making a request and checking the result
21 response = await service_client.post('/v1/multipart', data=form_data)
22 assert response.status == 200
23 assert response.text == f'city={address["city"]} image_size={len(image)}'
24 # /// [Functional test]
25
26
27async def test_bad_content_type(service_client):
28 response = await service_client.post('/v1/multipart', data='{}')
29 assert response.status == 400
30 assert response.content == b'Expected \'multipart/form-data\' content type'