Coverage for tests/test_tutorial/test_first_steps/test_tutorial001.py: 100%
13 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
1import pytest 1abcde
2from fastapi.testclient import TestClient 1abcde
4from docs_src.first_steps.tutorial001 import app 1abcde
6client = TestClient(app) 1abcde
9@pytest.mark.parametrize( 1abcde
10 "path,expected_status,expected_response",
11 [
12 ("/", 200, {"message": "Hello World"}),
13 ("/nonexistent", 404, {"detail": "Not Found"}),
14 ],
15)
16def test_get_path(path, expected_status, expected_response): 1abcde
17 response = client.get(path) 1abcde
18 assert response.status_code == expected_status 1abcde
19 assert response.json() == expected_response 1abcde
22def test_openapi_schema(): 1abcde
23 response = client.get("/openapi.json") 1abcde
24 assert response.status_code == 200 1abcde
25 assert response.json() == { 1abcde
26 "openapi": "3.1.0",
27 "info": {"title": "FastAPI", "version": "0.1.0"},
28 "paths": {
29 "/": {
30 "get": {
31 "responses": {
32 "200": {
33 "description": "Successful Response",
34 "content": {"application/json": {"schema": {}}},
35 }
36 },
37 "summary": "Root",
38 "operationId": "root__get",
39 }
40 }
41 },
42 }