-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into refactor/transport
- Loading branch information
Showing
14 changed files
with
475 additions
and
10 deletions.
There are no files selected for viewing
Empty file.
30 changes: 30 additions & 0 deletions
30
aries_cloudagent/protocols/actionmenu/handlers/tests/test_menu_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
from asynctest import ( | ||
mock as async_mock, | ||
TestCase as AsyncTestCase, | ||
) | ||
|
||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import MockResponder | ||
|
||
from .. import menu_handler as handler | ||
|
||
|
||
class TestHandler(AsyncTestCase): | ||
async def test_called(self): | ||
request_context = RequestContext() | ||
request_context.connection_record = async_mock.MagicMock() | ||
request_context.connection_record.connection_id = "dummy" | ||
|
||
handler.save_connection_menu = async_mock.CoroutineMock() | ||
responder = MockResponder() | ||
|
||
request_context.message = handler.Menu() | ||
handler_inst = handler.MenuHandler() | ||
await handler_inst.handle(request_context, responder) | ||
|
||
handler.save_connection_menu.assert_called_once_with( | ||
request_context.message, | ||
request_context.connection_record.connection_id, | ||
request_context | ||
) |
68 changes: 68 additions & 0 deletions
68
aries_cloudagent/protocols/actionmenu/handlers/tests/test_menu_request_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytest | ||
from asynctest import ( | ||
mock as async_mock, | ||
TestCase as AsyncTestCase, | ||
) | ||
|
||
from .....config.injection_context import InjectionContext | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import MockResponder | ||
|
||
from .. import menu_request_handler as handler | ||
|
||
|
||
class TestHandler(AsyncTestCase): | ||
async def test_called(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) | ||
self.menu_service = MenuService() | ||
self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) | ||
self.context.inject = async_mock.CoroutineMock( | ||
return_value=self.menu_service | ||
) | ||
|
||
self.context.connection_record = async_mock.MagicMock() | ||
self.context.connection_record.connection_id = "dummy" | ||
|
||
responder = MockResponder() | ||
self.context.message = handler.MenuRequest() | ||
self.menu_service.get_active_menu = async_mock.CoroutineMock( | ||
return_value="menu" | ||
) | ||
|
||
handler_inst = handler.MenuRequestHandler() | ||
await handler_inst.handle(self.context, responder) | ||
|
||
messages = responder.messages | ||
assert len(messages) == 1 | ||
(result, target) = messages[0] | ||
assert result == "menu" | ||
assert target == {} | ||
|
||
async def test_called_no_active_menu(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) | ||
self.menu_service = MenuService() | ||
self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) | ||
self.context.inject = async_mock.CoroutineMock( | ||
return_value=self.menu_service | ||
) | ||
|
||
self.context.connection_record = async_mock.MagicMock() | ||
self.context.connection_record.connection_id = "dummy" | ||
|
||
responder = MockResponder() | ||
self.context.message = handler.MenuRequest() | ||
self.menu_service.get_active_menu = async_mock.CoroutineMock( | ||
return_value=None | ||
) | ||
|
||
handler_inst = handler.MenuRequestHandler() | ||
await handler_inst.handle(self.context, responder) | ||
|
||
messages = responder.messages | ||
assert not messages |
68 changes: 68 additions & 0 deletions
68
aries_cloudagent/protocols/actionmenu/handlers/tests/test_perform_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytest | ||
from asynctest import ( | ||
mock as async_mock, | ||
TestCase as AsyncTestCase, | ||
) | ||
|
||
from .....config.injection_context import InjectionContext | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import MockResponder | ||
|
||
from .. import perform_handler as handler | ||
|
||
|
||
class TestHandler(AsyncTestCase): | ||
async def test_called(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) | ||
self.menu_service = MenuService() | ||
self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) | ||
self.context.inject = async_mock.CoroutineMock( | ||
return_value=self.menu_service | ||
) | ||
|
||
self.context.connection_record = async_mock.MagicMock() | ||
self.context.connection_record.connection_id = "dummy" | ||
|
||
responder = MockResponder() | ||
self.context.message = handler.Perform() | ||
self.menu_service.perform_menu_action = async_mock.CoroutineMock( | ||
return_value="perform" | ||
) | ||
|
||
handler_inst = handler.PerformHandler() | ||
await handler_inst.handle(self.context, responder) | ||
|
||
messages = responder.messages | ||
assert len(messages) == 1 | ||
(result, target) = messages[0] | ||
assert result == "perform" | ||
assert target == {} | ||
|
||
async def test_called_no_active_menu(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) | ||
self.menu_service = MenuService() | ||
self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) | ||
self.context.inject = async_mock.CoroutineMock( | ||
return_value=self.menu_service | ||
) | ||
|
||
self.context.connection_record = async_mock.MagicMock() | ||
self.context.connection_record.connection_id = "dummy" | ||
|
||
responder = MockResponder() | ||
self.context.message = handler.Perform() | ||
self.menu_service.perform_menu_action = async_mock.CoroutineMock( | ||
return_value=None | ||
) | ||
|
||
handler_inst = handler.PerformHandler() | ||
await handler_inst.handle(self.context, responder) | ||
|
||
messages = responder.messages | ||
assert not messages |
26 changes: 26 additions & 0 deletions
26
aries_cloudagent/protocols/actionmenu/tests/test_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from ....config.injection_context import InjectionContext | ||
from ....messaging.request_context import RequestContext | ||
from .. import controller as test_module | ||
|
||
|
||
class TestActionMenuController(AsyncTestCase): | ||
async def test_controller(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
MenuService = async_mock.MagicMock(test_module.BaseMenuService, autospec=True) | ||
self.menu_service = MenuService() | ||
self.context.injector.bind_instance( | ||
test_module.BaseMenuService, | ||
self.menu_service | ||
) | ||
self.context.inject = async_mock.CoroutineMock( | ||
return_value=self.menu_service | ||
) | ||
|
||
controller = test_module.Controller("protocol") | ||
|
||
assert await controller.determine_roles(self.context) == ["provider"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
aries_cloudagent/protocols/actionmenu/tests/test_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from ....config.injection_context import InjectionContext | ||
from ....messaging.request_context import RequestContext | ||
from ....messaging.responder import MockResponder | ||
from .. import driver_service as test_module | ||
|
||
|
||
class TestActionMenuService(AsyncTestCase): | ||
async def test_get_active_menu(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
|
||
self.responder = MockResponder() | ||
self.context.injector.bind_instance(test_module.BaseResponder, self.responder) | ||
|
||
self.menu_service = await ( | ||
test_module.DriverMenuService.service_handler()(self.context) | ||
) | ||
|
||
connection = async_mock.MagicMock() | ||
connection.connection_id = "connid" | ||
thread_id = "thid" | ||
|
||
await self.menu_service.get_active_menu(connection, thread_id) | ||
|
||
webhooks = self.responder.webhooks | ||
assert len(webhooks) == 1 | ||
(result, target) = webhooks[0] | ||
assert result == "get-active-menu" | ||
assert target == { | ||
"connection_id": connection.connection_id, | ||
"thread_id": thread_id | ||
} | ||
|
||
async def test_perform_menu_action(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
|
||
self.responder = MockResponder() | ||
self.context.injector.bind_instance(test_module.BaseResponder, self.responder) | ||
|
||
self.menu_service = await ( | ||
test_module.DriverMenuService.service_handler()(self.context) | ||
) | ||
|
||
action_name = "action" | ||
action_params = {'a': 1, 'b': 2} | ||
connection = async_mock.MagicMock() | ||
connection.connection_id = "connid" | ||
thread_id = "thid" | ||
|
||
await self.menu_service.perform_menu_action( | ||
action_name, | ||
action_params, | ||
connection, | ||
thread_id | ||
) | ||
|
||
webhooks = self.responder.webhooks | ||
assert len(webhooks) == 1 | ||
(result, target) = webhooks[0] | ||
assert result == "perform-menu-action" | ||
assert target == { | ||
"connection_id": connection.connection_id, | ||
"thread_id": thread_id, | ||
"action_name": action_name, | ||
"action_params": action_params | ||
} |
Oops, something went wrong.