-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·116 lines (82 loc) · 2.71 KB
/
tests.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
108
109
110
111
112
113
114
115
116
import pytest
from server import create_app
from config import Test as TestConfig
@pytest.fixture(name='test_app')
def _test_app():
'''Create testing app fixture
App defined TestConfig class
Returns:
quart.Quart -- app
'''
app = create_app(TestConfig)
return app
@pytest.mark.asyncio
async def test_initial_post(test_app):
'''Initial test with helthcheck endpoint
Testing GET
'''
test_client = test_app.test_client()
response = await test_client.post('/healthcheck')
assert response.status_code == 200
result = await response.get_json()
assert result['status'] == 'OK'
@pytest.mark.asyncio
async def test_initial_get(test_app):
'''Initial test with helthcheck endpoint
Testing POST
'''
test_client = test_app.test_client()
response = await test_client.get('/healthcheck')
assert response.status_code == 200
result = await response.get_json()
assert result['status'] == 'OK'
@pytest.mark.asyncio
async def test_generate_get(test_app):
'''Generation API
Testing GET
'''
test_client = test_app.test_client()
response = await test_client.get('api/generate')
assert response.status_code == 200
result = await response.get_json()
assert 'music' in result
assert len(result['music']) > 0
@pytest.mark.asyncio
async def test_generate_post(test_app):
'''Generation API
Testing POST
'''
test_client = test_app.test_client()
data = {}
response = await test_client.post('api/generate',
json=data)
assert response.status_code == 200
result = await response.get_json()
assert 'music' in result
assert len(result['music']) > 0
@pytest.mark.asyncio
async def test_generate_post_without_prefix(test_app):
'''Generation API
Testing POST with [prefix] param without return
'''
test_client = test_app.test_client()
data = {'prefix': 'BB/2c'}
response = await test_client.post('api/generate',
json=data)
assert response.status_code == 200
result = await response.get_json()
assert len(result['music']) > 0
assert not result['music'].startswith(data['prefix'])
@pytest.mark.asyncio
async def test_generate_post_with_prefix(test_app):
'''Generation API
Testing POST with [prefix] param with return
'''
test_client = test_app.test_client()
data = {'prefix': 'BB/2c', 'include_prefix': True}
response = await test_client.post('api/generate',
json=data)
assert response.status_code == 200
result = await response.get_json()
assert len(result['music']) > 0
assert result['music'].startswith(data['prefix'])