Coverage for app/demo_test.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-19 10:29 +0000

1import unittest 

2 

3from fastapi.testclient import TestClient 

4 

5from .demo import app 

6 

7 

8class TestGetIndex(unittest.TestCase): 

9 def test_success(self) -> None: 

10 client = TestClient(app) 

11 response = client.get("/") 

12 self.assertEqual(response.status_code, 200) 

13 

14 def test_content_type(self) -> None: 

15 client = TestClient(app) 

16 response = client.get("/") 

17 self.assertEqual(response.headers.get("Content-Type"), "application/json") 

18 

19 

20class TestGetHello(unittest.TestCase): 

21 def test_default(self) -> None: 

22 client = TestClient(app) 

23 response = client.get("/hello") 

24 self.assertEqual(response.status_code, 200) 

25 self.assertEqual(response.json(), "Hello World.") 

26 

27 def test_angie(self) -> None: 

28 client = TestClient(app) 

29 response = client.get("/hello", params={"name": "Angie"}) 

30 self.assertEqual(response.status_code, 200) 

31 self.assertEqual(response.json(), "Hello Angie.") 

32 

33 

34# def test_bernd(self) -> None: 

35# client = TestClient(app) 

36# response = client.get("/hello", params={"name": "Bernd"}) 

37# self.assertEqual(response.status_code, 200) 

38# self.assertEqual(response.json(), "Bye.")