-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.py
30 lines (23 loc) · 871 Bytes
/
main_test.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
import unittest
import json
from fastapi.testclient import TestClient
from main import app
class TestApp(unittest.TestCase):
def setUp(self):
self.client = TestClient(app)
with open("data.json", "r") as f:
self.data = json.load(f)
def test_read_data(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), self.data)
def test_read_data_by_guid(self):
guid = self.data[0]["guid"]
response = self.client.get(f"/{guid}")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), self.data[0])
def test_read_data_by_invalid_guid(self):
response = self.client.get("/invalid-guid")
self.assertEqual(response.status_code, 404)
if __name__ == "__main__":
unittest.main()