Skip to content

Commit 4694540

Browse files
test: ex_7_3
1 parent d0678b3 commit 4694540

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pytest~=8.3.3
22
httpx~=0.27.2
33
uvicorn~=0.30.2
44
gunicorn~=19.9.0
5+
starlette==0.37.2

tests/test_ch7.py

+12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import os
33
import unittest
44
from unittest.mock import patch, AsyncMock, MagicMock
5+
from starlette.testclient import TestClient
56
import threading
67
import requests
78
import time
89
sys.path.append(os.path.abspath('docs/7. Web Applications'))
910
import ex_7_1 as ex1
1011
import ex_7_2 as ex2
12+
import ex_7_3 as ex3
1113

1214

1315
class TestGunicornApp(unittest.TestCase):
@@ -45,5 +47,15 @@ async def test_app_uvicorn(self):
4547
send_data.assert_any_call(data2_to_send)
4648

4749

50+
class TestStarletteHomepage(unittest.TestCase):
51+
def setUp(self):
52+
self.client = TestClient(ex3.app)
53+
54+
def test_homepage(self):
55+
response = self.client.get('/')
56+
self.assertEqual(response.status_code, 200)
57+
self.assertEqual(response.json(), {'hello': 'world'})
58+
59+
4860
if __name__ == '__main__':
4961
unittest.main()

0 commit comments

Comments
 (0)