diff options
author | Wang Qi <wangq.fnst@cn.fujitsu.com> | 2021-09-17 09:03:27 +0800 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2021-11-04 15:54:35 +0000 |
commit | 6e4d0fc065173ba7e356563a8bf176bd502642c6 (patch) | |
tree | 5c12513cff76987c17fa6d7b13911e9bdde85a1d | |
parent | 64e5d7e254968aee3e5f92f86663ae29920e64c7 (diff) |
Add testcase of agl-service-identity-agent
Bug-AGL: SPEC-4080
Signed-off-by: Wang Qi <wangq.fnst@cn.fujitsu.com>
Change-Id: I9af11f38dd046f57294113a6d83ac2418d2891bf
-rw-r--r-- | pyagl/pytest.ini | 1 | ||||
-rw-r--r-- | pyagl/services/identity_agent.py | 57 | ||||
-rw-r--r-- | pyagl/tests/test_identity_agent.py | 73 |
3 files changed, 131 insertions, 0 deletions
diff --git a/pyagl/pytest.ini b/pyagl/pytest.ini index 26685c8..80255a5 100644 --- a/pyagl/pytest.ini +++ b/pyagl/pytest.ini @@ -18,6 +18,7 @@ markers = mediaplayer: agl-service-mediaplayer tests network: agl-service-network tests nfc: agl-service-nfc tests + identity: agl-identity-service tests radio: agl-service-radio tests signal_composer: agl-service-signal-composer tests weather: agl-service-weather tests diff --git a/pyagl/services/identity_agent.py b/pyagl/services/identity_agent.py new file mode 100644 index 0000000..da1b60c --- /dev/null +++ b/pyagl/services/identity_agent.py @@ -0,0 +1,57 @@ +# 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 IdentityService(AGLBaseService): + service = 'agl-service-identity' + parser = AGLBaseService.getparser() + + def __init__(self, ip, port=None): + super().__init__(api='identity', ip=ip, port=port, service='agl-identity-service') + + async def subscribe(self, event=None): + return await super().subscribe(event=event) + + async def unsubscribe(self, event=None): + return await super().unsubscribe(event=event) + + async def fake_login(self, values): + return await self.request('fake-login', values=values) + + async def get(self): + return await self.request('get') + + async def logout(self, values): + return await self.request('logout', values=values) + + async def fake_auth(self, values): + return await self.request('fake-auth', values=values) + + +async def main(loop): + args = IdentityService.parser.parse_args() + ids = await IdentityService(ip=args.ipaddr, port=args.port) + + if args.subscribe: + for event in args.subscribe: + msgid = await ids.subscribe(event) + print(f'Subscribed for event {event} with messageid {msgid}') + print(await ids.afbresponse()) + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(loop)) diff --git a/pyagl/tests/test_identity_agent.py b/pyagl/tests/test_identity_agent.py new file mode 100644 index 0000000..4e3822c --- /dev/null +++ b/pyagl/tests/test_identity_agent.py @@ -0,0 +1,73 @@ +# 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.identity_agent import IdentityService as ids +pytestmark = [pytest.mark.asyncio, pytest.mark.identity] + + +@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 ids(ip=address, port=port) + yield svc + await svc.websocket.close() + + +async def test_subscribe(event_loop, service: ids): + msgid = await service.subscribe() + resp = await service.afbresponse() + assert resp.status == 'success' + + +async def test_unsubscribe(event_loop, service: ids): + msgid = await service.unsubscribe() + resp = await service.afbresponse() + assert resp.status == 'success' + + +async def test_fake_login(event_loop, service: ids): + msgid = await service.fake_login({'eventName': 'login', 'accountID': 'farfoll'}) + resp = await service.afbresponse() + assert resp.status == 'success' + + +async def test_get(event_loop, service: ids): + msgid = await service.get() + resp = await service.afbresponse() + assert resp.status == 'success' + + +async def test_logout(event_loop, service:ids): + msgid = await service.logout({'eventName': 'logout', 'accountID': 'null'}) + resp = await service.afbresponse() + assert resp.status == 'success' + + +async def test_fake_auth(event_loop, service: ids): + msgid = await service.fake_auth({'kind': 'kind', 'key': 'key'}) + resp = await service.afbresponse() + assert resp.status == 'success' |