Coverage for tests/test_put_no_body.py: 100%
19 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 1abcde
2from fastapi.testclient import TestClient 1abcde
4app = FastAPI() 1abcde
7@app.put("/items/{item_id}") 1abcde
8def save_item_no_body(item_id: str): 1abcde
9 return {"item_id": item_id} 1abcde
12client = TestClient(app) 1abcde
15def test_put_no_body(): 1abcde
16 response = client.put("/items/foo") 1abcde
17 assert response.status_code == 200, response.text 1abcde
18 assert response.json() == {"item_id": "foo"} 1abcde
21def test_put_no_body_with_body(): 1abcde
22 response = client.put("/items/foo", json={"name": "Foo"}) 1abcde
23 assert response.status_code == 200, response.text 1abcde
24 assert response.json() == {"item_id": "foo"} 1abcde
27def test_openapi_schema(): 1abcde
28 response = client.get("/openapi.json") 1abcde
29 assert response.status_code == 200, response.text 1abcde
30 assert response.json() == { 1abcde
31 "openapi": "3.1.0",
32 "info": {"title": "FastAPI", "version": "0.1.0"},
33 "paths": {
34 "/items/{item_id}": {
35 "put": {
36 "responses": {
37 "200": {
38 "description": "Successful Response",
39 "content": {"application/json": {"schema": {}}},
40 },
41 "422": {
42 "description": "Validation Error",
43 "content": {
44 "application/json": {
45 "schema": {
46 "$ref": "#/components/schemas/HTTPValidationError"
47 }
48 }
49 },
50 },
51 },
52 "summary": "Save Item No Body",
53 "operationId": "save_item_no_body_items__item_id__put",
54 "parameters": [
55 {
56 "required": True,
57 "schema": {"title": "Item Id", "type": "string"},
58 "name": "item_id",
59 "in": "path",
60 }
61 ],
62 }
63 }
64 },
65 "components": {
66 "schemas": {
67 "ValidationError": {
68 "title": "ValidationError",
69 "required": ["loc", "msg", "type"],
70 "type": "object",
71 "properties": {
72 "loc": {
73 "title": "Location",
74 "type": "array",
75 "items": {
76 "anyOf": [{"type": "string"}, {"type": "integer"}]
77 },
78 },
79 "msg": {"title": "Message", "type": "string"},
80 "type": {"title": "Error Type", "type": "string"},
81 },
82 },
83 "HTTPValidationError": {
84 "title": "HTTPValidationError",
85 "type": "object",
86 "properties": {
87 "detail": {
88 "title": "Detail",
89 "type": "array",
90 "items": {"$ref": "#/components/schemas/ValidationError"},
91 }
92 },
93 },
94 }
95 },
96 }