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 import FastAPI
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel from pydantic import BaseModel
app = FastAPI() app = FastAPI()
@ -39,76 +40,78 @@ client = TestClient(app)
def test_openapi_schema(): def test_openapi_schema():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
"openapi": "3.1.0", {
"info": {"title": "FastAPI", "version": "0.1.0"}, "openapi": "3.1.0",
"paths": { "info": {"title": "FastAPI", "version": "0.1.0"},
"/a": { "paths": {
"get": { "/a": {
"responses": { "get": {
"500": { "responses": {
"description": "Error", "500": {
"content": { "description": "Error",
"application/vnd.api+json": { "content": {
"schema": { "application/vnd.api+json": {
"$ref": "#/components/schemas/JsonApiError" "schema": {
"$ref": "#/components/schemas/JsonApiError"
}
} }
} },
},
"200": {
"description": "Successful Response",
"content": {"application/vnd.api+json": {"schema": {}}},
}, },
}, },
"200": { "summary": "A",
"description": "Successful Response", "operationId": "a_a_get",
"content": {"application/vnd.api+json": {"schema": {}}}, }
},
"/b": {
"get": {
"responses": {
"500": {
"description": "Error",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/Error"}
}
},
},
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
}, },
}, "summary": "B",
"summary": "A", "operationId": "b_b_get",
"operationId": "a_a_get", }
} },
}, },
"/b": { "components": {
"get": { "schemas": {
"responses": { "Error": {
"500": { "title": "Error",
"description": "Error", "required": ["status", "title"],
"content": { "type": "object",
"application/json": { "properties": {
"schema": {"$ref": "#/components/schemas/Error"} "status": {"title": "Status", "type": "string"},
} "title": {"title": "Title", "type": "string"},
},
}, },
"200": { },
"description": "Successful Response", "JsonApiError": {
"content": {"application/json": {"schema": {}}}, "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 fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.behind_a_proxy.tutorial001_py39 import app from docs_src.behind_a_proxy.tutorial001_py39 import app
@ -14,22 +15,24 @@ def test_main():
def test_openapi(): def test_openapi():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == { assert response.json() == snapshot(
"openapi": "3.1.0", {
"info": {"title": "FastAPI", "version": "0.1.0"}, "openapi": "3.1.0",
"paths": { "info": {"title": "FastAPI", "version": "0.1.0"},
"/app": { "paths": {
"get": { "/app": {
"summary": "Read Main", "get": {
"operationId": "read_main_app_get", "summary": "Read Main",
"responses": { "operationId": "read_main_app_get",
"200": { "responses": {
"description": "Successful Response", "200": {
"content": {"application/json": {"schema": {}}}, "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 fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.behind_a_proxy.tutorial002_py39 import app from docs_src.behind_a_proxy.tutorial002_py39 import app
@ -14,22 +15,24 @@ def test_main():
def test_openapi(): def test_openapi():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == { assert response.json() == snapshot(
"openapi": "3.1.0", {
"info": {"title": "FastAPI", "version": "0.1.0"}, "openapi": "3.1.0",
"paths": { "info": {"title": "FastAPI", "version": "0.1.0"},
"/app": { "paths": {
"get": { "/app": {
"summary": "Read Main", "get": {
"operationId": "read_main_app_get", "summary": "Read Main",
"responses": { "operationId": "read_main_app_get",
"200": { "responses": {
"description": "Successful Response", "200": {
"content": {"application/json": {"schema": {}}}, "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 fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.extending_openapi.tutorial001_py39 import app from docs_src.extending_openapi.tutorial001_py39 import app
@ -14,32 +15,34 @@ def test():
def test_openapi_schema(): def test_openapi_schema():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
"openapi": "3.1.0", {
"info": { "openapi": "3.1.0",
"title": "Custom title", "info": {
"summary": "This is a very custom OpenAPI schema", "title": "Custom title",
"description": "Here's a longer description of the custom **OpenAPI** schema", "summary": "This is a very custom OpenAPI schema",
"version": "2.5.0", "description": "Here's a longer description of the custom **OpenAPI** schema",
"x-logo": { "version": "2.5.0",
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" "x-logo": {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
},
}, },
}, "paths": {
"paths": { "/items/": {
"/items/": { "get": {
"get": { "responses": {
"responses": { "200": {
"200": { "description": "Successful Response",
"description": "Successful Response", "content": {"application/json": {"schema": {}}},
"content": {"application/json": {"schema": {}}}, }
} },
}, "summary": "Read Items",
"summary": "Read Items", "operationId": "read_items_items__get",
"operationId": "read_items_items__get", }
} }
} },
}, }
} )
openapi_schema = response.json() openapi_schema = response.json()
# Request again to test the custom cache # Request again to test the custom cache
response = client.get("/openapi.json") response = client.get("/openapi.json")

Loading…
Cancel
Save