为 post 方法模拟测试 api

Mock testing an api for post method

我正在尝试为其他人编码的 api 编写模拟测试,我的职责是测试模块的 post 方法。该模块被编写来完成处理程序的工作,它使用 BaseHandler 作为 super class.

我需要的是 how/what 在为 http post 方法编写模拟测试时进行模拟。我应该模仿 post 请求吗?还是做一个真人?或者还有什么?

不允许我分享任何代码,但是代码使用tornado连接本地主机,mongodb用于数据库读写,使用Python 3.6.[=12=编写]

欢迎任何想法。从现在开始谢谢。

import mock

class Test(ApiTestCase):
    @mock.patch.object(send_sms, 'delay'):
    def test_send_sms(self, send_sms_mock):
        data = {}
        resp = self.client.post(self.url, data, format='json')
        assert send_sms_mock.call_count == 1

这是模拟的基本示例 post