Create fastapi/tests/test_tutorial/test_path_params /test_tutorial003.py

It can be interesting to note that although we have created two queries with the same path there are still two roots, one does not overwrite the other
This commit is contained in:
Mgcsuper 2024-04-19 07:39:36 +02:00 committed by GitHub
parent d1770a51b8
commit 219d098f77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
from fastapi.testclient import TestClient
from fastapi.routing import APIRoute
import docs_src.path_params.tutorial003 as t3
client = TestClient(t3.app)
def test_get_users():
response = client.get("/users")
print(response.json())
assert response.status_code == 200
assert response.json() == {"user_id": "the current user"}
def test_routes_created():
root1 = APIRoute(path='/users', endpoint=t3.read_user, methods=['GET'], name = "name='read_user")
root2 = APIRoute(path='/users', endpoint=t3.read_user_me, methods=['GET'], name = "name='read_user_me'")
assert (root1 in t3.app.router.routes) and (root2 in t3.app.router.routes)