我正在为我的视图编写测试用例,现在我想发送包含用户图像的用户凭据的多部分请求。 我使用MultipartWriter,但是当我尝试读取部件时,我得到的部件是None。 我确定我的测试用例写错了。
感谢您的帮助,抱歉我的英语不好。
我的测试用例:
async def test_users_post(app):
with open('user_photo.jpg', 'rb') as file:
user_data = dict(
name='Test1',
password='Password',
grand=True,
description='Blank',
email='test@test.ru',
file=file
)
with MultipartWriter() as mpwriter:
mpwriter.append_form([(key, value) for key, value in user_data.items()])
response = await app['client'].post('/users', data=mpwriter)
assert response.status == 201
起始视图行:
async def post(self):
reader = await self.request.multipart()
async with self.request.app['db'].acquire() as conn:
data = {}
while True:
field = await reader.next()
print(field) # field is None here
if not field:
# If not fields were read