Coverage for tests / test_openapi_servers.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI 1abcd
2from fastapi.testclient import TestClient 1abcd
3from inline_snapshot import snapshot 1abcd
5app = FastAPI( 1abcd
6 servers=[
7 {"url": "/", "description": "Default, relative server"},
8 {
9 "url": "http://staging.localhost.tiangolo.com:8000",
10 "description": "Staging but actually localhost still",
11 },
12 {"url": "https://prod.example.com"},
13 ]
14)
17@app.get("/foo") 1abcd
18def foo(): 1abcd
19 return {"message": "Hello World"} 1efg
22client = TestClient(app) 1abcd
25def test_app(): 1abcd
26 response = client.get("/foo") 1efg
27 assert response.status_code == 200, response.text 1efg
30def test_openapi_schema(): 1abcd
31 response = client.get("/openapi.json") 1hij
32 assert response.status_code == 200, response.text 1hij
33 assert response.json() == snapshot( 1hij
34 {
35 "openapi": "3.1.0",
36 "info": {"title": "FastAPI", "version": "0.1.0"},
37 "servers": [
38 {"url": "/", "description": "Default, relative server"},
39 {
40 "url": "http://staging.localhost.tiangolo.com:8000",
41 "description": "Staging but actually localhost still",
42 },
43 {"url": "https://prod.example.com"},
44 ],
45 "paths": {
46 "/foo": {
47 "get": {
48 "summary": "Foo",
49 "operationId": "foo_foo_get",
50 "responses": {
51 "200": {
52 "description": "Successful Response",
53 "content": {"application/json": {"schema": {}}},
54 }
55 },
56 }
57 }
58 },
59 }
60 )