Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ASGI root_path for openapi docs #1199

Merged
merged 11 commits into from
Jun 11, 2020
Prev Previous commit
Next Next commit
✅ Add tests for Behind a Proxy with root_path
  • Loading branch information
tiangolo committed Jun 11, 2020
commit 07d7c37e1b280adfc568e3fb2383eeb33d17930f
Empty file.
36 changes: 36 additions & 0 deletions tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from fastapi.testclient import TestClient

from behind_a_proxy.tutorial001 import app

client = TestClient(app, root_path="/api/v1")

openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/api/v1/app": {
"get": {
"summary": "Read Main",
"operationId": "read_main_app_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
}
}
},
}


def test_openapi():
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == openapi_schema


def test_main():
response = client.get("/app")
assert response.status_code == 200
assert response.json() == {"message": "Hello World", "root_path": "/api/v1"}
36 changes: 36 additions & 0 deletions tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from fastapi.testclient import TestClient

from behind_a_proxy.tutorial002 import app

client = TestClient(app)

openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/api/v1/app": {
"get": {
"summary": "Read Main",
"operationId": "read_main_app_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
}
}
},
}


def test_openapi():
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == openapi_schema


def test_main():
response = client.get("/app")
assert response.status_code == 200
assert response.json() == {"message": "Hello World", "root_path": "/api/v1"}