Browse Source

Add test for `docs_src.response_status_code.tutorial001.py` and `docs_src.response_status_code.tutorial002.py`

pull/14569/head
Yurii Motov 7 months ago
parent
commit
e5a43bc575
  1. 0
      tests/test_tutorial/test_response_status_code/__init__.py
  2. 96
      tests/test_tutorial/test_response_status_code/test_tutorial001_tutorial002.py

0
tests/test_tutorial/test_response_status_code/__init__.py

96
tests/test_tutorial/test_response_status_code/test_tutorial001_tutorial002.py

@ -0,0 +1,96 @@
import importlib
import pytest
from fastapi.testclient import TestClient
@pytest.fixture(
name="client",
params=[
pytest.param("tutorial001"),
pytest.param("tutorial002"),
],
)
def get_client(request: pytest.FixtureRequest):
mod = importlib.import_module(f"docs_src.response_status_code.{request.param}")
client = TestClient(mod.app)
return client
def test_create_item(client: TestClient):
response = client.post("/items/", params={"name": "Test Item"})
assert response.status_code == 201, response.text
assert response.json() == {"name": "Test Item"}
def test_openapi_schema(client: TestClient):
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": {
"/items/": {
"post": {
"parameters": [
{
"name": "name",
"in": "query",
"required": True,
"schema": {"title": "Name", "type": "string"},
}
],
"summary": "Create Item",
"operationId": "create_item_items__post",
"responses": {
"201": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
}
}
},
"components": {
"schemas": {
"ValidationError": {
"title": "ValidationError",
"required": ["loc", "msg", "type"],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"anyOf": [{"type": "string"}, {"type": "integer"}]
},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
},
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"},
}
},
},
}
},
}
Loading…
Cancel
Save