File: test_default_query.py

package info (click to toggle)
flask-openapi3 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,976 kB
  • sloc: python: 4,754; sh: 17; makefile: 15; javascript: 5
file content (36 lines) | stat: -rw-r--r-- 731 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
# -*- coding: utf-8 -*-
# @Author  : llc
# @Time    : 2021/12/1 9:26
import pytest
from pydantic import BaseModel, Field

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 BookQuery(BaseModel):
    page: int = Field(1, description='current page')
    page_size: int = Field(15, description='size of per page')


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

    return client


@app.get('/book')
def get_book(query: BookQuery):
    print(query)
    return {"code": 0, "message": "ok"}


def test_get(client):
    resp = client.get("/book?page=2")
    print(resp.json)
    assert resp.status_code == 200