fastapi

Форк
0
/
test_additional_response_extra.py 
49 строк · 1.2 Кб
1
from fastapi import APIRouter, FastAPI
2
from fastapi.testclient import TestClient
3

4
router = APIRouter()
5

6
sub_router = APIRouter()
7

8
app = FastAPI()
9

10

11
@sub_router.get("/")
12
def read_item():
13
    return {"id": "foo"}
14

15

16
router.include_router(sub_router, prefix="/items")
17

18
app.include_router(router)
19

20
client = TestClient(app)
21

22

23
def test_path_operation():
24
    response = client.get("/items/")
25
    assert response.status_code == 200, response.text
26
    assert response.json() == {"id": "foo"}
27

28

29
def test_openapi_schema():
30
    response = client.get("/openapi.json")
31
    assert response.status_code == 200, response.text
32
    assert response.json() == {
33
        "openapi": "3.1.0",
34
        "info": {"title": "FastAPI", "version": "0.1.0"},
35
        "paths": {
36
            "/items/": {
37
                "get": {
38
                    "responses": {
39
                        "200": {
40
                            "description": "Successful Response",
41
                            "content": {"application/json": {"schema": {}}},
42
                        }
43
                    },
44
                    "summary": "Read Item",
45
                    "operationId": "read_item_items__get",
46
                }
47
            }
48
        },
49
    }
50

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.