pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
recognizing_app = FastAPI()
|
|
ignoring_app = FastAPI(ignore_trailing_whitespaces=True)
|
|
|
|
@recognizing_app.get("/example")
|
|
@ignoring_app.get("/example")
|
|
async def return_data():
|
|
return {"msg": "Reached the route!"}
|
|
|
|
recognizing_client = TestClient(recognizing_app)
|
|
ignoring_client = TestClient(ignoring_app)
|
|
|
|
def test_recognizing_trailing_slash():
|
|
response = recognizing_client.get("/example", follow_redirects=False)
|
|
assert response.status_code == 200
|
|
assert response.json()["msg"] == "Reached the route!"
|
|
response = recognizing_client.get("/example/", follow_redirects=False)
|
|
assert response.status_code == 307
|
|
assert response.headers["location"].endswith("/example")
|
|
|
|
def test_ignoring_trailing_slash():
|
|
response = ignoring_client.get("/example", follow_redirects=False)
|
|
assert response.status_code == 200
|
|
assert response.json()["msg"] == "Reached the route!"
|
|
response = ignoring_client.get("/example/", follow_redirects=False)
|
|
assert response.status_code == 200
|
|
assert response.json()["msg"] == "Reached the route!"
|
|
|