aboutsummaryrefslogtreecommitdiffstats
path: root/pyagl/tests/test_nfc.py
blob: b845b8de4c07178654048de2278bee4dcf5aa10d (plain)
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
import asyncio
import os
import pytest
import logging
from pyagl.services.base import AFBResponse, AFBT
from concurrent.futures import TimeoutError

from pyagl.services.nfc import NFCService as nfcs
pytestmark = pytest.mark.asyncio


@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)
    svc = await nfcs(ip=address, port=port)
    yield svc
    await svc.websocket.close()


@pytest.mark.nfc
@pytest.mark.regular
async def subscribe(event_loop, service: nfcs):
    msgid = service.subscribe()
    resp = await service.afbresponse()
    assert resp.msgid == msgid


@pytest.mark.nfc
@pytest.mark.regular
async def unsubscribe(event_loop, service: nfcs):
    msgid = service.unsubscribe()
    resp = await service.afbresponse()
    assert resp.msgid == msgid