-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
71 lines (62 loc) · 2.23 KB
/
test_api.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import unittest
import json
# TODO: separate
from fastapi.testclient import TestClient
from main import app, CONST_DEFAULT_MSG
test_item = {
"name": "Bananenshake",
"description": "Banana Shake Coffee",
"price": 10.0,
"tax": 19.0,
"total_price": 11.9,
"amount":0
}
class TestDependencies(unittest.TestCase):
def testUnitTest(self):
self.assertEqual(1,1,"Unit Tests funktionieren nicht")
def testHaveJSON(self):
import json
def testHaveFastAPI(self):
import fastapi
def testHaveTestClient(self):
import fastapi.testclient
return
def testHaveUvicorn(self):
import uvicorn
return
def testFoundMainModule(self):
import main
class TestAPIRoutes(unittest.TestCase):
def testRoute(self):
client = TestClient(app)
response = client.get("/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), CONST_DEFAULT_MSG)
def testGetItemsEmpty(self):
client = TestClient(app)
response = client.get("/items")
self.assertEqual(response.status_code, 200)
self.assertListEqual(response.json(), [])
def testPostItem(self):
client = TestClient(app)
response = client.post("/item", json=test_item)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), test_item)
def testPostAndGetItems(self):
client = TestClient(app)
response = client.post("/item", json=test_item)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), test_item)
response = client.get("/items")
self.assertEqual(response.status_code, 200)
self.assertListEqual(response.json(), [test_item])
def testPostAndClearItems(self):
client = TestClient(app)
response = client.post("/item", json=test_item)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), test_item)
response = client.get("/clear-items")
self.assertEqual(response.status_code, 200)
self.assertListEqual(response.json(), [])
if __name__ == "__main__":
unittest.main()