File: test_empty_body.py

package info (click to toggle)
flask-openapi3 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,224 kB
  • sloc: python: 4,807; makefile: 14; javascript: 5
file content (40 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
# @Author  : llc
# @Time    : 2021/12/1 9:39

import pytest
from pydantic import BaseModel

from flask_openapi3 import Info, OpenAPI

info = Info(title="book API", version="1.0.0")

app = OpenAPI(__name__, info=info)
app.config["TESTING"] = True


class CreateBookBody(BaseModel):
    pass

    model_config = {
        "extra": "allow",
    }


@pytest.fixture
def client():
    client = app.test_client()

    return client


@app.post("/book")
def create_book(body: CreateBookBody):
    print(body.model_dump())
    return {"code": 0, "message": "ok"}


def test_post(client):
    resp = client.post("/book", json={"aaa": 111, "bbb": 222})
    print(resp.json)
    assert resp.status_code == 200