1
2import json
3
4import aiohttp
5
6
7async def test_ok(service_client, load_binary):
8 form_data = aiohttp.FormData()
9
10
11 image = load_binary('logo_in_circle.png')
12 form_data.add_field('profileImage', image, filename='logo_in_circle.png')
13
14
15 address = {'street': '3, Garden St', 'city': 'Hillsbery, UT'}
16 form_data.add_field(
17 'address',
18 json.dumps(address),
19 content_type='application/json',
20 )
21
22
23 response = await service_client.post('/v1/multipart', data=form_data)
24 assert response.status == 200
25 assert 'application/json' in response.headers['Content-Type']
26 assert response.text == f'city={address["city"]} image_size={len(image)}'
27
28
29
30async def test_bad_content_type(service_client):
31 response = await service_client.post('/v1/multipart', data='{}')
32 assert response.status == 400
33 assert response.content == b"Expected 'multipart/form-data' content type"