test_cors() — fastapi Function Reference
Architecture documentation for the test_cors() function in test_tutorial001.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD e4936408_8abe_039b_3eb9_fcd59ecb05a0["test_cors()"] a53c9491_3c09_f5bb_f708_b9589ee8c416["test_tutorial001.py"] e4936408_8abe_039b_3eb9_fcd59ecb05a0 -->|defined in| a53c9491_3c09_f5bb_f708_b9589ee8c416 style e4936408_8abe_039b_3eb9_fcd59ecb05a0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_tutorial/test_cors/test_tutorial001.py lines 6–37
def test_cors():
client = TestClient(app)
# Test pre-flight response
headers = {
"Origin": "https://localhost.tiangolo.com",
"Access-Control-Request-Method": "GET",
"Access-Control-Request-Headers": "X-Example",
}
response = client.options("/", headers=headers)
assert response.status_code == 200, response.text
assert response.text == "OK"
assert (
response.headers["access-control-allow-origin"]
== "https://localhost.tiangolo.com"
)
assert response.headers["access-control-allow-headers"] == "X-Example"
# Test standard response
headers = {"Origin": "https://localhost.tiangolo.com"}
response = client.get("/", headers=headers)
assert response.status_code == 200, response.text
assert response.json() == {"message": "Hello World"}
assert (
response.headers["access-control-allow-origin"]
== "https://localhost.tiangolo.com"
)
# Test non-CORS response
response = client.get("/")
assert response.status_code == 200, response.text
assert response.json() == {"message": "Hello World"}
assert "access-control-allow-origin" not in response.headers
Domain
Subdomains
Source
Frequently Asked Questions
What does test_cors() do?
test_cors() is a function in the fastapi codebase, defined in tests/test_tutorial/test_cors/test_tutorial001.py.
Where is test_cors() defined?
test_cors() is defined in tests/test_tutorial/test_cors/test_tutorial001.py at line 6.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free