-
-
Notifications
You must be signed in to change notification settings - Fork 754
/
test_aiohttp_datetime.py
52 lines (42 loc) · 1.91 KB
/
test_aiohttp_datetime.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
import asyncio
from connexion import AioHttpApp
try:
import ujson as json
except ImportError:
import json
@asyncio.coroutine
def test_swagger_json(aiohttp_api_spec_dir, aiohttp_client):
""" Verify the swagger.json file is returned for default setting passed to app. """
app = AioHttpApp(__name__, port=5001,
specification_dir=aiohttp_api_spec_dir,
debug=True)
app.add_api('datetime_support.yaml')
app_client = yield from aiohttp_client(app.app)
swagger_json = yield from app_client.get('/v1.0/openapi.json')
spec_data = yield from swagger_json.json()
def get_value(data, path):
for part in path.split('.'):
data = data.get(part)
assert data, "No data in part '{}' of '{}'".format(part, path)
return data
example = get_value(spec_data, 'paths./datetime.get.responses.200.content.application/json.schema.example.value')
assert example in [
'2000-01-23T04:56:07.000008+00:00', # PyYAML 5.3
'2000-01-23T04:56:07.000008Z'
]
example = get_value(spec_data, 'paths./date.get.responses.200.content.application/json.schema.example.value')
assert example == '2000-01-23'
example = get_value(spec_data, 'paths./uuid.get.responses.200.content.application/json.schema.example.value')
assert example == 'a7b8869c-5f24-4ce0-a5d1-3e44c3663aa9'
resp = yield from app_client.get('/v1.0/datetime')
assert resp.status == 200
json_data = yield from resp.json()
assert json_data == {'value': '2000-01-02T03:04:05.000006Z'}
resp = yield from app_client.get('/v1.0/date')
assert resp.status == 200
json_data = yield from resp.json()
assert json_data == {'value': '2000-01-02'}
resp = yield from app_client.get('/v1.0/uuid')
assert resp.status == 200
json_data = yield from resp.json()
assert json_data == {'value': 'e7ff66d0-3ec2-4c4e-bed0-6e4723c24c51'}