summaryrefslogtreecommitdiffstats
path: root/test_bluetooth.py
diff options
context:
space:
mode:
authorEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-09 09:21:31 +0300
committerEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-09 09:30:31 +0300
commite2bb2d3ff3f909b9417040de4dd8ea876777a6ee (patch)
treee0ca7d0fd4e0e5d05f40f76cd7b3db0d04d23eac /test_bluetooth.py
parent67f7da94a293ac332fab73db50a2467913d10ae9 (diff)
Adding argparser to bluetooth
Diffstat (limited to 'test_bluetooth.py')
-rw-r--r--test_bluetooth.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/test_bluetooth.py b/test_bluetooth.py
index e69de29..1ccf499 100644
--- a/test_bluetooth.py
+++ b/test_bluetooth.py
@@ -0,0 +1,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'
+
+