如何在 Python (Trello) 中为 POST 函数编写单元测试?

How to write a unittest for POST function in Python (Trello)?

我想测试这样一个简单的函数,叫做 'posting.py':

import requests

def post():
        url = "https://api.trello.com/1/cards"
        params = {"key": "my_key",
                  "token": "my_token",
                  "name": "random_name",
                  "idList": "id"}
        response = requests.post(url=url, params=params)
        return response
post()

我创建了一个名为 'posting_test.py' 的文件,我知道我必须导入 post.py,但之后我就卡住了。我如何测试响应状态代码并断言它是 200?

import unittest
from posting import post

非常普遍:

class Mytest(unittest.TestCase):

    def test_post(self):
        response = post()
        self.assertEqual(response.status_code, 200)