简体   繁体   English

Django Rest Framework-测试客户端发布整数列表

[英]Django Rest Framework - Test Client Post list of integers

I'm doing an app using django and I want to unit test my viewsets. 我正在使用Django做一个应用程序,并且想对我的视图集进行单元测试。

I can test almost everything but, everytime I send an integer or a list to the viewset via API Client, in the viewset, the integer is converted to a string, therefore, that's a big fail for me :( 我几乎可以测试所有内容,但是每次我通过API客户端将整数或列表发送到视图集时,在视图集中,该整数都会转换为字符串,因此,这对我来说是一个很大的失败:(

Example - test file: 示例 -测试文件:

body = {
    "age": 60
}
client = APIClient()
res = client.post(url, body, **headers, type='json')

In the ViewSet: request.data 在ViewSet中: request.data

{
    "age" "60"
}

这有效:

client.post(url, json.dumps(body), **headers, format='json', content_type='application/json')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM