Browse Source

📸 Update snapshots

pull/14864/head
Sebastián Ramírez 5 months ago
parent
commit
1f51fa350d
  1. 129
      tests/test_additional_responses_response_class.py
  2. 39
      tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py
  3. 39
      tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py
  4. 51
      tests/test_tutorial/test_extending_openapi/test_tutorial001.py

129
tests/test_additional_responses_response_class.py

@ -1,6 +1,7 @@
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel
app = FastAPI()
@ -39,76 +40,78 @@ client = TestClient(app)
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/a": {
"get": {
"responses": {
"500": {
"description": "Error",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/JsonApiError"
assert response.json() == snapshot(
{
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/a": {
"get": {
"responses": {
"500": {
"description": "Error",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/JsonApiError"
}
}
}
},
},
"200": {
"description": "Successful Response",
"content": {"application/vnd.api+json": {"schema": {}}},
},
},
"200": {
"description": "Successful Response",
"content": {"application/vnd.api+json": {"schema": {}}},
"summary": "A",
"operationId": "a_a_get",
}
},
"/b": {
"get": {
"responses": {
"500": {
"description": "Error",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Error"}
}
},
},
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
},
},
"summary": "A",
"operationId": "a_a_get",
}
"summary": "B",
"operationId": "b_b_get",
}
},
},
"/b": {
"get": {
"responses": {
"500": {
"description": "Error",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Error"}
}
},
"components": {
"schemas": {
"Error": {
"title": "Error",
"required": ["status", "title"],
"type": "object",
"properties": {
"status": {"title": "Status", "type": "string"},
"title": {"title": "Title", "type": "string"},
},
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
"JsonApiError": {
"title": "JsonApiError",
"required": ["errors"],
"type": "object",
"properties": {
"errors": {
"title": "Errors",
"type": "array",
"items": {"$ref": "#/components/schemas/Error"},
}
},
},
"summary": "B",
"operationId": "b_b_get",
}
},
},
"components": {
"schemas": {
"Error": {
"title": "Error",
"required": ["status", "title"],
"type": "object",
"properties": {
"status": {"title": "Status", "type": "string"},
"title": {"title": "Title", "type": "string"},
},
},
"JsonApiError": {
"title": "JsonApiError",
"required": ["errors"],
"type": "object",
"properties": {
"errors": {
"title": "Errors",
"type": "array",
"items": {"$ref": "#/components/schemas/Error"},
}
},
},
}
},
}
}
)

39
tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py

@ -1,4 +1,5 @@
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.behind_a_proxy.tutorial001_py39 import app
@ -14,22 +15,24 @@ def test_main():
def test_openapi():
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/app": {
"get": {
"summary": "Read Main",
"operationId": "read_main_app_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
assert response.json() == snapshot(
{
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/app": {
"get": {
"summary": "Read Main",
"operationId": "read_main_app_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
}
}
}
},
"servers": [{"url": "/api/v1"}],
}
},
"servers": [{"url": "/api/v1"}],
}
)

39
tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py

@ -1,4 +1,5 @@
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.behind_a_proxy.tutorial002_py39 import app
@ -14,22 +15,24 @@ def test_main():
def test_openapi():
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/app": {
"get": {
"summary": "Read Main",
"operationId": "read_main_app_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
assert response.json() == snapshot(
{
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/app": {
"get": {
"summary": "Read Main",
"operationId": "read_main_app_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
}
}
}
},
"servers": [{"url": "/api/v1"}],
}
},
"servers": [{"url": "/api/v1"}],
}
)

51
tests/test_tutorial/test_extending_openapi/test_tutorial001.py

@ -1,4 +1,5 @@
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.extending_openapi.tutorial001_py39 import app
@ -14,32 +15,34 @@ def test():
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == {
"openapi": "3.1.0",
"info": {
"title": "Custom title",
"summary": "This is a very custom OpenAPI schema",
"description": "Here's a longer description of the custom **OpenAPI** schema",
"version": "2.5.0",
"x-logo": {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
assert response.json() == snapshot(
{
"openapi": "3.1.0",
"info": {
"title": "Custom title",
"summary": "This is a very custom OpenAPI schema",
"description": "Here's a longer description of the custom **OpenAPI** schema",
"version": "2.5.0",
"x-logo": {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
},
},
},
"paths": {
"/items/": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Items",
"operationId": "read_items_items__get",
"paths": {
"/items/": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Items",
"operationId": "read_items_items__get",
}
}
}
},
}
},
}
)
openapi_schema = response.json()
# Request again to test the custom cache
response = client.get("/openapi.json")

Loading…
Cancel
Save