Browse Source

Add test for `docs_src.response_directly.tutorial002.py`

pull/14569/head
Yurii Motov 7 months ago
parent
commit
5fb2efdcaa
  1. 69
      tests/test_tutorial/test_response_directly/test_tutorial002.py

69
tests/test_tutorial/test_response_directly/test_tutorial002.py

@ -0,0 +1,69 @@
import importlib
import pytest
from fastapi.testclient import TestClient
from ...utils import needs_pydanticv2
skip_for_pydantic_v1 = needs_pydanticv2
@pytest.fixture(
name="client",
params=[
pytest.param("tutorial002"),
],
)
def get_client(request: pytest.FixtureRequest):
mod = importlib.import_module(f"docs_src.response_directly.{request.param}")
client = TestClient(mod.app)
return client
def test_path_operation(client: TestClient):
expected_content = """<?xml version="1.0"?>
<shampoo>
<Header>
Apply shampoo here.
</Header>
<Body>
You'll have to use soap here.
</Body>
</shampoo>
"""
response = client.get("/legacy/")
assert response.status_code == 200, response.text
assert response.headers["content-type"] == "application/xml"
assert response.text == expected_content
def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == {
"info": {
"title": "FastAPI",
"version": "0.1.0",
},
"openapi": "3.1.0",
"paths": {
"/legacy/": {
"get": {
"operationId": "get_legacy_data_legacy__get",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {},
},
},
"description": "Successful Response",
},
},
"summary": "Get Legacy Data",
},
},
},
}
Loading…
Cancel
Save