我想测试一个这样的简单函数,名为" 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
答案 0 :(得分:2)
非常普遍:
class Mytest(unittest.TestCase):
def test_post(self):
response = post()
self.assertEqual(response.status_code, 200)