aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyagl/pytest.ini1
-rw-r--r--pyagl/services/navigation.py54
-rw-r--r--pyagl/tests/test_navigation.py71
3 files changed, 126 insertions, 0 deletions
diff --git a/pyagl/pytest.ini b/pyagl/pytest.ini
index 009b05e..6fec1e8 100644
--- a/pyagl/pytest.ini
+++ b/pyagl/pytest.ini
@@ -23,3 +23,4 @@ markers =
hvac: agl-service-hvac tests
taskmanager: agl-service-taskmanager tests
platforminfo: agl-service-platform-info tests
+ navigation: agl-service-navigation tests
diff --git a/pyagl/services/navigation.py b/pyagl/services/navigation.py
new file mode 100644
index 0000000..66b19b7
--- /dev/null
+++ b/pyagl/services/navigation.py
@@ -0,0 +1,54 @@
+# Copyright (C) 2021 Fujitsu
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from pyagl.services.base import AGLBaseService, AFBResponse
+import asyncio
+import os
+
+class NavigationService(AGLBaseService):
+ service = 'agl-service-navigation'
+ parser = AGLBaseService.getparser()
+
+ def __init__(self, ip, port=None):
+ super().__init__(api='navigation', ip=ip, port=port, service='agl-service-navigation')
+
+ async def subscribe(self, event='status'):
+ return await super().subscribe(event=event)
+
+ async def unsubscribe(self, event='status'):
+ return await super().unsubscribe(event=event)
+
+ async def broadcast_status(self, state):
+ return await self.request('broadcast_status', {'state': state})
+
+ async def broadcast_position(self):
+ return await self.request('broadcast_position')
+
+ async def broadcast_waypoints(self):
+ return await self.request('broadcast_waypoints')
+
+
+async def main(loop):
+ args = NavigationService.parser.parse_args()
+ tps = await NavigationService(ip=args.ipaddr, port=args.port)
+
+ if args.subscribe:
+ for event in args.subscribe:
+ msgid = await tps.subscribe(event)
+ print(f'Subscribed for event {event} with messageid {msgid}')
+ print(await tps.afbresponse())
+
+if __name__ == '__main__':
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(main(loop))
diff --git a/pyagl/tests/test_navigation.py b/pyagl/tests/test_navigation.py
new file mode 100644
index 0000000..50e4894
--- /dev/null
+++ b/pyagl/tests/test_navigation.py
@@ -0,0 +1,71 @@
+
+# Copyright (C) 2021 Fujitsu
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import asyncio
+import os
+import pytest
+import logging
+from pyagl.services.base import AFBResponse, AFBT
+
+from pyagl.services.navigation import NavigationService as ngs
+pytestmark = [pytest.mark.asyncio, pytest.mark.navigation]
+
+
+@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 ngs(ip=address, port=port)
+ yield svc
+ await svc.websocket.close()
+
+
+async def test_broadcast_status(event_loop, service: ngs):
+ msgid = await service.broadcast_status('stop')
+ resp = await service.afbresponse()
+ assert resp.status == 'success', resp.info
+
+
+async def test_subscribe(event_loop, service: ngs):
+ msgid = await service.subscribe('status')
+ resp = await service.afbresponse()
+ assert resp.status == 'success', resp.info
+ event = await service.afbresponse()
+ assert event.type == AFBT.EVENT
+ assert event.api == f'{service.api}/status'
+
+
+async def test_unsubscribe(event_loop, service: ngs):
+ msgid = await service.unsubscribe('status')
+ resp = await service.afbresponse()
+ assert resp.status == 'success', resp.info
+
+
+async def test_broadcast_position(event_loop, service: ngs):
+ msgid = await service.broadcast_position()
+ resp = await service.afbresponse()
+ assert resp.status == 'success', resp.info
+
+
+async def test_broadcast_waypoints(event_loop, service: ngs):
+ msgid = await service.broadcast_waypoints()
+ resp = await service.afbresponse()
+ assert resp.status == 'success', resp.info