1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-09-09 05:08:32 +00:00
actix-web/examples/multipart/client.py

35 lines
942 B
Python
Raw Normal View History

2017-12-19 18:25:23 +00:00
# This script could be used for actix-web multipart example test
# just start server and run client.py
2017-10-19 06:43:50 +00:00
import asyncio
import aiohttp
2017-12-19 17:51:28 +00:00
async def req1():
2017-10-19 06:43:50 +00:00
with aiohttp.MultipartWriter() as writer:
writer.append('test')
writer.append_json({'passed': True})
2017-12-19 17:51:28 +00:00
resp = await aiohttp.ClientSession().request(
2017-10-19 06:43:50 +00:00
"post", 'http://localhost:8080/multipart',
data=writer, headers=writer.headers)
print(resp)
assert 200 == resp.status
2017-12-19 17:51:28 +00:00
async def req2():
2017-10-19 23:22:21 +00:00
with aiohttp.MultipartWriter() as writer:
writer.append('test')
writer.append_json({'passed': True})
writer.append(open('src/main.rs'))
2017-12-19 17:51:28 +00:00
resp = await aiohttp.ClientSession().request(
2017-10-19 23:22:21 +00:00
"post", 'http://localhost:8080/multipart',
data=writer, headers=writer.headers)
print(resp)
assert 200 == resp.status
2017-10-19 06:43:50 +00:00
loop = asyncio.get_event_loop()
2017-10-19 23:22:21 +00:00
loop.run_until_complete(req1())
loop.run_until_complete(req2())