forked from apiflask/apiflask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_openapi_info.py
107 lines (90 loc) · 3.18 KB
/
test_openapi_info.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from openapi_spec_validator import validate_spec
from apiflask import APIFlask
def test_info_title_and_version(app):
assert app.title == 'APIFlask'
assert app.version == '0.1.0'
app = APIFlask(__name__, title='Foo', version='1.0')
assert app.spec['info']['title'] == 'Foo'
assert app.spec['info']['version'] == '1.0'
def test_other_info_fields(app, client):
assert app.description is None
assert app.terms_of_service is None
assert app.contact is None
assert app.license is None
app.description = 'My API'
app.terms_of_service = 'http://example.com/terms/'
app.contact = {
'name': 'API Support',
'url': 'http://www.example.com/support',
'email': '[email protected]'
}
app.license = {
'name': 'Apache 2.0',
'url': 'http://www.apache.org/licenses/LICENSE-2.0.html'
}
rv = client.get('/openapi.json')
assert rv.status_code == 200
validate_spec(rv.json)
assert rv.json['info']['description'] == app.description
assert rv.json['info']['termsOfService'] == app.terms_of_service
assert rv.json['info']['contact'] == app.contact
assert rv.json['info']['license'] == app.license
def test_info_attribute(app, client):
assert app.info is None
app.info = {
'description': 'My API',
'termsOfService': 'http://example.com',
'contact': {
'name': 'API Support',
'url': 'http://www.example.com/support',
'email': '[email protected]'
},
'license': {
'name': 'Apache 2.0',
'url': 'http://www.apache.org/licenses/LICENSE-2.0.html'
}
}
rv = client.get('/openapi.json')
assert rv.status_code == 200
validate_spec(rv.json)
assert rv.json['info']['description'] == app.info['description']
assert rv.json['info']['termsOfService'] == app.info['termsOfService']
assert rv.json['info']['contact'] == app.info['contact']
assert rv.json['info']['license'] == app.info['license']
def test_overwirte_info_attribute(app, client):
assert app.info is None
assert app.description is None
assert app.terms_of_service is None
assert app.contact is None
assert app.license is None
app.info = {
'description': 'Not set',
'termsOfService': 'Not set',
'contact': {
'name': 'Not set',
'url': 'Not set',
'email': 'Not set'
},
'license': {
'name': 'Not set',
'url': 'Not set'
}
}
app.description = 'My API'
app.terms_of_service = 'http://example.com/terms/'
app.contact = {
'name': 'API Support',
'url': 'http://www.example.com/support',
'email': '[email protected]'
}
app.license = {
'name': 'Apache 2.0',
'url': 'http://www.apache.org/licenses/LICENSE-2.0.html'
}
rv = client.get('/openapi.json')
assert rv.status_code == 200
validate_spec(rv.json)
assert rv.json['info']['description'] == app.description
assert rv.json['info']['termsOfService'] == app.terms_of_service
assert rv.json['info']['contact'] == app.contact
assert rv.json['info']['license'] == app.license