如何在Django中使用文本/文件测试AJAX表单?

时间:2015-01-13 18:05:02

标签: python ajax django testing

我正在为我的AJAX视图编写一个测试,它应该处理一些文本数据和图像。是否可以使用Django客户端,或者我应该使用Requests库进行此测试?

with open(somestring, "rb") as photo:
        updated_data = {
            'first_name': "updatedname",
            "last_name": "updatedlastname",
            "birth_date": str(date(2020, 5, 11).isoformat()),
            "email": "updateduser@example.com",
            "skype": "updateduser",
            # '"blah-blah" is not JSON serializable' raised 
            # "photo": photo
            }

        data = json.dumps(updated_data)
        # data is a string
        # with getRawImage() as photo:
        #     data.update({"photo": photo})



    self.client.post('/',
                     data,
                     content_type='application/json',
                     HTTP_X_REQUESTED_WITH='XMLHttpRequest'
    )

0 个答案:

没有答案