-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with FastAPI mounts. (#1183)
- Loading branch information
Showing
6 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Tests the FastAPI server can be mounted.""" | ||
|
||
from fastapi import FastAPI | ||
from fastapi.testclient import TestClient | ||
|
||
from .server import app as lilac_app | ||
|
||
app = FastAPI() | ||
|
||
MOUNT_POINT = '/lilac_sub' | ||
|
||
|
||
@app.get('/') | ||
def read_main() -> dict: | ||
"""The main endpoint.""" | ||
return {'message': 'hello world'} | ||
|
||
|
||
app.mount(MOUNT_POINT, lilac_app) | ||
client = TestClient(app) | ||
|
||
|
||
def test_mount_root() -> None: | ||
response = client.get('/', allow_redirects=False) | ||
assert response.status_code == 200 | ||
assert response.json() == {'message': 'hello world'} | ||
|
||
|
||
def test_mount_slash_redirect() -> None: | ||
response = client.get(f'{MOUNT_POINT}/auth_info/', allow_redirects=False) | ||
assert response.status_code == 307 | ||
# We should redirect to the URL with slash removed. | ||
assert response.headers['location'] == f'{MOUNT_POINT}/auth_info' | ||
|
||
# Allow redirects to follow through. | ||
response = client.get(f'{MOUNT_POINT}/auth_info/', allow_redirects=True) | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters