userver: samples/multipart_service/tests/test_multipart.py
Loading...
Searching...
No Matches
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 'application/json' in response.headers['Content-Type']
24 assert response.text == f'city={address["city"]} image_size={len(image)}'
25 # /// [Functional test]
26
27
28async def test_bad_content_type(service_client):
29 response = await service_client.post('/v1/multipart', data='{}')
30 assert response.status == 400
31 assert response.content == b"Expected 'multipart/form-data' content type"