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 49 50 51
|
# -*- coding: utf-8 -*-
# @Author : llc
# @Time : 2022/12/19 10:34
import pytest
from flask_openapi3 import Info, Tag
from flask_openapi3 import OpenAPI, APIBlueprint
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
api1 = APIBlueprint("book1", __name__)
@api1.get('/book', tags=[Tag(name="book")])
def get_book():
... # pragma: no cover
api2 = APIBlueprint("book2", __name__)
@api2.get('/book2', tags=[Tag(name="book")])
def get_book2():
... # pragma: no cover
app.register_api(api1)
app.register_api(api2)
def test_openapi(client):
resp = client.get("/openapi/openapi.json")
_json = resp.json
assert resp.status_code == 200
tags = _json["tags"]
news_tags = []
for tag in tags:
if tag not in news_tags:
news_tags.append(tag)
assert news_tags == tags
|