I wanted to test a simple function like this, called '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()
I created a file called 'posting_test.py', I know I have to import post.py, but after that I'm stuck. How can I test the response status code and assert that it's 200?
import unittest
from posting import post
Very generally:
class Mytest(unittest.TestCase):
def test_post(self):
response = post()
self.assertEqual(response.status_code, 200)