- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_tests.py
More file actions
Latest commit
31 lines (24 loc) · 880 Bytes
/
Copy pathunit_tests.py
File metadata and controls
31 lines (24 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
importunittest
importmain
frommainimportapp
fromfastapiimportFastAPI
fromfastapi.testclientimportTestClient
client=TestClient(app)
classTestStringMethods(unittest.TestCase):
deftest_root(self):
root_value=main.read_root()
self.assertEqual(root_value['Hello'], 'World')
deftest_get_quote(self):
first_quote=main.read_item(1)
self.assertEqual(first_quote.id, 1)
self.assertEqual(first_quote.author, 'Lemmy Kilmister')
deftest_insert_quote(self):
response=client.post(
"/items/",
headers={"X-Token": "coneofsilence"},
json={"id": 100, "quote":"New quote", "author":"New author"},
)
assertresponse.status_code==200
assertresponse.json() == {"id": 100, "quote":"New quote", "author":"New author"}
if__name__=='__main__':
unittest.main()