Coverage for tests/test_openapi_servers.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from dirty_equals import IsOneOf 1abcde
2from fastapi import FastAPI 1abcde
3from fastapi.testclient import TestClient 1abcde
5app = FastAPI( 1abcde
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") 1abcde
18def foo(): 1abcde
19 return {"message": "Hello World"} 1abcde
22client = TestClient(app) 1abcde
25def test_app(): 1abcde
26 response = client.get("/foo") 1abcde
27 assert response.status_code == 200, response.text 1abcde
30def test_openapi_schema(): 1abcde
31 response = client.get("/openapi.json") 1abcde
32 assert response.status_code == 200, response.text 1abcde
33 assert response.json() == { 1abcde
34 "openapi": "3.1.0",
35 "info": {"title": "FastAPI", "version": "0.1.0"},
36 "servers": [
37 {"url": "/", "description": "Default, relative server"},
38 {
39 "url": IsOneOf(
40 "http://staging.localhost.tiangolo.com:8000/",
41 # TODO: remove when deprecating Pydantic v1
42 "http://staging.localhost.tiangolo.com:8000",
43 ),
44 "description": "Staging but actually localhost still",
45 },
46 {
47 "url": IsOneOf(
48 "https://prod.example.com/",
49 # TODO: remove when deprecating Pydantic v1
50 "https://prod.example.com",
51 )
52 },
53 ],
54 "paths": {
55 "/foo": {
56 "get": {
57 "summary": "Foo",
58 "operationId": "foo_foo_get",
59 "responses": {
60 "200": {
61 "description": "Successful Response",
62 "content": {"application/json": {"schema": {}}},
63 }
64 },
65 }
66 }
67 },
68 }