-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_hello.py
More file actions
32 lines (25 loc) · 1.43 KB
/
Copy pathtest_hello.py
File metadata and controls
32 lines (25 loc) · 1.43 KB
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
import unittest
from fastapi import status
from .utils import get_test_client
class TestResourceHello(unittest.TestCase):
def test_hello(self):
"""Tests the Hello World API"""
with get_test_client() as client:
res = client.get("/hello").raise_for_status()
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertDictEqual(res.json(), {"message": "Hello, World!"})
def test_greet_name(self):
"""Tests the greeting API (echo)"""
with get_test_client() as client:
with self.subTest("Generic name"):
res = client.get("/hello/greet", params={"name": "TestClient"}).raise_for_status()
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertDictEqual(res.json(), {"message": "Hello, TestClient!"})
with self.subTest("Emoji"):
res = client.get("/hello/greet", params={"name": "🚀 FastAPI"}).raise_for_status()
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertDictEqual(res.json(), {"message": "Hello, 🚀 FastAPI!"})
with self.subTest("Control Characters"):
res = client.get("/hello/greet", params={"name": "John\tAdam\nDoe"}).raise_for_status()
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertDictEqual(res.json(), {"message": "Hello, John\tAdam\nDoe!"})