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
|
import asyncio
import os
import pytest
import logging
from pyagl.services.base import AFBResponse, AFBT
from pyagl.services.gps import GPSService as GPS
from asyncio.exceptions import TimeoutError
pytestmark = [pytest.mark.asyncio, pytest.mark.gps]
@pytest.fixture(scope='module')
def event_loop():
loop = asyncio.get_event_loop()
yield loop
@pytest.fixture(scope='module')
async def service():
address = os.environ.get('AGL_TGT_IP', 'localhost')
port = os.environ.get('AGL_TGT_PORT', None)
gpss = await GPS(ip=address, port=port)
yield gpss
await gpss.websocket.close()
# @pytest.fixture(scope='module')
# async def response(event_loop, service):
# async for _response in service.listener():
# yield _response
@pytest.mark.regular
async def test_location_verb(event_loop, service: GPS):
msgid = await service.location()
resp = await service.afbresponse()
assert resp.msgid == msgid
@pytest.mark.regular
@pytest.mark.xfail(reason='expecting this to fail because of "No 3D GNSS fix" and GPS is unavailable')
async def test_location_result(event_loop, service: GPS):
msgid = await service.location()
resp = await service.afbresponse()
assert resp.status == 'success'
@pytest.mark.regular
async def test_subscribe_verb(event_loop, service: GPS):
msgid = await service.subscribe()
resp = await service.afbresponse()
assert resp.msgid == msgid
assert resp.status == 'success'
@pytest.mark.regular
@pytest.mark.dependency
async def test_enable_recording(event_loop, service: GPS):
msgid = await service.record()
resp = await service.afbresponse()
assert resp.status == 'success', resp.info
@pytest.mark.regular
@pytest.mark.dependency(depends=['test_enable_recording'])
async def test_disable_recording(event_loop, service: GPS):
msgid = await service.record('off')
resp = await service.afbresponse()
assert resp.status == 'success', resp.info
@pytest.mark.regular
@pytest.mark.dependency
async def test_subscribe_location(event_loop, service: GPS):
msgid = await service.subscribe('location')
resp = await service.afbresponse()
assert resp.msgid == msgid
assert resp.status == 'success'
@pytest.mark.hwrequired
@pytest.mark.dependency(depends=['test_subscribe_location'])
@pytest.mark.xfail # expecting this to fail because of "No 3D GNSS fix" and GPS is unavailable
async def test_location_events(event_loop, service: GPS):
msgid = await service.subscribe('location')
resp = await service.afbresponse()
assert resp.msgid == msgid
assert resp.status == 'success' # successful subscription
task = asyncio.create_task(service.afbresponse())
try:
resp = await asyncio.wait_for(task, 10)
assert resp.type == AFBT.EVENT, f'Expected EVENT response, got {resp.type.name} instead'
# TODO one more assert for the actual received event, haven't received a location event yet
except TimeoutError:
task.cancel()
pytest.xfail("Did not receive location event")
@pytest.mark.regular
async def test_unsubscribe(event_loop, service: GPS):
msgid = await service.unsubscribe('location')
resp = await service.afbresponse()
assert resp.msgid == msgid
assert resp.status == 'success'
|