Coverage for tests/test_repeated_parameter_alias.py: 100%
16 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 fastapi import FastAPI, Path, Query, status 1abcde
2from fastapi.testclient import TestClient 1abcde
4app = FastAPI() 1abcde
7@app.get("/{repeated_alias}") 1abcde
8def get_parameters_with_repeated_aliases( 1abcde
9 path: str = Path(..., alias="repeated_alias"),
10 query: str = Query(..., alias="repeated_alias"),
11):
12 return {"path": path, "query": query} 1abcde
15client = TestClient(app) 1abcde
18def test_get_parameters(): 1abcde
19 response = client.get("/test_path", params={"repeated_alias": "test_query"}) 1abcde
20 assert response.status_code == 200, response.text 1abcde
21 assert response.json() == {"path": "test_path", "query": "test_query"} 1abcde
24def test_openapi_schema(): 1abcde
25 response = client.get("/openapi.json") 1abcde
26 assert response.status_code == status.HTTP_200_OK 1abcde
27 actual_schema = response.json() 1abcde
28 assert actual_schema == { 1abcde
29 "components": {
30 "schemas": {
31 "HTTPValidationError": {
32 "properties": {
33 "detail": {
34 "items": {"$ref": "#/components/schemas/ValidationError"},
35 "title": "Detail",
36 "type": "array",
37 }
38 },
39 "title": "HTTPValidationError",
40 "type": "object",
41 },
42 "ValidationError": {
43 "properties": {
44 "loc": {
45 "items": {
46 "anyOf": [{"type": "string"}, {"type": "integer"}]
47 },
48 "title": "Location",
49 "type": "array",
50 },
51 "msg": {"title": "Message", "type": "string"},
52 "type": {"title": "Error Type", "type": "string"},
53 },
54 "required": ["loc", "msg", "type"],
55 "title": "ValidationError",
56 "type": "object",
57 },
58 }
59 },
60 "info": {"title": "FastAPI", "version": "0.1.0"},
61 "openapi": "3.1.0",
62 "paths": {
63 "/{repeated_alias}": {
64 "get": {
65 "operationId": "get_parameters_with_repeated_aliases__repeated_alias__get",
66 "parameters": [
67 {
68 "in": "path",
69 "name": "repeated_alias",
70 "required": True,
71 "schema": {"title": "Repeated Alias", "type": "string"},
72 },
73 {
74 "in": "query",
75 "name": "repeated_alias",
76 "required": True,
77 "schema": {"title": "Repeated Alias", "type": "string"},
78 },
79 ],
80 "responses": {
81 "200": {
82 "content": {"application/json": {"schema": {}}},
83 "description": "Successful Response",
84 },
85 "422": {
86 "content": {
87 "application/json": {
88 "schema": {
89 "$ref": "#/components/schemas/HTTPValidationError"
90 }
91 }
92 },
93 "description": "Validation Error",
94 },
95 },
96 "summary": "Get Parameters With Repeated Aliases",
97 }
98 }
99 },
100 }