mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-26 09:52:26 -04:00
📝 Add new docs section, How To - Recipes, move docs that don't have to be read by everyone to How To (#10114)
* 📝 Start How To docs section, move Peewee, remove Peewee from dependencies * 🚚 Move em files to new locations * 🚚 Move and re-structure advanced docs, move relevant to How To * 🔧 Update MkDocs config, new files in How To * 📝 Move docs for Conditional OpenAPI for Japanese to How To * 📝 Move example source files for Extending OpenAPI into each of the new sections * ✅ Update tests with new locations for source files * 🔥 Remove init from Peewee examples
This commit is contained in:
committed by
GitHub
parent
3971c44a38
commit
8cd7cfc2b6
@@ -1,42 +0,0 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def client():
|
||||
static_dir: Path = Path(os.getcwd()) / "static"
|
||||
print(static_dir)
|
||||
static_dir.mkdir(exist_ok=True)
|
||||
from docs_src.extending_openapi.tutorial002 import app
|
||||
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
static_dir.rmdir()
|
||||
|
||||
|
||||
def test_swagger_ui_html(client: TestClient):
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
assert "/static/swagger-ui-bundle.js" in response.text
|
||||
assert "/static/swagger-ui.css" in response.text
|
||||
|
||||
|
||||
def test_swagger_ui_oauth2_redirect_html(client: TestClient):
|
||||
response = client.get("/docs/oauth2-redirect")
|
||||
assert response.status_code == 200, response.text
|
||||
assert "window.opener.swaggerUIRedirectOauth2" in response.text
|
||||
|
||||
|
||||
def test_redoc_html(client: TestClient):
|
||||
response = client.get("/redoc")
|
||||
assert response.status_code == 200, response.text
|
||||
assert "/static/redoc.standalone.js" in response.text
|
||||
|
||||
|
||||
def test_api(client: TestClient):
|
||||
response = client.get("/users/john")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json()["message"] == "Hello john"
|
||||
@@ -1,41 +0,0 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from docs_src.extending_openapi.tutorial003 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_swagger_ui():
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
assert (
|
||||
'"syntaxHighlight": false' in response.text
|
||||
), "syntaxHighlight should be included and converted to JSON"
|
||||
assert (
|
||||
'"dom_id": "#swagger-ui"' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert "presets: [" in response.text, "default configs should be preserved"
|
||||
assert (
|
||||
"SwaggerUIBundle.presets.apis," in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
"SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"layout": "BaseLayout",' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"deepLinking": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"showExtensions": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"showCommonExtensions": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
|
||||
|
||||
def test_get_users():
|
||||
response = client.get("/users/foo")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {"message": "Hello foo"}
|
||||
@@ -1,44 +0,0 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from docs_src.extending_openapi.tutorial004 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_swagger_ui():
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
assert (
|
||||
'"syntaxHighlight": false' not in response.text
|
||||
), "not used parameters should not be included"
|
||||
assert (
|
||||
'"syntaxHighlight.theme": "obsidian"' in response.text
|
||||
), "parameters with middle dots should be included in a JSON compatible way"
|
||||
assert (
|
||||
'"dom_id": "#swagger-ui"' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert "presets: [" in response.text, "default configs should be preserved"
|
||||
assert (
|
||||
"SwaggerUIBundle.presets.apis," in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
"SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"layout": "BaseLayout",' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"deepLinking": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"showExtensions": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"showCommonExtensions": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
|
||||
|
||||
def test_get_users():
|
||||
response = client.get("/users/foo")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {"message": "Hello foo"}
|
||||
@@ -1,44 +0,0 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from docs_src.extending_openapi.tutorial005 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_swagger_ui():
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
assert (
|
||||
'"deepLinking": false,' in response.text
|
||||
), "overridden configs should be preserved"
|
||||
assert (
|
||||
'"deepLinking": true' not in response.text
|
||||
), "overridden configs should not include the old value"
|
||||
assert (
|
||||
'"syntaxHighlight": false' not in response.text
|
||||
), "not used parameters should not be included"
|
||||
assert (
|
||||
'"dom_id": "#swagger-ui"' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert "presets: [" in response.text, "default configs should be preserved"
|
||||
assert (
|
||||
"SwaggerUIBundle.presets.apis," in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
"SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"layout": "BaseLayout",' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"showExtensions": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
assert (
|
||||
'"showCommonExtensions": true,' in response.text
|
||||
), "default configs should be preserved"
|
||||
|
||||
|
||||
def test_get_users():
|
||||
response = client.get("/users/foo")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {"message": "Hello foo"}
|
||||
Reference in New Issue
Block a user