summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorduerpei <duep.fnst@fujitsu.com>2021-12-21 15:20:11 +0800
committerduerpei <duep.fnst@fujitsu.com>2021-12-21 15:20:11 +0800
commit8b5ee87d3a89b710cf3bb89aaf700315c78f4803 (patch)
tree2a9e0fc54d35d7c9ee9ff3fe23b300afb573e210
parent5e7faf4f9851f436c8d5240031faabbf4e9ff916 (diff)
Add test case for agl-service-unicens
Bug-AGL:SPEC-4187 Signed-off-by: duerpei <duep.fnst@fujitsu.com> Change-Id: I327398fe2bcf9028fb6abd1257d5571f90584b78
-rw-r--r--pyagl/pytest.ini1
-rw-r--r--pyagl/services/unicens.py40
-rw-r--r--pyagl/tests/test_unicens.py52
3 files changed, 93 insertions, 0 deletions
diff --git a/pyagl/pytest.ini b/pyagl/pytest.ini
index 80255a5..b76d234 100644
--- a/pyagl/pytest.ini
+++ b/pyagl/pytest.ini
@@ -27,3 +27,4 @@ markers =
platforminfo: agl-service-platform-info tests
navigation: agl-service-navigation tests
geofence: agl-service-geofence tests
+ unicens: agl-service-unicens tests
diff --git a/pyagl/services/unicens.py b/pyagl/services/unicens.py
new file mode 100644
index 0000000..e21de6d
--- /dev/null
+++ b/pyagl/services/unicens.py
@@ -0,0 +1,40 @@
+# Copyright (C) 2021 Fujitsu
+# Author: Du Erpei
+#
+# 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
+import json
+
+class UnicensService(AGLBaseService):
+ service = 'agl-service-unicens'
+ parser = AGLBaseService.getparser()
+
+ def __init__(self, ip, port=None):
+ super().__init__(api='unicens', ip=ip, port=port, service='agl-service-unicens')
+
+ async def subscribe(self):
+ return await self.request('subscribe')
+
+ async def subscriberx(self):
+ return await self.request('subscriberx')
+
+async def main(loop):
+ args = HVACService.parser.parse_args()
+ hvs = await HVACService(args.ipaddr)
+
+if __name__ == '__main__':
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(main(loop))
diff --git a/pyagl/tests/test_unicens.py b/pyagl/tests/test_unicens.py
new file mode 100644
index 0000000..6a3c643
--- /dev/null
+++ b/pyagl/tests/test_unicens.py
@@ -0,0 +1,52 @@
+# Copyright (C) 2021 Fujitsu
+# Author: Du Erpei
+#
+# 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.unicens import UnicensService as us
+pytestmark = [pytest.mark.asyncio, pytest.mark.unicens]
+
+
+@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 us(ip=address, port=port)
+ yield svc
+ await svc.websocket.close()
+
+
+async def test_subscribe(event_loop, service: us):
+ msgid = await service.subscribe()
+ resp = await service.afbresponse()
+ assert resp.status == 'success'
+
+
+async def test_subscriberx(event_loop, service: us):
+ msgid = await service.subscriberx()
+ resp = await service.afbresponse()
+ assert resp.status == 'success'