diff options
author | Qiu Tingting <qiutt@fujitsu.com> | 2021-09-15 08:54:35 +0800 |
---|---|---|
committer | Jan-Simon Möller <jsmoeller@linuxfoundation.org> | 2021-11-03 15:11:21 +0100 |
commit | 87c500fad4cb16c20f4c9b94919965ca61b67446 (patch) | |
tree | 4f0c9c729bbc217d53869a604a0afa21a3ed41f4 | |
parent | 1c60b87da5e3c35e029ffddb72152f0d71718fb6 (diff) |
Add test cases of scan for agl-service-geofence
Bug-AGL: SPEC-4078
Signed-off-by: Qiu Tingting <qiutt@fujitsu.com>
Change-Id: Ida7bb07ca142c2ac61cc2e2776e3126f91bc5e7b
-rw-r--r-- | pyagl/pytest.ini | 1 | ||||
-rw-r--r-- | pyagl/services/geofence.py | 103 | ||||
-rw-r--r-- | pyagl/tests/test_geofence.py | 71 |
3 files changed, 175 insertions, 0 deletions
diff --git a/pyagl/pytest.ini b/pyagl/pytest.ini index 6fec1e8..8865272 100644 --- a/pyagl/pytest.ini +++ b/pyagl/pytest.ini @@ -24,3 +24,4 @@ markers = taskmanager: agl-service-taskmanager tests platforminfo: agl-service-platform-info tests navigation: agl-service-navigation tests + geofence: agl-service-geofence tests diff --git a/pyagl/services/geofence.py b/pyagl/services/geofence.py new file mode 100644 index 0000000..62cee47 --- /dev/null +++ b/pyagl/services/geofence.py @@ -0,0 +1,103 @@ +# Copyright (C) 2021 Fujitsu +# Author: Qiu Tingting +# +# 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 GeofenceService(AGLBaseService): + service = 'agl-service-geofence' + parser = AGLBaseService.getparser() + parser.add_argument('--list_fences', action='store_true', help='list current bounding boxes and state.') + parser.add_argument('--add_fence', help='add geofence bounding box.') + parser.add_argument('--remove_fence', help='remove named geofence.') + parser.add_argument('--dwell_transition', help='get/set dwell transition time interval.') + + def __init__(self, ip, port=None): + super().__init__(api='geofence', ip=ip, port=port, service='agl-service-geofence') + + async def list_fences(self): + return await self.request('list_fences') + + async def add_fence(self, name=None): + msg={'name': name, 'bbox': { 'min_latitude': '45.600136', 'max_latitude': '45.600384', 'min_longitude': '-122.499217', 'max_longitude': '-122.498732'}} + return await self.request('add_fence', msg) + + async def remove_fence(self, name=None): + return await self.request('remove_fence', {'name': name}) + + async def dwell_transition(self, value=None): + return await self.request('dwell_transition', {'value': value}) + + async def subscribe(self, event=None): + return await self.request('subscribe', {'value': event}) + + async def unsubscribe(self, event=None): + return await self.request('unsubscribe', {'value': event}) + + +async def main(loop): + args = GeofenceService.parser.parse_args() + gfs = await GeofenceService(args.ipaddr, args.port) + + if args.list_fences: + msgid = await gfs.list_fences() + print(f'Sent list_fences request with value {args.list_fences} and messageid {msgid}') + resp = await gfs.afbresponse() + print(resp) + + if args.add_fence: + msgid = await gfs.add_fence(args.add_fence) + print(f'Sent add_fence request with value {args.add_fence} and messageid {msgid}') + resp = await gfs.afbresponse() + print(resp) + + if args.remove_fence: + msgid = await gfs.remove_fence(args.remove_fence) + print(f'Sent remove_fence request with value {args.remove_fence} and messageid {msgid}') + resp = await gfs.afbresponse() + print(resp) + + if args.dwell_transition: + msgid = await gfs.dwell_transition(args.dwell_transition) + print(f'Sent dwell_transition request with value {args.dwell_transition} and messageid {msgid}') + resp = await gfs.afbresponse() + print(resp) + + + if args.subscribe: + for event in args.subscribe: + msgid = await gfs.subscribe(event) + print(f'Subscribing for event {event} with messageid {msgid}') + resp = await gfs.afbresponse() + print(resp) + + if args.unsubscribe: + for event in args.unsubscribe: + msgid = await gfs.unsubscribe(event) + print(f'Unsubscribing for event {event} with messageid {msgid}') + resp = await gfs.afbresponse() + print(resp) + + + if args.listener: + async for response in gfs.listener(): + print(response) + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(loop)) diff --git a/pyagl/tests/test_geofence.py b/pyagl/tests/test_geofence.py new file mode 100644 index 0000000..82adb2e --- /dev/null +++ b/pyagl/tests/test_geofence.py @@ -0,0 +1,71 @@ +# Copyright (C) 2021 Fujitsu +# Author: Qiu Tingting +# +# 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.geofence import GeofenceService as gfs +pytestmark = [pytest.mark.asyncio, pytest.mark.geofence] + + +@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 gfs(ip=address, port=port) + yield svc + await svc.websocket.close() + + +async def test_list_fences(event_loop, service: gfs): + msgid = await service.list_fences() + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_dwell_transition(event_loop, service: gfs): + msgid = await service.dwell_transition(value='10') + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_add_fence(event_loop, service: gfs): + msgid = await service.add_fence(name='fence_name') + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_remove_fence(event_loop, service: gfs): + msgid = await service.remove_fence(name='fence_name') + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_subscribe(event_loop, service: gfs): + msgid = await service.subscribe(event='fence') + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_unsubscribe(event_loop, service: gfs): + msgid = await service.unsubscribe(event='fence') + resp = await service.afbresponse() + assert resp.status == 'success' + |