summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyagl/pytest.ini1
-rw-r--r--pyagl/services/platforminfo.py81
-rw-r--r--pyagl/tests/test_platform-info.py63
3 files changed, 145 insertions, 0 deletions
diff --git a/pyagl/pytest.ini b/pyagl/pytest.ini
index 83d1f53..009b05e 100644
--- a/pyagl/pytest.ini
+++ b/pyagl/pytest.ini
@@ -22,3 +22,4 @@ markers =
weather: agl-service-weather tests
hvac: agl-service-hvac tests
taskmanager: agl-service-taskmanager tests
+ platforminfo: agl-service-platform-info tests
diff --git a/pyagl/services/platforminfo.py b/pyagl/services/platforminfo.py
new file mode 100644
index 0000000..c5f8c1c
--- /dev/null
+++ b/pyagl/services/platforminfo.py
@@ -0,0 +1,81 @@
+# 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 PlatformInfoService(AGLBaseService):
+ service = 'agl-service-platform-info'
+ parser = AGLBaseService.getparser()
+ parser.add_argument('--get', action='store_true', help='Get a platform data.')
+ parser.add_argument('--getwithkey', help='Get a platform data with key.')
+
+ def __init__(self, ip, port=None):
+ super().__init__(api='platform-info', ip=ip, port=port, service='agl-service-platform-info')
+
+ async def get(self):
+ return await self.request('get')
+
+ async def getwithkey(self, key='bb_aglversion'):
+ return await self.request('get', key)
+
+ async def subscribe(self, event=None):
+ return await self.request('subscribe', {'event': event})
+
+ async def unsubscribe(self, event=None):
+ return await self.request('unsubscribe', {'event': event})
+
+
+async def main(loop):
+ args = PlatformInfoService.parser.parse_args()
+ svc = await PlatformInfoService(args.ipaddr, args.port)
+
+ if args.get:
+ msgid = await svc.get()
+ print(f'Sent get request with value {args.get} and messageid {msgid}')
+ resp = await svc.afbresponse()
+ print(resp)
+
+ if args.getwithkey:
+ msgid = await svc.getwithkey(args.getwithkey)
+ print(f'Sent get request with value {args.getwithkey} and messageid {msgid}')
+ resp = await svc.afbresponse()
+ print(resp)
+
+ if args.subscribe:
+ for event in args.subscribe:
+ msgid = await svc.subscribe(event)
+ print(f'Subscribing for event {event} with messageid {msgid}')
+ resp = await svc.afbresponse()
+ print(resp)
+
+ if args.unsubscribe:
+ for event in args.unsubscribe:
+ msgid = await svc.unsubscribe(event)
+ print(f'Unsubscribing for event {event} with messageid {msgid}')
+ resp = await svc.afbresponse()
+ print(resp)
+
+
+ if args.listener:
+ async for response in svc.listener():
+ print(response)
+
+if __name__ == '__main__':
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(main(loop))
diff --git a/pyagl/tests/test_platform-info.py b/pyagl/tests/test_platform-info.py
new file mode 100644
index 0000000..20dc80c
--- /dev/null
+++ b/pyagl/tests/test_platform-info.py
@@ -0,0 +1,63 @@
+# 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.platforminfo import PlatformInfoService as pis
+pytestmark = [pytest.mark.asyncio, pytest.mark.platforminfo]
+
+
+@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 pis(ip=address, port=port)
+ yield svc
+ await svc.websocket.close()
+
+
+async def test_get_all(event_loop, service: pis):
+ # test with no para
+ msgid = await service.get()
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+
+async def test_get_with_args(event_loop, service: pis):
+ # test with para
+ msgid = await service.getwithkey('bb_aglversion')
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+
+async def test_subscribe(event_loop, service: pis):
+ msgid = await service.subscribe(event='monitor-devices')
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+
+async def test_unsubscribe(event_loop, service: pis):
+ msgid = await service.unsubscribe(event='monitor-devices')
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+