烧瓶测试失败,200!= <response streamed =“”[200 =“”ok] =“”>

时间:2018-05-07 17:21:47

标签: python python-3.x flask

我目前正在编写一个应该测试我的Flask(实际上是连接,使用烧瓶)API的测试。在这个测试中,我有以下陈述:

response_add_subscription_1 = self.app.post(
            '/user/alice/data_source/{}/subscriptions/{}'.format(ds_uuid1, dp_uuid), content_type='application/json')

self.assertEqual(200, response_add_subscription_1._status_code, "Status code of response for subscription "
                                                                        "registration of alice is not 200!")

但是,在运行测试时,它会抛出assert语句,并说:

AssertionError: 200 != <Response streamed [200 OK]>

当我将断言更改为

self.assertEqual('<Response streamed [200 OK]>', response_add_subscription_1._status_code, "Status code of response for subscription registration of alice is not 200!")

它仍然会抛出,但这次AssertionError是另一种方式:

AssertionError: '<Response streamed [200 OK]>' != 200

看来,我的状态代码同时是200'<Response streamed [200 OK]>',但绝不是我断言的。谁能给我一个暗示我在这里做错了什么?我的断言代码适用于其他API资源......

1 个答案:

答案 0 :(得分:0)

我正在使用内容类型的application / json,即使我没有通过帖子请求传递任何json ...

相关问题