File: test_summary.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 (48 lines) | stat: -rw-r--r-- 1,241 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
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# @Author  : llc
# @Time    : 2022/1/1 16:54

import pytest

from flask_openapi3 import Info
from flask_openapi3 import OpenAPI

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

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


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

    return client


@app.get('/book', summary='new summary', description='new description')
def get_book():
    """Get a book
    to get some book by id, like:
    http://localhost:5000/book/3
    """
    return {"code": 0, "message": "ok"}  # pragma: no cover


@app.get('/book2', description='new description')
def get_book2():
    """Get a book
    to get some book by id, like:
    http://localhost:5000/book/3
    """
    return {"code": 0, "message": "ok"}  # pragma: no cover


def test_openapi(client):
    resp = client.get("/openapi/openapi.json")
    _json = resp.json
    assert resp.status_code == 200
    assert _json['paths']['/book']['get']['summary'] == 'new summary'
    assert _json['paths']['/book']['get']['description'] == 'new description'
    assert _json['paths']['/book2']['get']['summary'] == 'Get a book'
    assert _json['paths']['/book2']['get']['description'] == 'new description'