aboutsummaryrefslogtreecommitdiffstats
path: root/test_bluetooth.py
blob: 1ccf499c0015737a1526222a2a572d5a3c5ede0e (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
41
42
43
44
45
46
47
48
49
50
import asyncio
import os
import pytest
from bluetooth import BluetoothService as BTS
import logging
from aglbaseservice import AFBResponse, AFBT

logger = logging.getLogger(f'pytest-{BTS.service}')
logger.setLevel(logging.DEBUG)
pytestmark = pytest.mark.asyncio


@pytest.fixture(scope="module")
def event_loop():
    loop = asyncio.get_event_loop()
    yield loop
    loop.close()


@pytest.fixture(scope='module')
async def service():
    address = os.environ.get('AGL_TGT_IP', 'localhost')
    port = os.environ.get('AGL_TGT_PORT', None)

    bts = await BTS(ip=address, port=port)
    yield bts
    await bts.websocket.close()


async def test_default_adapter(event_loop, service: BTS):
    id = await service.default_adapter()
    resp = AFBResponse(await service.response())
    assert resp.status == 'success', resp
    assert 'adapter' in resp.data.keys()
    assert resp.data['adapter'] == 'hci0'


async def test_managed_objects(event_loop, service: BTS):
    id = await service.managed_objects()
    resp = AFBResponse(await service.response())
    assert resp.status == 'success', str(resp)


async def test_has_single_adapter(event_loop, service: BTS):
    id = await service.managed_objects()
    resp = AFBResponse(await service.response())
    assert len(resp.data['adapters']) == 1, \
        f'Detected {len(resp.data["adapters"])} adapters. Multiple adapters may also break testing'