Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python模拟REST API_Python_Rest_Unit Testing_Python Requests - Fatal编程技术网

Python模拟REST API

Python模拟REST API,python,rest,unit-testing,python-requests,Python,Rest,Unit Testing,Python Requests,我需要对一个有两个rest调用和另一个方法调用的方法进行单元测试。具体描述如下: class A(): def methA(self, param1): val1 = methB(someParam) res1 = requests.get(url1, headers=headers, verify=False) res2 = requests.post(endpoint, payload, headers=headers, verify=

我需要对一个有两个rest调用和另一个方法调用的方法进行单元测试。具体描述如下:

class A():
    def methA(self, param1):
        val1 = methB(someParam)
        res1 = requests.get(url1, headers=headers, verify=False)
        res2 = requests.post(endpoint, payload, headers=headers, verify=False)
        val2 = methC(someParam)
        return val2

    def methB(self, param1):
        res = requests.get(url, headers=headers, verify=False)
        return res

    def methC(self, param1):
        res = requests.get(url, headers=headers, verify=False)
        return res
现在,对于methB和methC方法,我用给出的解决方案模拟了rest调用。但是使用methA()我无法为两种不同类型(GET和POST)的两个不同REST调用修补mock。模拟此场景的可能解决方案是什么?
提前下载。

使用模拟API服务,该服务允许您模拟POST和GET请求。允许您这样做。这是一款适用于MacOS、Linux和Windows的可下载桌面应用程序,您可以使用它在本地主机上运行服务器,并轻松模拟您希望发送的响应