-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
66 lines (50 loc) · 1.69 KB
/
test.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
import os
import sys
import json
import pytest
from server import create_app
import logging
LOGGER = logging.getLogger(__name__)
def custom_log(text):
LOGGER.info('-' * 20 + ' {} '.format(text) + '-' * 20)
@pytest.yield_fixture
def app():
app = create_app()
yield app
@pytest.fixture
def test_cli(loop, app, sanic_client):
return loop.run_until_complete(sanic_client(app))
async def test_fixture_device(test_cli):
##### get devices #####
custom_log('GET DEVICES')
resp = await test_cli.get('/app/devices')
devices = await resp.json()
print(devices)
assert isinstance(devices, list)
return devices
async def test_fixture_devices(test_cli):
wallet = '0x75a59b94889a05c03c66c3c84e9d2f8308ca4abd'
##### register device #####
custom_log('REGISTER DEVICE')
resp = await test_cli.post('/app/register',
headers={
'content-type': 'application/json'
}, json={
'name': 'TEST-0',
'wallet': wallet
})
assert resp.status == 200
##### get device #####
custom_log('GET DEVICE')
resp = await test_cli.get('/app/devices/{}'.format(wallet))
device = await resp.json()
print(device)
assert isinstance(device, dict)
devices = await test_fixture_get_devices(test_cli)
assert device in devices
##### delete device #####
custom_log('DELETE DEVICE')
resp = await test_cli.delete('/app/devices/{}'.format(wallet))
assert resp.status == 200
devices = await test_fixture_get_devices(test_cli)
assert device not in devices