From afd177faa0dda33746974b7334b42fcfbefba1fd Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 09:22:49 -0700 Subject: [PATCH 001/103] Add debug log for loaded module Signed-off-by: Nicholas Rempel --- aries_cloudagent/core/plugin_registry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aries_cloudagent/core/plugin_registry.py b/aries_cloudagent/core/plugin_registry.py index 002c44ec98..65bdbb25a0 100644 --- a/aries_cloudagent/core/plugin_registry.py +++ b/aries_cloudagent/core/plugin_registry.py @@ -37,6 +37,7 @@ def register_plugin(self, module_name: str) -> ModuleType: else: try: mod = ClassLoader.load_module(module_name) + LOGGER.debug(f"Loaded module: {module_name}") except ModuleLoadError as e: LOGGER.error("Error loading plugin module: %s", e) mod = None From 7376110fcdd98c429ec9e001ca32b133322ead1d Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 12:44:30 -0700 Subject: [PATCH 002/103] refactor action menu into version subdir Signed-off-by: Nicholas Rempel --- aries_cloudagent/config/default_context.py | 4 +- aries_cloudagent/core/error.py | 4 + aries_cloudagent/core/plugin_registry.py | 77 +++++++++++++++++-- .../protocols/actionmenu/definition.py | 3 + .../actionmenu/{handlers => v1_0}/__init__.py | 0 .../actionmenu/{ => v1_0}/base_service.py | 6 +- .../actionmenu/{ => v1_0}/controller.py | 2 +- .../actionmenu/{ => v1_0}/driver_service.py | 6 +- .../tests => v1_0/handlers}/__init__.py | 0 .../{ => v1_0}/handlers/menu_handler.py | 0 .../handlers/menu_request_handler.py | 0 .../{ => v1_0}/handlers/perform_handler.py | 0 .../handlers/tests}/__init__.py | 0 .../handlers/tests/test_menu_handler.py | 0 .../tests/test_menu_request_handler.py | 0 .../handlers/tests/test_perform_handler.py | 0 .../actionmenu/{ => v1_0}/message_types.py | 0 .../tests => v1_0/messages}/__init__.py | 0 .../actionmenu/{ => v1_0}/messages/menu.py | 2 +- .../{ => v1_0}/messages/menu_request.py | 2 +- .../actionmenu/{ => v1_0}/messages/perform.py | 2 +- .../messages/tests}/__init__.py | 0 .../{ => v1_0}/messages/tests/test_menu.py | 0 .../messages/tests/test_menu_request.py | 0 .../{ => v1_0}/messages/tests/test_perform.py | 0 .../{tests => v1_0/models}/__init__.py | 0 .../actionmenu/{ => v1_0}/models/menu_form.py | 2 +- .../{ => v1_0}/models/menu_form_param.py | 2 +- .../{ => v1_0}/models/menu_option.py | 2 +- .../protocols/actionmenu/{ => v1_0}/routes.py | 6 +- .../actionmenu/v1_0/tests/__init__.py | 0 .../{ => v1_0}/tests/test_controller.py | 4 +- .../{ => v1_0}/tests/test_routes.py | 2 +- .../{ => v1_0}/tests/test_service.py | 6 +- .../actionmenu/{ => v1_0}/tests/test_util.py | 14 ++-- .../protocols/actionmenu/{ => v1_0}/util.py | 6 +- 36 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 aries_cloudagent/protocols/actionmenu/definition.py rename aries_cloudagent/protocols/actionmenu/{handlers => v1_0}/__init__.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/base_service.py (89%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/controller.py (90%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/driver_service.py (92%) rename aries_cloudagent/protocols/actionmenu/{handlers/tests => v1_0/handlers}/__init__.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/handlers/menu_handler.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/handlers/menu_request_handler.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/handlers/perform_handler.py (100%) rename aries_cloudagent/protocols/actionmenu/{messages => v1_0/handlers/tests}/__init__.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/handlers/tests/test_menu_handler.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/handlers/tests/test_menu_request_handler.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/handlers/tests/test_perform_handler.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/message_types.py (100%) rename aries_cloudagent/protocols/actionmenu/{messages/tests => v1_0/messages}/__init__.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/messages/menu.py (96%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/messages/menu_request.py (91%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/messages/perform.py (94%) rename aries_cloudagent/protocols/actionmenu/{models => v1_0/messages/tests}/__init__.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/messages/tests/test_menu.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/messages/tests/test_menu_request.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/messages/tests/test_perform.py (100%) rename aries_cloudagent/protocols/actionmenu/{tests => v1_0/models}/__init__.py (100%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/models/menu_form.py (96%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/models/menu_form_param.py (96%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/models/menu_option.py (96%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/routes.py (97%) create mode 100644 aries_cloudagent/protocols/actionmenu/v1_0/tests/__init__.py rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/tests/test_controller.py (87%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/tests/test_routes.py (99%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/tests/test_service.py (92%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/tests/test_util.py (90%) rename aries_cloudagent/protocols/actionmenu/{ => v1_0}/util.py (90%) diff --git a/aries_cloudagent/config/default_context.py b/aries_cloudagent/config/default_context.py index dd6957565d..73dfa50932 100644 --- a/aries_cloudagent/config/default_context.py +++ b/aries_cloudagent/config/default_context.py @@ -13,8 +13,8 @@ from ..issuer.base import BaseIssuer from ..holder.base import BaseHolder from ..verifier.base import BaseVerifier -from ..protocols.actionmenu.base_service import BaseMenuService -from ..protocols.actionmenu.driver_service import DriverMenuService +from ..protocols.actionmenu.v1_0.base_service import BaseMenuService +from ..protocols.actionmenu.v1_0.driver_service import DriverMenuService from ..protocols.introduction.base_service import BaseIntroductionService from ..protocols.introduction.demo_service import DemoIntroductionService from ..storage.base import BaseStorage diff --git a/aries_cloudagent/core/error.py b/aries_cloudagent/core/error.py index ceb6c2be02..f610964cf0 100644 --- a/aries_cloudagent/core/error.py +++ b/aries_cloudagent/core/error.py @@ -20,3 +20,7 @@ def message(self) -> str: class StartupError(BaseError): """Error raised when there is a problem starting the conductor.""" + + +class ProtocolDefinitionValidationError(BaseError): + """Error raised when there is a problem validating a protocol definition.""" diff --git a/aries_cloudagent/core/plugin_registry.py b/aries_cloudagent/core/plugin_registry.py index 65bdbb25a0..695d00e4e5 100644 --- a/aries_cloudagent/core/plugin_registry.py +++ b/aries_cloudagent/core/plugin_registry.py @@ -5,6 +5,8 @@ from types import ModuleType from typing import Sequence +from .error import ProtocolDefinitionValidationError + from ..config.injection_context import InjectionContext from ..utils.classloader import ClassLoader, ModuleLoadError @@ -30,6 +32,46 @@ def plugins(self) -> Sequence[ModuleType]: """Accessor for a list of all plugin modules.""" return list(self._plugins.values()) + def validate_version(self, version_list, module_name): + """Validate version dict format.""" + + is_list = type(version_list) is list + + # Must be a list + if not is_list: + raise ProtocolDefinitionValidationError( + "Versions definition is not of type list" + ) + + for version_dict in version_list: + # Dicts must have correct format + is_dict = type(version_dict) is dict + if not is_dict: + raise ProtocolDefinitionValidationError( + "Element of versions definition list is not of type obj" + ) + + try: + type(version_dict["major_version"]) is int and type( + version_dict["minimum_minor"] + ) is int and type(version_dict["path"]) is str + except KeyError as e: + raise ProtocolDefinitionValidationError( + f"Element of versions definition list is missing an attribute: {e}" + ) + + # Specified module must be loadable + version_path = version_dict["path"] + mod = ClassLoader.load_module(version_path, module_name) + + if not mod: + raise ProtocolDefinitionValidationError( + "Version module path is not " + + f"loadable: {module_name}, {version_path}" + ) + + return True + def register_plugin(self, module_name: str) -> ModuleType: """Register a plugin module.""" if module_name in self._plugins: @@ -39,13 +81,34 @@ def register_plugin(self, module_name: str) -> ModuleType: mod = ClassLoader.load_module(module_name) LOGGER.debug(f"Loaded module: {module_name}") except ModuleLoadError as e: - LOGGER.error("Error loading plugin module: %s", e) - mod = None - else: - if mod: - self._plugins[module_name] = mod - else: - LOGGER.error("Plugin module not found: %s", module_name) + LOGGER.error(f"Error loading plugin module: {e}") + return None + + definition = ClassLoader.load_module("definition", module_name) + + # definition.py must exist in protocol + if not definition: + LOGGER.error(f"Protocol does not include definition.py: {module_name}") + return None + + # definition.py must include versions attribute + if not hasattr(definition, "versions"): + LOGGER.error( + "Protocol definition does not " + + f"include versions attribute: {module_name}" + ) + return None + + # Definition list must not be malformed + try: + self.validate_version(definition.versions, module_name) + except ProtocolDefinitionValidationError as e: + LOGGER.error( + f"Protocol versions definition is malformed. {e}" + ) + return None + + self._plugins[module_name] = mod return mod def register_package(self, package_name: str) -> Sequence[ModuleType]: diff --git a/aries_cloudagent/protocols/actionmenu/definition.py b/aries_cloudagent/protocols/actionmenu/definition.py new file mode 100644 index 0000000000..6bb77e7868 --- /dev/null +++ b/aries_cloudagent/protocols/actionmenu/definition.py @@ -0,0 +1,3 @@ +"""Version definitions for this protocol.""" + +versions = [{"major_version": 1, "minimum_minor": 0, "path": "v1_0"}] diff --git a/aries_cloudagent/protocols/actionmenu/handlers/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/__init__.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/__init__.py rename to aries_cloudagent/protocols/actionmenu/v1_0/__init__.py diff --git a/aries_cloudagent/protocols/actionmenu/base_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/base_service.py similarity index 89% rename from aries_cloudagent/protocols/actionmenu/base_service.py rename to aries_cloudagent/protocols/actionmenu/v1_0/base_service.py index 4ec4b6a7ac..874ba76ce5 100644 --- a/aries_cloudagent/protocols/actionmenu/base_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/base_service.py @@ -2,9 +2,9 @@ from abc import ABC, abstractmethod -from ...config.injection_context import InjectionContext -from ...connections.models.connection_record import ConnectionRecord -from ...messaging.agent_message import AgentMessage +from ....config.injection_context import InjectionContext +from ....connections.models.connection_record import ConnectionRecord +from ....messaging.agent_message import AgentMessage from .messages.menu import Menu diff --git a/aries_cloudagent/protocols/actionmenu/controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/controller.py similarity index 90% rename from aries_cloudagent/protocols/actionmenu/controller.py rename to aries_cloudagent/protocols/actionmenu/v1_0/controller.py index 9decbe9f6c..70a5a67252 100644 --- a/aries_cloudagent/protocols/actionmenu/controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/controller.py @@ -2,7 +2,7 @@ from typing import Sequence -from ...config.injection_context import InjectionContext +from ....config.injection_context import InjectionContext from .base_service import BaseMenuService diff --git a/aries_cloudagent/protocols/actionmenu/driver_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py similarity index 92% rename from aries_cloudagent/protocols/actionmenu/driver_service.py rename to aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py index aaff8094c3..b5ea85adef 100644 --- a/aries_cloudagent/protocols/actionmenu/driver_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py @@ -2,9 +2,9 @@ import logging -from ...connections.models.connection_record import ConnectionRecord -from ...messaging.agent_message import AgentMessage -from ...messaging.responder import BaseResponder +from ....connections.models.connection_record import ConnectionRecord +from ....messaging.agent_message import AgentMessage +from ....messaging.responder import BaseResponder from .base_service import BaseMenuService from .messages.menu import Menu diff --git a/aries_cloudagent/protocols/actionmenu/handlers/tests/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/__init__.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/tests/__init__.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/__init__.py diff --git a/aries_cloudagent/protocols/actionmenu/handlers/menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_handler.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/menu_handler.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_handler.py diff --git a/aries_cloudagent/protocols/actionmenu/handlers/menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_request_handler.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/menu_request_handler.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_request_handler.py diff --git a/aries_cloudagent/protocols/actionmenu/handlers/perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/perform_handler.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/perform_handler.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/perform_handler.py diff --git a/aries_cloudagent/protocols/actionmenu/messages/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/__init__.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/messages/__init__.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/__init__.py diff --git a/aries_cloudagent/protocols/actionmenu/handlers/tests/test_menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/tests/test_menu_handler.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py diff --git a/aries_cloudagent/protocols/actionmenu/handlers/tests/test_menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/tests/test_menu_request_handler.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py diff --git a/aries_cloudagent/protocols/actionmenu/handlers/tests/test_perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/handlers/tests/test_perform_handler.py rename to aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py diff --git a/aries_cloudagent/protocols/actionmenu/message_types.py b/aries_cloudagent/protocols/actionmenu/v1_0/message_types.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/message_types.py rename to aries_cloudagent/protocols/actionmenu/v1_0/message_types.py diff --git a/aries_cloudagent/protocols/actionmenu/messages/tests/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/__init__.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/messages/tests/__init__.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/__init__.py diff --git a/aries_cloudagent/protocols/actionmenu/messages/menu.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py similarity index 96% rename from aries_cloudagent/protocols/actionmenu/messages/menu.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py index ae713a8dd3..f94e074c94 100644 --- a/aries_cloudagent/protocols/actionmenu/messages/menu.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py @@ -4,7 +4,7 @@ from marshmallow import fields -from ....messaging.agent_message import AgentMessage, AgentMessageSchema +from .....messaging.agent_message import AgentMessage, AgentMessageSchema from ..message_types import MENU, PROTOCOL_PACKAGE from ..models.menu_option import MenuOption, MenuOptionSchema diff --git a/aries_cloudagent/protocols/actionmenu/messages/menu_request.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py similarity index 91% rename from aries_cloudagent/protocols/actionmenu/messages/menu_request.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py index f27d655601..e294d7ce5c 100644 --- a/aries_cloudagent/protocols/actionmenu/messages/menu_request.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py @@ -1,6 +1,6 @@ """Represents a request for an action menu.""" -from ....messaging.agent_message import AgentMessage, AgentMessageSchema +from .....messaging.agent_message import AgentMessage, AgentMessageSchema from ..message_types import MENU_REQUEST, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/actionmenu/messages/perform.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py similarity index 94% rename from aries_cloudagent/protocols/actionmenu/messages/perform.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py index cbbf0ce205..1ef15e7788 100644 --- a/aries_cloudagent/protocols/actionmenu/messages/perform.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py @@ -4,7 +4,7 @@ from marshmallow import fields -from ....messaging.agent_message import AgentMessage, AgentMessageSchema +from .....messaging.agent_message import AgentMessage, AgentMessageSchema from ..message_types import PERFORM, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/actionmenu/models/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/__init__.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/models/__init__.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/__init__.py diff --git a/aries_cloudagent/protocols/actionmenu/messages/tests/test_menu.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/messages/tests/test_menu.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py diff --git a/aries_cloudagent/protocols/actionmenu/messages/tests/test_menu_request.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/messages/tests/test_menu_request.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py diff --git a/aries_cloudagent/protocols/actionmenu/messages/tests/test_perform.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/messages/tests/test_perform.py rename to aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py diff --git a/aries_cloudagent/protocols/actionmenu/tests/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/__init__.py similarity index 100% rename from aries_cloudagent/protocols/actionmenu/tests/__init__.py rename to aries_cloudagent/protocols/actionmenu/v1_0/models/__init__.py diff --git a/aries_cloudagent/protocols/actionmenu/models/menu_form.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py similarity index 96% rename from aries_cloudagent/protocols/actionmenu/models/menu_form.py rename to aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py index 7653defba7..3209c8481b 100644 --- a/aries_cloudagent/protocols/actionmenu/models/menu_form.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py @@ -4,7 +4,7 @@ from marshmallow import fields -from ....messaging.models.base import BaseModel, BaseModelSchema +from .....messaging.models.base import BaseModel, BaseModelSchema from .menu_form_param import MenuFormParam, MenuFormParamSchema diff --git a/aries_cloudagent/protocols/actionmenu/models/menu_form_param.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py similarity index 96% rename from aries_cloudagent/protocols/actionmenu/models/menu_form_param.py rename to aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py index 7d6f2bb255..7b2c77e70e 100644 --- a/aries_cloudagent/protocols/actionmenu/models/menu_form_param.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py @@ -2,7 +2,7 @@ from marshmallow import fields -from ....messaging.models.base import BaseModel, BaseModelSchema +from .....messaging.models.base import BaseModel, BaseModelSchema class MenuFormParam(BaseModel): diff --git a/aries_cloudagent/protocols/actionmenu/models/menu_option.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py similarity index 96% rename from aries_cloudagent/protocols/actionmenu/models/menu_option.py rename to aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py index 2c2a1d3a32..ac7dfd40e0 100644 --- a/aries_cloudagent/protocols/actionmenu/models/menu_option.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py @@ -2,7 +2,7 @@ from marshmallow import fields -from ....messaging.models.base import BaseModel, BaseModelSchema +from .....messaging.models.base import BaseModel, BaseModelSchema from .menu_form import MenuForm, MenuFormSchema diff --git a/aries_cloudagent/protocols/actionmenu/routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/routes.py similarity index 97% rename from aries_cloudagent/protocols/actionmenu/routes.py rename to aries_cloudagent/protocols/actionmenu/v1_0/routes.py index 8d5528b7ec..e5092774ca 100644 --- a/aries_cloudagent/protocols/actionmenu/routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/routes.py @@ -7,9 +7,9 @@ from marshmallow import fields, Schema -from ...connections.models.connection_record import ConnectionRecord -from ...messaging.valid import UUIDFour -from ...storage.error import StorageNotFoundError +from ....connections.models.connection_record import ConnectionRecord +from ....messaging.valid import UUIDFour +from ....storage.error import StorageNotFoundError from .messages.menu import Menu from .messages.menu_request import MenuRequest diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/__init__.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aries_cloudagent/protocols/actionmenu/tests/test_controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py similarity index 87% rename from aries_cloudagent/protocols/actionmenu/tests/test_controller.py rename to aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py index e1f2469a93..5a7b9c5e5c 100644 --- a/aries_cloudagent/protocols/actionmenu/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,8 +1,8 @@ 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 .....config.injection_context import InjectionContext +from .....messaging.request_context import RequestContext from .. import controller as test_module diff --git a/aries_cloudagent/protocols/actionmenu/tests/test_routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py similarity index 99% rename from aries_cloudagent/protocols/actionmenu/tests/test_routes.py rename to aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py index 30dc968eaf..4f1e0a477e 100644 --- a/aries_cloudagent/protocols/actionmenu/tests/test_routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py @@ -1,7 +1,7 @@ from asynctest import TestCase as AsyncTestCase from asynctest import mock as async_mock -from ....storage.error import StorageNotFoundError +from .....storage.error import StorageNotFoundError from .. import routes as test_module diff --git a/aries_cloudagent/protocols/actionmenu/tests/test_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py similarity index 92% rename from aries_cloudagent/protocols/actionmenu/tests/test_service.py rename to aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py index b1702f18e8..751395eb16 100644 --- a/aries_cloudagent/protocols/actionmenu/tests/test_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py @@ -1,9 +1,9 @@ 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 ......config.injection_context import InjectionContext +from ......messaging.request_context import RequestContext +from ......messaging.responder import MockResponder from .. import driver_service as test_module diff --git a/aries_cloudagent/protocols/actionmenu/tests/test_util.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py similarity index 90% rename from aries_cloudagent/protocols/actionmenu/tests/test_util.py rename to aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py index 52533a1781..d1c556cc28 100644 --- a/aries_cloudagent/protocols/actionmenu/tests/test_util.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py @@ -1,12 +1,12 @@ from asynctest import TestCase as AsyncTestCase -from ....config.injection_context import InjectionContext -from ....connections.models.connection_record import ConnectionRecord -from ....messaging.responder import MockResponder -from ....storage.base import BaseStorage -from ....storage.basic import BasicStorage -from ....wallet.base import BaseWallet -from ....wallet.basic import BasicWallet +from .....config.injection_context import InjectionContext +from .....connections.models.connection_record import ConnectionRecord +from .....messaging.responder import MockResponder +from .....storage.base import BaseStorage +from .....storage.basic import BasicStorage +from .....wallet.base import BaseWallet +from .....wallet.basic import BasicWallet from .. import util as test_module from ..models.menu_form_param import MenuFormParam diff --git a/aries_cloudagent/protocols/actionmenu/util.py b/aries_cloudagent/protocols/actionmenu/v1_0/util.py similarity index 90% rename from aries_cloudagent/protocols/actionmenu/util.py rename to aries_cloudagent/protocols/actionmenu/v1_0/util.py index 996ea18139..300bc9f299 100644 --- a/aries_cloudagent/protocols/actionmenu/util.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/util.py @@ -1,8 +1,8 @@ """Action menu utility methods.""" -from ...config.injection_context import InjectionContext -from ...messaging.responder import BaseResponder -from ...storage.base import BaseStorage, StorageRecord, StorageNotFoundError +from ....config.injection_context import InjectionContext +from ....messaging.responder import BaseResponder +from ....storage.base import BaseStorage, StorageRecord, StorageNotFoundError from .messages.menu import Menu From 9da907f78adae73c32688748d1d858015fd83907 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 13:11:09 -0700 Subject: [PATCH 003/103] Include current minor version and validate Signed-off-by: Nicholas Rempel --- aries_cloudagent/core/plugin_registry.py | 32 ++++++++++++++++--- .../protocols/actionmenu/definition.py | 9 +++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/aries_cloudagent/core/plugin_registry.py b/aries_cloudagent/core/plugin_registry.py index 695d00e4e5..0a8452a482 100644 --- a/aries_cloudagent/core/plugin_registry.py +++ b/aries_cloudagent/core/plugin_registry.py @@ -53,13 +53,37 @@ def validate_version(self, version_list, module_name): try: type(version_dict["major_version"]) is int and type( - version_dict["minimum_minor"] - ) is int and type(version_dict["path"]) is str + version_dict["minimum_minor_version"] + ) is int and type( + version_dict["current_minor_version"] + ) is int and type( + version_dict["path"] + ) is str except KeyError as e: raise ProtocolDefinitionValidationError( f"Element of versions definition list is missing an attribute: {e}" ) + # Version number cannot be negative + if ( + version_dict["major_version"] < 0 + or version_dict["minimum_minor_version"] < 0 + or version_dict["current_minor_version"] < 0 + ): + raise ProtocolDefinitionValidationError( + "Version number cannot be negative" + ) + + # Minimum minor version cannot be great than current version + if ( + version_dict["minimum_minor_version"] + > version_dict["current_minor_version"] + ): + raise ProtocolDefinitionValidationError( + "Minimum supported minor version cannot" + + " be greater than current minor version" + ) + # Specified module must be loadable version_path = version_dict["path"] mod = ClassLoader.load_module(version_path, module_name) @@ -103,9 +127,7 @@ def register_plugin(self, module_name: str) -> ModuleType: try: self.validate_version(definition.versions, module_name) except ProtocolDefinitionValidationError as e: - LOGGER.error( - f"Protocol versions definition is malformed. {e}" - ) + LOGGER.error(f"Protocol versions definition is malformed. {e}") return None self._plugins[module_name] = mod diff --git a/aries_cloudagent/protocols/actionmenu/definition.py b/aries_cloudagent/protocols/actionmenu/definition.py index 6bb77e7868..62bddef6f5 100644 --- a/aries_cloudagent/protocols/actionmenu/definition.py +++ b/aries_cloudagent/protocols/actionmenu/definition.py @@ -1,3 +1,10 @@ """Version definitions for this protocol.""" -versions = [{"major_version": 1, "minimum_minor": 0, "path": "v1_0"}] +versions = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + } +] From be6e50617dbefee5267a26df88b737c2c82345ba Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 13:56:02 -0700 Subject: [PATCH 004/103] use absolute import paths Signed-off-by: Nicholas Rempel --- .../protocols/actionmenu/v1_0/base_service.py | 6 +++--- .../protocols/actionmenu/v1_0/controller.py | 2 +- .../protocols/actionmenu/v1_0/driver_service.py | 6 +++--- .../actionmenu/v1_0/handlers/menu_handler.py | 6 +++++- .../v1_0/handlers/menu_request_handler.py | 6 +++++- .../actionmenu/v1_0/handlers/perform_handler.py | 6 +++++- .../v1_0/handlers/tests/test_menu_handler.py | 4 ++-- .../handlers/tests/test_menu_request_handler.py | 6 +++--- .../v1_0/handlers/tests/test_perform_handler.py | 6 +++--- .../protocols/actionmenu/v1_0/message_types.py | 2 +- .../protocols/actionmenu/v1_0/messages/menu.py | 2 +- .../actionmenu/v1_0/messages/menu_request.py | 2 +- .../protocols/actionmenu/v1_0/messages/perform.py | 2 +- .../protocols/actionmenu/v1_0/models/menu_form.py | 2 +- .../actionmenu/v1_0/models/menu_form_param.py | 2 +- .../actionmenu/v1_0/models/menu_option.py | 2 +- .../protocols/actionmenu/v1_0/routes.py | 6 +++--- .../actionmenu/v1_0/tests/test_controller.py | 4 ++-- .../protocols/actionmenu/v1_0/tests/test_routes.py | 2 +- .../actionmenu/v1_0/tests/test_service.py | 6 +++--- .../protocols/actionmenu/v1_0/tests/test_util.py | 14 +++++++------- aries_cloudagent/protocols/actionmenu/v1_0/util.py | 10 +++++++--- 22 files changed, 60 insertions(+), 44 deletions(-) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/base_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/base_service.py index 874ba76ce5..ec07b3e142 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/base_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/base_service.py @@ -2,9 +2,9 @@ from abc import ABC, abstractmethod -from ....config.injection_context import InjectionContext -from ....connections.models.connection_record import ConnectionRecord -from ....messaging.agent_message import AgentMessage +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.messaging.agent_message import AgentMessage from .messages.menu import Menu diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/controller.py index 70a5a67252..376113a301 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/controller.py @@ -2,7 +2,7 @@ from typing import Sequence -from ....config.injection_context import InjectionContext +from aries_cloudagent.config.injection_context import InjectionContext from .base_service import BaseMenuService diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py index b5ea85adef..1aaad9dbdf 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/driver_service.py @@ -2,9 +2,9 @@ import logging -from ....connections.models.connection_record import ConnectionRecord -from ....messaging.agent_message import AgentMessage -from ....messaging.responder import BaseResponder +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.messaging.agent_message import AgentMessage +from aries_cloudagent.messaging.responder import BaseResponder from .base_service import BaseMenuService from .messages.menu import Menu diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_handler.py index a2ca3efcc8..4409c2ea42 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_handler.py @@ -1,6 +1,10 @@ """Action menu message handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.messaging.base_handler import ( + BaseHandler, + BaseResponder, + RequestContext, +) from ..messages.menu import Menu from ..util import save_connection_menu diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_request_handler.py index 7df59c02c8..4fd8e5c1f0 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_request_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/menu_request_handler.py @@ -1,6 +1,10 @@ """Action menu request message handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.messaging.base_handler import ( + BaseHandler, + BaseResponder, + RequestContext, +) from ..base_service import BaseMenuService from ..messages.menu_request import MenuRequest diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/perform_handler.py index bdb2e40273..10ed098770 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/perform_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/perform_handler.py @@ -1,6 +1,10 @@ """Action menu perform request message handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.messaging.base_handler import ( + BaseHandler, + BaseResponder, + RequestContext, +) from ..base_service import BaseMenuService from ..messages.perform import Perform diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py index a2287782b0..2ff9bc64e4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py @@ -4,8 +4,8 @@ TestCase as AsyncTestCase, ) -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder from .. import menu_handler as handler diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py index 6de8233fb2..bf547543b8 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py @@ -4,9 +4,9 @@ TestCase as AsyncTestCase, ) -from .....config.injection_context import InjectionContext -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder from .. import menu_request_handler as handler diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py index 93af2bccfb..129e7b4922 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py @@ -4,9 +4,9 @@ TestCase as AsyncTestCase, ) -from .....config.injection_context import InjectionContext -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder from .. import perform_handler as handler diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/message_types.py b/aries_cloudagent/protocols/actionmenu/v1_0/message_types.py index 5a006de1aa..1dd278c314 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/message_types.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/message_types.py @@ -12,7 +12,7 @@ NEW_MENU_REQUEST = f"{NEW_PROTOCOL_URI}/menu-request" NEW_PERFORM = f"{NEW_PROTOCOL_URI}/perform" -PROTOCOL_PACKAGE = "aries_cloudagent.protocols.actionmenu" +PROTOCOL_PACKAGE = "aries_cloudagent.protocols.actionmenu.v1_0" MESSAGE_TYPES = { MENU: f"{PROTOCOL_PACKAGE}.messages.menu.Menu", diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py index f94e074c94..f05c11c917 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu.py @@ -4,7 +4,7 @@ from marshmallow import fields -from .....messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema from ..message_types import MENU, PROTOCOL_PACKAGE from ..models.menu_option import MenuOption, MenuOptionSchema diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py index e294d7ce5c..c4c3b8a8ee 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/menu_request.py @@ -1,6 +1,6 @@ """Represents a request for an action menu.""" -from .....messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema from ..message_types import MENU_REQUEST, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py index 1ef15e7788..6f84993bb7 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/perform.py @@ -4,7 +4,7 @@ from marshmallow import fields -from .....messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema from ..message_types import PERFORM, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py index 3209c8481b..fad1a86e1f 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form.py @@ -4,7 +4,7 @@ from marshmallow import fields -from .....messaging.models.base import BaseModel, BaseModelSchema +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema from .menu_form_param import MenuFormParam, MenuFormParamSchema diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py index 7b2c77e70e..1a83db26ee 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_form_param.py @@ -2,7 +2,7 @@ from marshmallow import fields -from .....messaging.models.base import BaseModel, BaseModelSchema +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema class MenuFormParam(BaseModel): diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py index ac7dfd40e0..c734f7b0c4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/models/menu_option.py @@ -2,7 +2,7 @@ from marshmallow import fields -from .....messaging.models.base import BaseModel, BaseModelSchema +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema from .menu_form import MenuForm, MenuFormSchema diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/routes.py index e5092774ca..374f114c4e 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/routes.py @@ -7,9 +7,9 @@ from marshmallow import fields, Schema -from ....connections.models.connection_record import ConnectionRecord -from ....messaging.valid import UUIDFour -from ....storage.error import StorageNotFoundError +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.messaging.valid import UUIDFour +from aries_cloudagent.storage.error import StorageNotFoundError from .messages.menu import Menu from .messages.menu_request import MenuRequest diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py index 5a7b9c5e5c..386a1fc2af 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,8 +1,8 @@ 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 aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.messaging.request_context import RequestContext from .. import controller as test_module diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py index 4f1e0a477e..79c21670e0 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py @@ -1,7 +1,7 @@ from asynctest import TestCase as AsyncTestCase from asynctest import mock as async_mock -from .....storage.error import StorageNotFoundError +from aries_cloudagent.storage.error import StorageNotFoundError from .. import routes as test_module diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py index 751395eb16..57105ee46d 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py @@ -1,9 +1,9 @@ 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 aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder from .. import driver_service as test_module diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py index d1c556cc28..8b19020fb3 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py @@ -1,12 +1,12 @@ from asynctest import TestCase as AsyncTestCase -from .....config.injection_context import InjectionContext -from .....connections.models.connection_record import ConnectionRecord -from .....messaging.responder import MockResponder -from .....storage.base import BaseStorage -from .....storage.basic import BasicStorage -from .....wallet.base import BaseWallet -from .....wallet.basic import BasicWallet +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.messaging.responder import MockResponder +from aries_cloudagent.storage.base import BaseStorage +from aries_cloudagent.storage.basic import BasicStorage +from aries_cloudagent.wallet.base import BaseWallet +from aries_cloudagent.wallet.basic import BasicWallet from .. import util as test_module from ..models.menu_form_param import MenuFormParam diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/util.py b/aries_cloudagent/protocols/actionmenu/v1_0/util.py index 300bc9f299..001e96d05f 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/util.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/util.py @@ -1,8 +1,12 @@ """Action menu utility methods.""" -from ....config.injection_context import InjectionContext -from ....messaging.responder import BaseResponder -from ....storage.base import BaseStorage, StorageRecord, StorageNotFoundError +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.messaging.responder import BaseResponder +from aries_cloudagent.storage.base import ( + BaseStorage, + StorageRecord, + StorageNotFoundError, +) from .messages.menu import Menu From ece714931cf80cfd3d162635ab5f66b1b82ba0f9 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 14:39:45 -0700 Subject: [PATCH 005/103] Add tests and more validation restrictions Signed-off-by: Nicholas Rempel --- aries_cloudagent/core/plugin_registry.py | 18 +++++++ .../core/tests/test_plugin_registry.py | 47 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/core/plugin_registry.py b/aries_cloudagent/core/plugin_registry.py index 0a8452a482..fee2851ca0 100644 --- a/aries_cloudagent/core/plugin_registry.py +++ b/aries_cloudagent/core/plugin_registry.py @@ -43,6 +43,12 @@ def validate_version(self, version_list, module_name): "Versions definition is not of type list" ) + # Must have at least one definition + if len(version_list) < 1: + raise ProtocolDefinitionValidationError( + "Versions list must define at least one version module" + ) + for version_dict in version_list: # Dicts must have correct format is_dict = type(version_dict) is dict @@ -84,6 +90,18 @@ def validate_version(self, version_list, module_name): + " be greater than current minor version" ) + # There can only be one definition per major version + major_version = version_dict["major_version"] + count = 0 + for version_dict in version_list: + if version_dict["major_version"] == major_version: + count += 1 + if count > 1: + raise ProtocolDefinitionValidationError( + "There can only be one definition per major version. " + + f"Found {count} for major version {major_version}." + ) + # Specified module must be loadable version_path = version_dict["path"] mod = ClassLoader.load_module(version_path, module_name) diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index 92ec76a398..f4fc3ed001 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -1,3 +1,5 @@ +import pytest + from asynctest import TestCase as AsyncTestCase, mock as async_mock from ...config.injection_context import InjectionContext @@ -5,6 +7,7 @@ from ..plugin_registry import PluginRegistry +from ..error import ProtocolDefinitionValidationError class TestPluginRegistry(AsyncTestCase): def setUp(self): @@ -31,12 +34,54 @@ async def test_register_routes(self): mod.routes.register = async_mock.CoroutineMock() with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes), + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) ) as load_module: await self.registry.register_admin_routes(app) load_module.assert_called_once_with(mod_name + ".routes") mod.routes.register.assert_awaited_once_with(app) + async def test_validate_version_not_a_list(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = {} + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + + async def test_validate_version_list_element_not_an_object(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [{}, []] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + + async def test_validate_version_list_element_empty(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + def test_repr(self): assert type(repr(self.registry)) is str From ed0b676695a78d5f7f76bc7ef7935d13bd6f67e0 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 15:05:52 -0700 Subject: [PATCH 006/103] more tests Signed-off-by: Nicholas Rempel --- .../core/tests/test_plugin_registry.py | 115 +++++++++++++++++- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index f4fc3ed001..cb78b57dae 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -1,6 +1,6 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from asynctest import TestCase as AsyncTestCase, mock as async_mock, call from ...config.injection_context import InjectionContext from ...utils.classloader import ClassLoader @@ -9,6 +9,7 @@ from ..error import ProtocolDefinitionValidationError + class TestPluginRegistry(AsyncTestCase): def setUp(self): self.registry = PluginRegistry() @@ -54,7 +55,6 @@ async def test_validate_version_not_a_list(self): with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) - async def test_validate_version_list_element_not_an_object(self): mod_name = "test_mod" mod = async_mock.MagicMock() @@ -68,7 +68,6 @@ async def test_validate_version_list_element_not_an_object(self): with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) - async def test_validate_version_list_element_empty(self): mod_name = "test_mod" mod = async_mock.MagicMock() @@ -82,6 +81,116 @@ async def test_validate_version_list_element_empty(self): with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) + async def test_validate_version_list_missing_attribute(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + # "path": "v1_0", # missing + } + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + async def test_validate_version_negative_version(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": -1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + } + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + async def test_validate_version_min_greater_current(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": 1, + "minimum_minor_version": 1, + "current_minor_version": 0, + "path": "v1_0", + } + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + + async def test_validate_version_list_correct(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + }, + { + "major_version": 2, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v2_0" + } + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + assert self.registry.validate_version(versions_not_a_list, mod_name) is True + + load_module.has_calls( + call(versions_not_a_list[0]["path"], mod_name), + call(versions_not_a_list[1]["path"], mod_name) + ) + + async def test_validate_version_list_extra_attributes_ok(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + "not": "an attribute", + } + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ) as load_module: + assert self.registry.validate_version(versions_not_a_list, mod_name) is True def test_repr(self): assert type(repr(self.registry)) is str From c16b301d553f1a8751f50692a1825c67fae28e14 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 19 Mar 2020 15:23:43 -0700 Subject: [PATCH 007/103] more tests Signed-off-by: Nicholas Rempel --- .../core/tests/test_plugin_registry.py | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index cb78b57dae..6702f34b69 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -50,7 +50,7 @@ async def test_validate_version_not_a_list(self): versions_not_a_list = {} with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) @@ -63,7 +63,7 @@ async def test_validate_version_list_element_not_an_object(self): versions_not_a_list = [{}, []] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) @@ -76,7 +76,7 @@ async def test_validate_version_list_element_empty(self): versions_not_a_list = [] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) @@ -96,7 +96,7 @@ async def test_validate_version_list_missing_attribute(self): ] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) @@ -116,7 +116,7 @@ async def test_validate_version_negative_version(self): ] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) @@ -136,11 +136,56 @@ async def test_validate_version_min_greater_current(self): ] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) + + async def test_validate_version_multiple_major(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + }, + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 1, + "path": "v1_1", + }, + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) + async def test_validate_version_bad_path(self): + mod_name = "test_mod" + mod = async_mock.MagicMock() + mod.__name__ = mod_name + + versions_not_a_list = [ + { + "major_version": 1, + "minimum_minor_version": 1, + "current_minor_version": 0, + "path": "v1_0", + } + ] + + with async_mock.patch.object( + ClassLoader, "load_module", async_mock.MagicMock(return_value=None) + ) as load_module: + with pytest.raises(ProtocolDefinitionValidationError): + self.registry.validate_version(versions_not_a_list, mod_name) async def test_validate_version_list_correct(self): mod_name = "test_mod" @@ -158,18 +203,18 @@ async def test_validate_version_list_correct(self): "major_version": 2, "minimum_minor_version": 0, "current_minor_version": 0, - "path": "v2_0" - } + "path": "v2_0", + }, ] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: assert self.registry.validate_version(versions_not_a_list, mod_name) is True - + load_module.has_calls( call(versions_not_a_list[0]["path"], mod_name), - call(versions_not_a_list[1]["path"], mod_name) + call(versions_not_a_list[1]["path"], mod_name), ) async def test_validate_version_list_extra_attributes_ok(self): @@ -188,7 +233,7 @@ async def test_validate_version_list_extra_attributes_ok(self): ] with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=mod.routes) + ClassLoader, "load_module", async_mock.MagicMock() ) as load_module: assert self.registry.validate_version(versions_not_a_list, mod_name) is True From efdbb06a88c8d79d9875fc1bdf24780a791cbdb7 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Mon, 23 Mar 2020 10:52:08 -0700 Subject: [PATCH 008/103] Refactor basicmessage Signed-off-by: Nicholas Rempel --- aries_cloudagent/protocols/basicmessage/definition.py | 10 ++++++++++ .../basicmessage/{handlers => v1_0}/__init__.py | 0 .../{handlers/tests => v1_0/handlers}/__init__.py | 0 .../{ => v1_0}/handlers/basicmessage_handler.py | 6 +++++- .../{messages => v1_0/handlers/tests}/__init__.py | 0 .../handlers/tests/test_basicmessage_handler.py | 9 ++++----- .../protocols/basicmessage/{ => v1_0}/message_types.py | 2 +- .../{messages/tests => v1_0/messages}/__init__.py | 0 .../basicmessage/{ => v1_0}/messages/basicmessage.py | 8 ++++---- .../basicmessage/{ => v1_0/messages}/tests/__init__.py | 0 .../{ => v1_0}/messages/tests/test_basic_message.py | 0 .../protocols/basicmessage/{ => v1_0}/routes.py | 4 ++-- .../protocols/basicmessage/v1_0/tests/__init__.py | 0 .../basicmessage/{ => v1_0}/tests/test_routes.py | 2 +- 14 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 aries_cloudagent/protocols/basicmessage/definition.py rename aries_cloudagent/protocols/basicmessage/{handlers => v1_0}/__init__.py (100%) rename aries_cloudagent/protocols/basicmessage/{handlers/tests => v1_0/handlers}/__init__.py (100%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/handlers/basicmessage_handler.py (94%) rename aries_cloudagent/protocols/basicmessage/{messages => v1_0/handlers/tests}/__init__.py (100%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/handlers/tests/test_basicmessage_handler.py (91%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/message_types.py (87%) rename aries_cloudagent/protocols/basicmessage/{messages/tests => v1_0/messages}/__init__.py (100%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/messages/basicmessage.py (86%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0/messages}/tests/__init__.py (100%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/messages/tests/test_basic_message.py (100%) rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/routes.py (90%) create mode 100644 aries_cloudagent/protocols/basicmessage/v1_0/tests/__init__.py rename aries_cloudagent/protocols/basicmessage/{ => v1_0}/tests/test_routes.py (97%) diff --git a/aries_cloudagent/protocols/basicmessage/definition.py b/aries_cloudagent/protocols/basicmessage/definition.py new file mode 100644 index 0000000000..62bddef6f5 --- /dev/null +++ b/aries_cloudagent/protocols/basicmessage/definition.py @@ -0,0 +1,10 @@ +"""Version definitions for this protocol.""" + +versions = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + } +] diff --git a/aries_cloudagent/protocols/basicmessage/handlers/__init__.py b/aries_cloudagent/protocols/basicmessage/v1_0/__init__.py similarity index 100% rename from aries_cloudagent/protocols/basicmessage/handlers/__init__.py rename to aries_cloudagent/protocols/basicmessage/v1_0/__init__.py diff --git a/aries_cloudagent/protocols/basicmessage/handlers/tests/__init__.py b/aries_cloudagent/protocols/basicmessage/v1_0/handlers/__init__.py similarity index 100% rename from aries_cloudagent/protocols/basicmessage/handlers/tests/__init__.py rename to aries_cloudagent/protocols/basicmessage/v1_0/handlers/__init__.py diff --git a/aries_cloudagent/protocols/basicmessage/handlers/basicmessage_handler.py b/aries_cloudagent/protocols/basicmessage/v1_0/handlers/basicmessage_handler.py similarity index 94% rename from aries_cloudagent/protocols/basicmessage/handlers/basicmessage_handler.py rename to aries_cloudagent/protocols/basicmessage/v1_0/handlers/basicmessage_handler.py index 21697bd0cf..7f8e9f7e11 100644 --- a/aries_cloudagent/protocols/basicmessage/handlers/basicmessage_handler.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/handlers/basicmessage_handler.py @@ -1,6 +1,10 @@ """Basic message handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.messaging.base_handler import ( + BaseHandler, + BaseResponder, + RequestContext, +) from ..messages.basicmessage import BasicMessage diff --git a/aries_cloudagent/protocols/basicmessage/messages/__init__.py b/aries_cloudagent/protocols/basicmessage/v1_0/handlers/tests/__init__.py similarity index 100% rename from aries_cloudagent/protocols/basicmessage/messages/__init__.py rename to aries_cloudagent/protocols/basicmessage/v1_0/handlers/tests/__init__.py diff --git a/aries_cloudagent/protocols/basicmessage/handlers/tests/test_basicmessage_handler.py b/aries_cloudagent/protocols/basicmessage/v1_0/handlers/tests/test_basicmessage_handler.py similarity index 91% rename from aries_cloudagent/protocols/basicmessage/handlers/tests/test_basicmessage_handler.py rename to aries_cloudagent/protocols/basicmessage/v1_0/handlers/tests/test_basicmessage_handler.py index 6528b3a8db..49978e69f7 100644 --- a/aries_cloudagent/protocols/basicmessage/handlers/tests/test_basicmessage_handler.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/handlers/tests/test_basicmessage_handler.py @@ -1,9 +1,9 @@ import pytest from unittest import mock -from .....messaging.base_handler import HandlerException -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder +from aries_cloudagent.messaging.base_handler import HandlerException +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder from ...handlers.basicmessage_handler import BasicMessageHandler from ...messages.basicmessage import BasicMessage @@ -64,8 +64,7 @@ async def test_basic_message_response_reply_with(self, request_context): request_context.default_label = "agent" test_message_content = "Reply with: g'day" request_context.message = BasicMessage( - content=test_message_content, - localization="en-CA" + content=test_message_content, localization="en-CA" ) request_context.connection_ready = True handler = BasicMessageHandler() diff --git a/aries_cloudagent/protocols/basicmessage/message_types.py b/aries_cloudagent/protocols/basicmessage/v1_0/message_types.py similarity index 87% rename from aries_cloudagent/protocols/basicmessage/message_types.py rename to aries_cloudagent/protocols/basicmessage/v1_0/message_types.py index 4c793d23eb..fbaf4d4a3b 100644 --- a/aries_cloudagent/protocols/basicmessage/message_types.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/message_types.py @@ -8,7 +8,7 @@ NEW_BASIC_MESSAGE = f"{NEW_PROTOCOL_URI}/message" -PROTOCOL_PACKAGE = "aries_cloudagent.protocols.basicmessage" +PROTOCOL_PACKAGE = "aries_cloudagent.protocols.basicmessage/v1_0" MESSAGE_TYPES = { BASIC_MESSAGE: f"{PROTOCOL_PACKAGE}.messages.basicmessage.BasicMessage", diff --git a/aries_cloudagent/protocols/basicmessage/messages/tests/__init__.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/__init__.py similarity index 100% rename from aries_cloudagent/protocols/basicmessage/messages/tests/__init__.py rename to aries_cloudagent/protocols/basicmessage/v1_0/messages/__init__.py diff --git a/aries_cloudagent/protocols/basicmessage/messages/basicmessage.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/basicmessage.py similarity index 86% rename from aries_cloudagent/protocols/basicmessage/messages/basicmessage.py rename to aries_cloudagent/protocols/basicmessage/v1_0/messages/basicmessage.py index 343be01acd..f23cb439d4 100644 --- a/aries_cloudagent/protocols/basicmessage/messages/basicmessage.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/messages/basicmessage.py @@ -5,9 +5,9 @@ from marshmallow import fields -from ....messaging.agent_message import AgentMessage, AgentMessageSchema -from ....messaging.util import datetime_now, datetime_to_str -from ....messaging.valid import INDY_ISO8601_DATETIME +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.util import datetime_now, datetime_to_str +from aries_cloudagent.messaging.valid import INDY_ISO8601_DATETIME from ..message_types import BASIC_MESSAGE, PROTOCOL_PACKAGE @@ -63,4 +63,4 @@ class Meta: description="Time message was sent, ISO8601 with space date/time separator", **INDY_ISO8601_DATETIME, ) - content = fields.Str(required=True, description="Message content", example="Hello",) + content = fields.Str(required=True, description="Message content", example="Hello") diff --git a/aries_cloudagent/protocols/basicmessage/tests/__init__.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/__init__.py similarity index 100% rename from aries_cloudagent/protocols/basicmessage/tests/__init__.py rename to aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/__init__.py diff --git a/aries_cloudagent/protocols/basicmessage/messages/tests/test_basic_message.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py similarity index 100% rename from aries_cloudagent/protocols/basicmessage/messages/tests/test_basic_message.py rename to aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py diff --git a/aries_cloudagent/protocols/basicmessage/routes.py b/aries_cloudagent/protocols/basicmessage/v1_0/routes.py similarity index 90% rename from aries_cloudagent/protocols/basicmessage/routes.py rename to aries_cloudagent/protocols/basicmessage/v1_0/routes.py index 2368464c55..112196b9da 100644 --- a/aries_cloudagent/protocols/basicmessage/routes.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/routes.py @@ -5,8 +5,8 @@ from marshmallow import fields, Schema -from ...connections.models.connection_record import ConnectionRecord -from ...storage.error import StorageNotFoundError +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.storage.error import StorageNotFoundError from .messages.basicmessage import BasicMessage diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/tests/__init__.py b/aries_cloudagent/protocols/basicmessage/v1_0/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aries_cloudagent/protocols/basicmessage/tests/test_routes.py b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py similarity index 97% rename from aries_cloudagent/protocols/basicmessage/tests/test_routes.py rename to aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py index ad06480a13..8a6eefaca9 100644 --- a/aries_cloudagent/protocols/basicmessage/tests/test_routes.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py @@ -1,7 +1,7 @@ from asynctest import TestCase as AsyncTestCase from asynctest import mock as async_mock -from ....storage.error import StorageNotFoundError +from aries_cloudagent.storage.error import StorageNotFoundError from .. import routes as test_module From 86273d19495f2f658de2c13ebe6135f8e7bf5a49 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Mon, 23 Mar 2020 11:09:09 -0700 Subject: [PATCH 009/103] update message_types path Signed-off-by: Nicholas Rempel --- aries_cloudagent/protocols/basicmessage/v1_0/message_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/message_types.py b/aries_cloudagent/protocols/basicmessage/v1_0/message_types.py index fbaf4d4a3b..d3ff4aecd6 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/message_types.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/message_types.py @@ -8,7 +8,7 @@ NEW_BASIC_MESSAGE = f"{NEW_PROTOCOL_URI}/message" -PROTOCOL_PACKAGE = "aries_cloudagent.protocols.basicmessage/v1_0" +PROTOCOL_PACKAGE = "aries_cloudagent.protocols.basicmessage.v1_0" MESSAGE_TYPES = { BASIC_MESSAGE: f"{PROTOCOL_PACKAGE}.messages.basicmessage.BasicMessage", From 7cb06ea87d0543a807f9d100073009e8dda44c67 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Mon, 23 Mar 2020 15:14:35 -0700 Subject: [PATCH 010/103] Refactor connection protocol Signed-off-by: Nicholas Rempel --- .../protocols/connections/definition.py | 10 + .../{handlers => v1_0}/__init__.py | 0 .../tests => v1_0/handlers}/__init__.py | 0 .../handlers/connection_invitation_handler.py | 2 +- .../handlers/connection_request_handler.py | 2 +- .../handlers/connection_response_handler.py | 4 +- .../handlers/tests}/__init__.py | 0 .../handlers/tests/test_invitation_handler.py | 8 +- .../handlers/tests/test_request_handler.py | 49 ++-- .../handlers/tests/test_response_handler.py | 48 ++-- .../connections/{ => v1_0}/manager.py | 38 +-- .../connections/{ => v1_0}/message_types.py | 2 +- .../tests => v1_0/messages}/__init__.py | 0 .../messages/connection_invitation.py | 6 +- .../{ => v1_0}/messages/connection_request.py | 3 +- .../messages/connection_response.py | 3 +- .../{ => v1_0}/messages/problem_report.py | 3 +- .../messages/tests}/__init__.py | 0 .../tests/test_connection_invitation.py | 3 +- .../messages/tests/test_connection_request.py | 11 +- .../tests/test_connection_response.py | 9 +- .../messages/tests/test_problem_report.py | 3 +- .../{tests => v1_0/models}/__init__.py | 0 .../{ => v1_0}/models/connection_detail.py | 6 +- .../connections/{ => v1_0}/routes.py | 6 +- .../connections/v1_0/tests/__init__.py | 0 .../{ => v1_0}/tests/test_manager.py | 256 ++++++------------ .../{ => v1_0}/tests/test_routes.py | 11 +- 28 files changed, 206 insertions(+), 277 deletions(-) create mode 100644 aries_cloudagent/protocols/connections/definition.py rename aries_cloudagent/protocols/connections/{handlers => v1_0}/__init__.py (100%) rename aries_cloudagent/protocols/connections/{handlers/tests => v1_0/handlers}/__init__.py (100%) rename aries_cloudagent/protocols/connections/{ => v1_0}/handlers/connection_invitation_handler.py (91%) rename aries_cloudagent/protocols/connections/{ => v1_0}/handlers/connection_request_handler.py (94%) rename aries_cloudagent/protocols/connections/{ => v1_0}/handlers/connection_response_handler.py (92%) rename aries_cloudagent/protocols/connections/{messages => v1_0/handlers/tests}/__init__.py (100%) rename aries_cloudagent/protocols/connections/{ => v1_0}/handlers/tests/test_invitation_handler.py (78%) rename aries_cloudagent/protocols/connections/{ => v1_0}/handlers/tests/test_request_handler.py (85%) rename aries_cloudagent/protocols/connections/{ => v1_0}/handlers/tests/test_response_handler.py (87%) rename aries_cloudagent/protocols/connections/{ => v1_0}/manager.py (97%) rename aries_cloudagent/protocols/connections/{ => v1_0}/message_types.py (95%) rename aries_cloudagent/protocols/connections/{messages/tests => v1_0/messages}/__init__.py (100%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/connection_invitation.py (95%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/connection_request.py (95%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/connection_response.py (93%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/problem_report.py (95%) rename aries_cloudagent/protocols/connections/{models => v1_0/messages/tests}/__init__.py (100%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/tests/test_connection_invitation.py (98%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/tests/test_connection_request.py (95%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/tests/test_connection_response.py (94%) rename aries_cloudagent/protocols/connections/{ => v1_0}/messages/tests/test_problem_report.py (89%) rename aries_cloudagent/protocols/connections/{tests => v1_0/models}/__init__.py (100%) rename aries_cloudagent/protocols/connections/{ => v1_0}/models/connection_detail.py (91%) rename aries_cloudagent/protocols/connections/{ => v1_0}/routes.py (98%) create mode 100644 aries_cloudagent/protocols/connections/v1_0/tests/__init__.py rename aries_cloudagent/protocols/connections/{ => v1_0}/tests/test_manager.py (90%) rename aries_cloudagent/protocols/connections/{ => v1_0}/tests/test_routes.py (98%) diff --git a/aries_cloudagent/protocols/connections/definition.py b/aries_cloudagent/protocols/connections/definition.py new file mode 100644 index 0000000000..62bddef6f5 --- /dev/null +++ b/aries_cloudagent/protocols/connections/definition.py @@ -0,0 +1,10 @@ +"""Version definitions for this protocol.""" + +versions = [ + { + "major_version": 1, + "minimum_minor_version": 0, + "current_minor_version": 0, + "path": "v1_0", + } +] diff --git a/aries_cloudagent/protocols/connections/handlers/__init__.py b/aries_cloudagent/protocols/connections/v1_0/__init__.py similarity index 100% rename from aries_cloudagent/protocols/connections/handlers/__init__.py rename to aries_cloudagent/protocols/connections/v1_0/__init__.py diff --git a/aries_cloudagent/protocols/connections/handlers/tests/__init__.py b/aries_cloudagent/protocols/connections/v1_0/handlers/__init__.py similarity index 100% rename from aries_cloudagent/protocols/connections/handlers/tests/__init__.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/__init__.py diff --git a/aries_cloudagent/protocols/connections/handlers/connection_invitation_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/connection_invitation_handler.py similarity index 91% rename from aries_cloudagent/protocols/connections/handlers/connection_invitation_handler.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/connection_invitation_handler.py index 1ee6c20424..7ddf53d003 100644 --- a/aries_cloudagent/protocols/connections/handlers/connection_invitation_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/connection_invitation_handler.py @@ -1,6 +1,6 @@ """Connect invitation handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.messaging.base_handler import BaseHandler, BaseResponder, RequestContext from ..messages.connection_invitation import ConnectionInvitation from ..messages.problem_report import ProblemReport, ProblemReportReason diff --git a/aries_cloudagent/protocols/connections/handlers/connection_request_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/connection_request_handler.py similarity index 94% rename from aries_cloudagent/protocols/connections/handlers/connection_request_handler.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/connection_request_handler.py index 56f0bdb347..0fb56440df 100644 --- a/aries_cloudagent/protocols/connections/handlers/connection_request_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/connection_request_handler.py @@ -1,6 +1,6 @@ """Connection request handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.messaging.base_handler import BaseHandler, BaseResponder, RequestContext from ..manager import ConnectionManager, ConnectionManagerError from ..messages.connection_request import ConnectionRequest diff --git a/aries_cloudagent/protocols/connections/handlers/connection_response_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/connection_response_handler.py similarity index 92% rename from aries_cloudagent/protocols/connections/handlers/connection_response_handler.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/connection_response_handler.py index 2450453ed4..d702582b35 100644 --- a/aries_cloudagent/protocols/connections/handlers/connection_response_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/connection_response_handler.py @@ -1,7 +1,7 @@ """Connection response handler.""" -from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext -from ....protocols.trustping.messages.ping import Ping +from aries_cloudagent.messaging.base_handler import BaseHandler, BaseResponder, RequestContext +from aries_cloudagent.protocols.trustping.messages.ping import Ping from ..manager import ConnectionManager, ConnectionManagerError from ..messages.connection_response import ConnectionResponse diff --git a/aries_cloudagent/protocols/connections/messages/__init__.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/__init__.py similarity index 100% rename from aries_cloudagent/protocols/connections/messages/__init__.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/tests/__init__.py diff --git a/aries_cloudagent/protocols/connections/handlers/tests/test_invitation_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_invitation_handler.py similarity index 78% rename from aries_cloudagent/protocols/connections/handlers/tests/test_invitation_handler.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_invitation_handler.py index 4e1a5fee40..bb866253b4 100644 --- a/aries_cloudagent/protocols/connections/handlers/tests/test_invitation_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_invitation_handler.py @@ -1,9 +1,9 @@ import pytest -from .....messaging.base_handler import HandlerException -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder -from .....transport.inbound.receipt import MessageReceipt +from aries_cloudagent.messaging.base_handler import HandlerException +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder +from aries_cloudagent.transport.inbound.receipt import MessageReceipt from ...handlers.connection_invitation_handler import ConnectionInvitationHandler from ...messages.connection_invitation import ConnectionInvitation diff --git a/aries_cloudagent/protocols/connections/handlers/tests/test_request_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py similarity index 85% rename from aries_cloudagent/protocols/connections/handlers/tests/test_request_handler.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py index f7b8051bb6..6532f5a928 100644 --- a/aries_cloudagent/protocols/connections/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py @@ -1,12 +1,17 @@ import pytest from asynctest import mock as async_mock -from .....connections.models import connection_target -from .....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service -from .....messaging.base_handler import HandlerException -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder -from .....transport.inbound.receipt import MessageReceipt +from aries_cloudagent.connections.models import connection_target +from aries_cloudagent.connections.models.diddoc import ( + DIDDoc, + PublicKey, + PublicKeyType, + Service, +) +from aries_cloudagent.messaging.base_handler import HandlerException +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder +from aries_cloudagent.transport.inbound.receipt import MessageReceipt from ...handlers import connection_request_handler as handler from ...manager import ConnectionManagerError @@ -21,12 +26,14 @@ def request_context() -> RequestContext: ctx.message_receipt = MessageReceipt() yield ctx + TEST_DID = "55GkHamhTU1ZbTbV2ab9DE" TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" TEST_LABEL = "Label" TEST_ENDPOINT = "http://localhost" TEST_IMAGE_URL = "http://aries.ca/images/sample.png" + @pytest.fixture() def did_doc(): doc = DIDDoc(did=TEST_DID) @@ -34,23 +41,13 @@ def did_doc(): ident = "1" pk_value = TEST_VERKEY pk = PublicKey( - TEST_DID, - ident, - pk_value, - PublicKeyType.ED25519_SIG_2018, - controller, - False, + TEST_DID, ident, pk_value, PublicKeyType.ED25519_SIG_2018, controller, False ) doc.set(pk) recip_keys = [pk] router_keys = [] service = Service( - TEST_DID, - "indy", - "IndyAgent", - recip_keys, - router_keys, - TEST_ENDPOINT, + TEST_DID, "indy", "IndyAgent", recip_keys, router_keys, TEST_ENDPOINT ) doc.set(service) yield doc @@ -96,11 +93,7 @@ async def test_problem_report(self, mock_conn_mgr, request_context): @async_mock.patch.object(handler, "ConnectionManager") @async_mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( - self, - mock_conn_target, - mock_conn_mgr, - request_context, - did_doc + self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( @@ -112,7 +105,7 @@ async def test_problem_report_did_doc( request_context.message = ConnectionRequest( connection=ConnectionDetail(did=TEST_DID, did_doc=did_doc), label=TEST_LABEL, - image_url=TEST_IMAGE_URL + image_url=TEST_IMAGE_URL, ) handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -130,11 +123,7 @@ async def test_problem_report_did_doc( @async_mock.patch.object(handler, "ConnectionManager") @async_mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( - self, - mock_conn_target, - mock_conn_mgr, - request_context, - did_doc + self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( @@ -146,7 +135,7 @@ async def test_problem_report_did_doc_no_conn_target( request_context.message = ConnectionRequest( connection=ConnectionDetail(did=TEST_DID, did_doc=did_doc), label=TEST_LABEL, - image_url=TEST_IMAGE_URL + image_url=TEST_IMAGE_URL, ) handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/connections/handlers/tests/test_response_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py similarity index 87% rename from aries_cloudagent/protocols/connections/handlers/tests/test_response_handler.py rename to aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py index 74cdadb8e0..5b331c5c9d 100644 --- a/aries_cloudagent/protocols/connections/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py @@ -1,13 +1,18 @@ import pytest from asynctest import mock as async_mock -from .....connections.models import connection_target -from .....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service -from .....messaging.base_handler import HandlerException -from .....messaging.request_context import RequestContext -from .....messaging.responder import MockResponder -from .....protocols.trustping.messages.ping import Ping -from .....transport.inbound.receipt import MessageReceipt +from aries_cloudagent.connections.models import connection_target +from aries_cloudagent.connections.models.diddoc import ( + DIDDoc, + PublicKey, + PublicKeyType, + Service, +) +from aries_cloudagent.messaging.base_handler import HandlerException +from aries_cloudagent.messaging.request_context import RequestContext +from aries_cloudagent.messaging.responder import MockResponder +from aries_cloudagent.protocols.trustping.messages.ping import Ping +from aries_cloudagent.transport.inbound.receipt import MessageReceipt from ...handlers import connection_response_handler as handler from ...manager import ConnectionManagerError @@ -22,12 +27,14 @@ def request_context() -> RequestContext: ctx.message_receipt = MessageReceipt() yield ctx + TEST_DID = "55GkHamhTU1ZbTbV2ab9DE" TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" TEST_LABEL = "Label" TEST_ENDPOINT = "http://localhost" TEST_IMAGE_URL = "http://aries.ca/images/sample.png" + @pytest.fixture() def did_doc(): doc = DIDDoc(did=TEST_DID) @@ -35,27 +42,18 @@ def did_doc(): ident = "1" pk_value = TEST_VERKEY pk = PublicKey( - TEST_DID, - ident, - pk_value, - PublicKeyType.ED25519_SIG_2018, - controller, - False, + TEST_DID, ident, pk_value, PublicKeyType.ED25519_SIG_2018, controller, False ) doc.set(pk) recip_keys = [pk] router_keys = [] service = Service( - TEST_DID, - "indy", - "IndyAgent", - recip_keys, - router_keys, - TEST_ENDPOINT, + TEST_DID, "indy", "IndyAgent", recip_keys, router_keys, TEST_ENDPOINT ) doc.set(service) yield doc + class TestResponseHandler: @pytest.mark.asyncio @async_mock.patch.object(handler, "ConnectionManager") @@ -115,11 +113,7 @@ async def test_problem_report(self, mock_conn_mgr, request_context): @async_mock.patch.object(handler, "ConnectionManager") @async_mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( - self, - mock_conn_target, - mock_conn_mgr, - request_context, - did_doc + self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( @@ -147,11 +141,7 @@ async def test_problem_report_did_doc( @async_mock.patch.object(handler, "ConnectionManager") @async_mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( - self, - mock_conn_target, - mock_conn_mgr, - request_context, - did_doc + self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( diff --git a/aries_cloudagent/protocols/connections/manager.py b/aries_cloudagent/protocols/connections/v1_0/manager.py similarity index 97% rename from aries_cloudagent/protocols/connections/manager.py rename to aries_cloudagent/protocols/connections/v1_0/manager.py index 70d5657412..6fd0190e5a 100644 --- a/aries_cloudagent/protocols/connections/manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/manager.py @@ -4,25 +4,25 @@ from typing import Sequence, Tuple -from ...cache.base import BaseCache -from ...connections.models.connection_record import ConnectionRecord -from ...connections.models.connection_target import ConnectionTarget -from ...connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service -from ...config.base import InjectorError -from ...config.injection_context import InjectionContext -from ...core.error import BaseError -from ...ledger.base import BaseLedger -from ...messaging.responder import BaseResponder -from ...storage.base import BaseStorage -from ...storage.error import StorageError, StorageNotFoundError -from ...storage.record import StorageRecord -from ...transport.inbound.receipt import MessageReceipt -from ...wallet.base import BaseWallet, DIDInfo -from ...wallet.crypto import create_keypair, seed_to_did -from ...wallet.error import WalletNotFoundError -from ...wallet.util import bytes_to_b58 - -from ..routing.manager import RoutingManager +from aries_cloudagent.cache.base import BaseCache +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.connections.models.connection_target import ConnectionTarget +from aries_cloudagent.connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service +from aries_cloudagent.config.base import InjectorError +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.core.error import BaseError +from aries_cloudagent.ledger.base import BaseLedger +from aries_cloudagent.messaging.responder import BaseResponder +from aries_cloudagent.storage.base import BaseStorage +from aries_cloudagent.storage.error import StorageError, StorageNotFoundError +from aries_cloudagent.storage.record import StorageRecord +from aries_cloudagent.transport.inbound.receipt import MessageReceipt +from aries_cloudagent.wallet.base import BaseWallet, DIDInfo +from aries_cloudagent.wallet.crypto import create_keypair, seed_to_did +from aries_cloudagent.wallet.error import WalletNotFoundError +from aries_cloudagent.wallet.util import bytes_to_b58 + +from aries_cloudagent.protocols.routing.manager import RoutingManager from .messages.connection_invitation import ConnectionInvitation from .messages.connection_request import ConnectionRequest diff --git a/aries_cloudagent/protocols/connections/message_types.py b/aries_cloudagent/protocols/connections/v1_0/message_types.py similarity index 95% rename from aries_cloudagent/protocols/connections/message_types.py rename to aries_cloudagent/protocols/connections/v1_0/message_types.py index 92cae00ce4..bfa40fbf2f 100644 --- a/aries_cloudagent/protocols/connections/message_types.py +++ b/aries_cloudagent/protocols/connections/v1_0/message_types.py @@ -14,7 +14,7 @@ NEW_CONNECTION_RESPONSE = f"{NEW_PROTOCOL_URI}/response" NEW_PROBLEM_REPORT = f"{NEW_PROTOCOL_URI}/problem_report" -PROTOCOL_PACKAGE = "aries_cloudagent.protocols.connections" +PROTOCOL_PACKAGE = "aries_cloudagent.protocols.connections.v1_0" MESSAGE_TYPES = { CONNECTION_INVITATION: ( diff --git a/aries_cloudagent/protocols/connections/messages/tests/__init__.py b/aries_cloudagent/protocols/connections/v1_0/messages/__init__.py similarity index 100% rename from aries_cloudagent/protocols/connections/messages/tests/__init__.py rename to aries_cloudagent/protocols/connections/v1_0/messages/__init__.py diff --git a/aries_cloudagent/protocols/connections/messages/connection_invitation.py b/aries_cloudagent/protocols/connections/v1_0/messages/connection_invitation.py similarity index 95% rename from aries_cloudagent/protocols/connections/messages/connection_invitation.py rename to aries_cloudagent/protocols/connections/v1_0/messages/connection_invitation.py index 87c8b2c6dd..556c510c98 100644 --- a/aries_cloudagent/protocols/connections/messages/connection_invitation.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/connection_invitation.py @@ -5,9 +5,9 @@ from marshmallow import ValidationError, fields, validates_schema -from ....messaging.agent_message import AgentMessage, AgentMessageSchema -from ....messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY -from ....wallet.util import b64_to_bytes, bytes_to_b64 +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY +from aries_cloudagent.wallet.util import b64_to_bytes, bytes_to_b64 from ..message_types import CONNECTION_INVITATION, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/connections/messages/connection_request.py b/aries_cloudagent/protocols/connections/v1_0/messages/connection_request.py similarity index 95% rename from aries_cloudagent/protocols/connections/messages/connection_request.py rename to aries_cloudagent/protocols/connections/v1_0/messages/connection_request.py index d30a550146..e29b67d27a 100644 --- a/aries_cloudagent/protocols/connections/messages/connection_request.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/connection_request.py @@ -2,7 +2,8 @@ from marshmallow import fields -from ....messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema + from ..message_types import CONNECTION_REQUEST, PROTOCOL_PACKAGE from ..models.connection_detail import ConnectionDetail, ConnectionDetailSchema diff --git a/aries_cloudagent/protocols/connections/messages/connection_response.py b/aries_cloudagent/protocols/connections/v1_0/messages/connection_response.py similarity index 93% rename from aries_cloudagent/protocols/connections/messages/connection_response.py rename to aries_cloudagent/protocols/connections/v1_0/messages/connection_response.py index 6a9c0c5134..2c6f23dcbb 100644 --- a/aries_cloudagent/protocols/connections/messages/connection_response.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/connection_response.py @@ -2,7 +2,8 @@ from marshmallow import fields -from ....messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema + from ..message_types import CONNECTION_RESPONSE, PROTOCOL_PACKAGE from ..models.connection_detail import ConnectionDetail, ConnectionDetailSchema diff --git a/aries_cloudagent/protocols/connections/messages/problem_report.py b/aries_cloudagent/protocols/connections/v1_0/messages/problem_report.py similarity index 95% rename from aries_cloudagent/protocols/connections/messages/problem_report.py rename to aries_cloudagent/protocols/connections/v1_0/messages/problem_report.py index e5beef4407..dfd90cb46d 100644 --- a/aries_cloudagent/protocols/connections/messages/problem_report.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/problem_report.py @@ -3,7 +3,8 @@ from enum import Enum from marshmallow import fields, validate -from ....messaging.agent_message import AgentMessage, AgentMessageSchema +from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema + from ..message_types import PROBLEM_REPORT HANDLER_CLASS = "aries_cloudagent.messaging.problem_report.handler.ProblemReportHandler" diff --git a/aries_cloudagent/protocols/connections/models/__init__.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/__init__.py similarity index 100% rename from aries_cloudagent/protocols/connections/models/__init__.py rename to aries_cloudagent/protocols/connections/v1_0/messages/tests/__init__.py diff --git a/aries_cloudagent/protocols/connections/messages/tests/test_connection_invitation.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py similarity index 98% rename from aries_cloudagent/protocols/connections/messages/tests/test_connection_invitation.py rename to aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py index 12c25415cf..bac176ee16 100644 --- a/aries_cloudagent/protocols/connections/messages/tests/test_connection_invitation.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py @@ -1,6 +1,7 @@ from unittest import mock, TestCase -from .....messaging.models.base import BaseModelError +from aries_cloudagent.messaging.models.base import BaseModelError + from ...message_types import CONNECTION_INVITATION from ..connection_invitation import ConnectionInvitation diff --git a/aries_cloudagent/protocols/connections/messages/tests/test_connection_request.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py similarity index 95% rename from aries_cloudagent/protocols/connections/messages/tests/test_connection_request.py rename to aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py index 8dd70d1a7d..1f5d916193 100644 --- a/aries_cloudagent/protocols/connections/messages/tests/test_connection_request.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py @@ -2,7 +2,12 @@ from asynctest import TestCase as AsyncTestCase -from .....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service +from aries_cloudagent.connections.models.diddoc import ( + DIDDoc, + PublicKey, + PublicKeyType, + Service, +) from ...message_types import CONNECTION_REQUEST from ...models.connection_detail import ConnectionDetail @@ -109,8 +114,8 @@ async def test_make_model(self): async def test_make_model_conn_detail_interpolate_authn_service(self): did_doc_dict = self.make_did_doc().serialize() - del did_doc_dict['authentication'] - del did_doc_dict['service'] + del did_doc_dict["authentication"] + del did_doc_dict["service"] did_doc = DIDDoc.deserialize(did_doc_dict) connection_request = ConnectionRequest( diff --git a/aries_cloudagent/protocols/connections/messages/tests/test_connection_response.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py similarity index 94% rename from aries_cloudagent/protocols/connections/messages/tests/test_connection_response.py rename to aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py index 2febde357b..8be76b142a 100644 --- a/aries_cloudagent/protocols/connections/messages/tests/test_connection_response.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py @@ -2,8 +2,13 @@ from asynctest import TestCase as AsyncTestCase -from .....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service -from .....wallet.basic import BasicWallet +from aries_cloudagent.connections.models.diddoc import ( + DIDDoc, + PublicKey, + PublicKeyType, + Service, +) +from aries_cloudagent.wallet.basic import BasicWallet from ...message_types import CONNECTION_RESPONSE from ...models.connection_detail import ConnectionDetail diff --git a/aries_cloudagent/protocols/connections/messages/tests/test_problem_report.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_problem_report.py similarity index 89% rename from aries_cloudagent/protocols/connections/messages/tests/test_problem_report.py rename to aries_cloudagent/protocols/connections/v1_0/messages/tests/test_problem_report.py index c16f404cd2..16823df1b5 100644 --- a/aries_cloudagent/protocols/connections/messages/tests/test_problem_report.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_problem_report.py @@ -1,6 +1,7 @@ from unittest import mock, TestCase -from .....messaging.models.base import BaseModelError +from aries_cloudagent.messaging.models.base import BaseModelError + from ...message_types import PROBLEM_REPORT from ..problem_report import ProblemReport, ProblemReportReason diff --git a/aries_cloudagent/protocols/connections/tests/__init__.py b/aries_cloudagent/protocols/connections/v1_0/models/__init__.py similarity index 100% rename from aries_cloudagent/protocols/connections/tests/__init__.py rename to aries_cloudagent/protocols/connections/v1_0/models/__init__.py diff --git a/aries_cloudagent/protocols/connections/models/connection_detail.py b/aries_cloudagent/protocols/connections/v1_0/models/connection_detail.py similarity index 91% rename from aries_cloudagent/protocols/connections/models/connection_detail.py rename to aries_cloudagent/protocols/connections/v1_0/models/connection_detail.py index a7542ec878..2fd1c37b38 100644 --- a/aries_cloudagent/protocols/connections/models/connection_detail.py +++ b/aries_cloudagent/protocols/connections/v1_0/models/connection_detail.py @@ -2,9 +2,9 @@ from marshmallow import fields -from ....connections.models.diddoc import DIDDoc -from ....messaging.models.base import BaseModel, BaseModelSchema -from ....messaging.valid import INDY_DID +from aries_cloudagent.connections.models.diddoc import DIDDoc +from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema +from aries_cloudagent.messaging.valid import INDY_DID class DIDDocWrapper(fields.Field): diff --git a/aries_cloudagent/protocols/connections/routes.py b/aries_cloudagent/protocols/connections/v1_0/routes.py similarity index 98% rename from aries_cloudagent/protocols/connections/routes.py rename to aries_cloudagent/protocols/connections/v1_0/routes.py index 508d41f2fb..196e4ac69f 100644 --- a/aries_cloudagent/protocols/connections/routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/routes.py @@ -5,12 +5,12 @@ from marshmallow import fields, Schema -from ...connections.models.connection_record import ( +from aries_cloudagent.connections.models.connection_record import ( ConnectionRecord, ConnectionRecordSchema, ) -from ...messaging.valid import IndyDID, UUIDFour -from ...storage.error import StorageNotFoundError +from aries_cloudagent.messaging.valid import IndyDID, UUIDFour +from aries_cloudagent.storage.error import StorageNotFoundError from .manager import ConnectionManager from .messages.connection_invitation import ( diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/__init__.py b/aries_cloudagent/protocols/connections/v1_0/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aries_cloudagent/protocols/connections/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py similarity index 90% rename from aries_cloudagent/protocols/connections/tests/test_manager.py rename to aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index f17461ed00..1e70385271 100644 --- a/aries_cloudagent/protocols/connections/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -1,24 +1,29 @@ from asynctest import TestCase as AsyncTestCase from asynctest import mock as async_mock -from ....cache.base import BaseCache -from ....cache.basic import BasicCache -from ....config.base import InjectorError -from ....config.injection_context import InjectionContext -from ....connections.models.connection_record import ConnectionRecord -from ....connections.models.connection_target import ConnectionTarget -from ....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service -from ....ledger.base import BaseLedger -from ....messaging.responder import BaseResponder, MockResponder -from ....storage.base import BaseStorage -from ....storage.basic import BasicStorage -from ....storage.error import StorageNotFoundError -from ....transport.inbound.receipt import MessageReceipt -from ....wallet.base import BaseWallet, DIDInfo -from ....wallet.basic import BasicWallet -from ....wallet.error import WalletNotFoundError - -from ...routing.manager import RoutingManager +from aries_cloudagent.cache.base import BaseCache +from aries_cloudagent.cache.basic import BasicCache +from aries_cloudagent.config.base import InjectorError +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.connections.models.connection_target import ConnectionTarget +from aries_cloudagent.connections.models.diddoc import ( + DIDDoc, + PublicKey, + PublicKeyType, + Service, +) +from aries_cloudagent.ledger.base import BaseLedger +from aries_cloudagent.messaging.responder import BaseResponder, MockResponder +from aries_cloudagent.storage.base import BaseStorage +from aries_cloudagent.storage.basic import BasicStorage +from aries_cloudagent.storage.error import StorageNotFoundError +from aries_cloudagent.transport.inbound.receipt import MessageReceipt +from aries_cloudagent.wallet.base import BaseWallet, DIDInfo +from aries_cloudagent.wallet.basic import BasicWallet +from aries_cloudagent.wallet.error import WalletNotFoundError + +from aries_cloudagentrouting.manager import RoutingManager from ..manager import ConnectionManager, ConnectionManagerError from ..messages.connection_invitation import ConnectionInvitation @@ -43,17 +48,18 @@ def make_did_doc(self, did, verkey): ident = "1" pk_value = verkey pk = PublicKey( - did, ident, pk_value, PublicKeyType.ED25519_SIG_2018, controller, False, + did, ident, pk_value, PublicKeyType.ED25519_SIG_2018, controller, False ) doc.set(pk) recip_keys = [pk] router_keys = [] service = Service( - did, "indy", "IndyAgent", recip_keys, router_keys, self.test_endpoint, + did, "indy", "IndyAgent", recip_keys, router_keys, self.test_endpoint ) doc.set(service) return doc + class TestConnectionManager(AsyncTestCase, TestConfig): def setUp(self): self.storage = BasicStorage() @@ -77,7 +83,6 @@ def setUp(self): } ) - self.manager = ConnectionManager(self.context) self.test_conn_rec = ConnectionRecord( my_did=self.test_did, @@ -92,7 +97,7 @@ async def test_create_invitation_public_and_multi_use_fails(self): BaseWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( - self.test_did, self.test_verkey, None, + self.test_did, self.test_verkey, None ) with self.assertRaises(ConnectionManagerError): await self.manager.create_invitation(public=True, multi_use=True) @@ -133,11 +138,10 @@ async def test_create_invitation_public(self): BaseWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( - self.test_did, self.test_verkey, None, + self.test_did, self.test_verkey, None ) connect_record, connect_invite = await self.manager.create_invitation( - public=True, - my_endpoint="testendpoint" + public=True, my_endpoint="testendpoint" ) assert connect_record == None @@ -148,8 +152,7 @@ async def test_create_invitation_public_no_public_invites(self): with self.assertRaises(ConnectionManagerError): await self.manager.create_invitation( - public=True, - my_endpoint="testendpoint" + public=True, my_endpoint="testendpoint" ) async def test_create_invitation_public_no_public_did(self): @@ -161,8 +164,7 @@ async def test_create_invitation_public_no_public_did(self): mock_wallet_get_public_did.return_value = None with self.assertRaises(ConnectionManagerError): await self.manager.create_invitation( - public=True, - my_endpoint="testendpoint" + public=True, my_endpoint="testendpoint" ) async def test_create_invitation_multi_use(self): @@ -208,8 +210,8 @@ async def test_receive_invitation_no_auto_accept(self): ) invitee_record = await self.manager.receive_invitation( - connect_invite, - accept=ConnectionRecord.ACCEPT_MANUAL) + connect_invite, accept=ConnectionRecord.ACCEPT_MANUAL + ) assert invitee_record.state == ConnectionRecord.STATE_INVITATION async def test_receive_invitation_bad_invitation(self): @@ -217,7 +219,7 @@ async def test_receive_invitation_bad_invitation(self): ConnectionInvitation(), ConnectionInvitation( recipient_keys=["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"] - ) + ), ] for x_invite in x_invites: @@ -245,16 +247,13 @@ async def test_create_request_my_endpoint(self): their_role="Point of contact", alias="Bob", ), - my_endpoint="http://testendpoint.com/endpoint" + my_endpoint="http://testendpoint.com/endpoint", ) assert conn_req async def test_create_request_my_did(self): wallet = await self.context.inject(BaseWallet) - await wallet.create_local_did( - seed=None, - did=self.test_did - ) + await wallet.create_local_did(seed=None, did=self.test_did) conn_req = await self.manager.create_request( ConnectionRecord( initiator=ConnectionRecord.INITIATOR_EXTERNAL, @@ -277,10 +276,7 @@ async def test_receive_request_public_did(self): receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) wallet = await self.context.inject(BaseWallet) - await wallet.create_local_did( - seed=None, - did=self.test_did - ) + await wallet.create_local_did(seed=None, did=self.test_did) self.manager.context.update_settings({"public_invites": True}) with async_mock.patch.object( @@ -310,10 +306,7 @@ async def test_receive_request_public_did_no_did_doc(self): receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) wallet = await self.context.inject(BaseWallet) - await wallet.create_local_did( - seed=None, - did=self.test_did - ) + await wallet.create_local_did(seed=None, did=self.test_did) self.manager.context.update_settings({"public_invites": True}) with async_mock.patch.object( @@ -338,10 +331,7 @@ async def test_receive_request_public_did_wrong_did(self): receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) wallet = await self.context.inject(BaseWallet) - await wallet.create_local_did( - seed=None, - did=self.test_did - ) + await wallet.create_local_did(seed=None, did=self.test_did) self.manager.context.update_settings({"public_invites": True}) with async_mock.patch.object( @@ -366,10 +356,7 @@ async def test_receive_request_public_did_no_public_invites(self): receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) wallet = await self.context.inject(BaseWallet) - await wallet.create_local_did( - seed=None, - did=self.test_did - ) + await wallet.create_local_did(seed=None, did=self.test_did) self.manager.context.update_settings({"public_invites": False}) with async_mock.patch.object( @@ -394,10 +381,7 @@ async def test_receive_request_public_did_no_auto_accept(self): receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) wallet = await self.context.inject(BaseWallet) - await wallet.create_local_did( - seed=None, - did=self.test_did - ) + await wallet.create_local_did(seed=None, did=self.test_did) self.manager.context.update_settings( {"public_invites": True, "debug.auto_accept_requests": False} @@ -426,7 +410,7 @@ async def test_create_response_bad_state(self): their_label="Hello", their_role="Point of contact", alias="Bob", - state=ConnectionRecord.STATE_ERROR + state=ConnectionRecord.STATE_ERROR, ) ) @@ -448,9 +432,7 @@ async def test_accept_response_find_by_thread_id(self): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock() mock_conn_retrieve_by_req_id.return_value.did = self.test_target_did mock_conn_retrieve_by_req_id.return_value.did_doc = async_mock.MagicMock() - mock_conn_retrieve_by_req_id.return_value.did_doc.did = ( - self.test_target_did - ) + mock_conn_retrieve_by_req_id.return_value.did_doc.did = self.test_target_did mock_conn_retrieve_by_req_id.return_value.state = ( ConnectionRecord.STATE_RESPONSE ) @@ -481,9 +463,7 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel mock_conn_retrieve_by_did.return_value = async_mock.MagicMock() mock_conn_retrieve_by_did.return_value.did = self.test_target_did mock_conn_retrieve_by_did.return_value.did_doc = async_mock.MagicMock() - mock_conn_retrieve_by_did.return_value.did_doc.did = ( - self.test_target_did - ) + mock_conn_retrieve_by_did.return_value.did_doc.did = self.test_target_did mock_conn_retrieve_by_did.return_value.state = ( ConnectionRecord.STATE_RESPONSE ) @@ -556,9 +536,7 @@ async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock() mock_conn_retrieve_by_req_id.return_value.did = self.test_target_did mock_conn_retrieve_by_req_id.return_value.did_doc = async_mock.MagicMock() - mock_conn_retrieve_by_req_id.return_value.did_doc.did = ( - self.test_target_did - ) + mock_conn_retrieve_by_req_id.return_value.did_doc.did = self.test_target_did mock_conn_retrieve_by_req_id.return_value.state = ( ConnectionRecord.STATE_RESPONSE ) @@ -584,9 +562,7 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock() mock_conn_retrieve_by_req_id.return_value.did = self.test_target_did mock_conn_retrieve_by_req_id.return_value.did_doc = async_mock.MagicMock() - mock_conn_retrieve_by_req_id.return_value.did_doc.did = ( - self.test_target_did - ) + mock_conn_retrieve_by_req_id.return_value.did_doc.did = self.test_target_did mock_conn_retrieve_by_req_id.return_value.state = ( ConnectionRecord.STATE_RESPONSE ) @@ -639,8 +615,7 @@ async def test_find_connection_retrieve_by_did(self): ConnectionRecord, "retrieve_by_did", async_mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( - state=ConnectionRecord.STATE_RESPONSE, - save=async_mock.CoroutineMock() + state=ConnectionRecord.STATE_RESPONSE, save=async_mock.CoroutineMock() ) conn_rec = await self.manager.find_connection( @@ -659,8 +634,7 @@ async def test_find_connection_retrieve_by_invitation_key(self): ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.return_value = async_mock.MagicMock( - state=ConnectionRecord.STATE_RESPONSE, - save=async_mock.CoroutineMock() + state=ConnectionRecord.STATE_RESPONSE, save=async_mock.CoroutineMock() ) conn_rec = await self.manager.find_connection( @@ -675,8 +649,7 @@ async def test_find_connection_retrieve_by_did_inactive(self): ConnectionRecord, "retrieve_by_did", async_mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( - state=ConnectionRecord.STATE_INACTIVE, - save=async_mock.CoroutineMock() + state=ConnectionRecord.STATE_INACTIVE, save=async_mock.CoroutineMock() ) conn_rec = await self.manager.find_connection( @@ -768,7 +741,7 @@ async def test_resolve_inbound_connection(self): self.manager, "find_connection", async_mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.return_value = DIDInfo( - self.test_did, self.test_verkey, {"public": True}, + self.test_did, self.test_verkey, {"public": True} ) mock_mgr_find_conn.return_value = mock_conn @@ -815,9 +788,7 @@ async def test_resolve_inbound_connection_wallet_not_found_error(self): assert await self.manager.resolve_inbound_connection(receipt) async def test_create_did_document(self): - did_info = DIDInfo( - self.test_did, self.test_verkey, None, - ) + did_info = DIDInfo(self.test_did, self.test_verkey, None) mock_conn = async_mock.MagicMock() mock_conn.connection_id = "dummy" @@ -826,8 +797,7 @@ async def test_create_did_document(self): mock_conn.state = ConnectionRecord.STATE_ACTIVE did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) for i in range(2): # first cover store-record, then update-value await self.manager.store_did_document(did_doc) @@ -840,13 +810,11 @@ async def test_create_did_document(self): did_doc = await self.manager.create_did_document( did_info=did_info, inbound_connection_id="dummy", - svc_endpoints=[self.test_endpoint] + svc_endpoints=[self.test_endpoint], ) async def test_create_did_document_not_active(self): - did_info = DIDInfo( - self.test_did, self.test_verkey, None, - ) + did_info = DIDInfo(self.test_did, self.test_verkey, None) mock_conn = async_mock.MagicMock() mock_conn.connection_id = "dummy" @@ -863,13 +831,11 @@ async def test_create_did_document_not_active(self): await self.manager.create_did_document( did_info=did_info, inbound_connection_id="dummy", - svc_endpoints=[self.test_endpoint] + svc_endpoints=[self.test_endpoint], ) async def test_create_did_document_no_services(self): - did_info = DIDInfo( - self.test_did, self.test_verkey, None, - ) + did_info = DIDInfo(self.test_did, self.test_verkey, None) mock_conn = async_mock.MagicMock() mock_conn.connection_id = "dummy" @@ -878,8 +844,7 @@ async def test_create_did_document_no_services(self): mock_conn.state = ConnectionRecord.STATE_ACTIVE x_did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) x_did_doc._service = {} for i in range(2): # first cover store-record, then update-value @@ -894,13 +859,11 @@ async def test_create_did_document_no_services(self): await self.manager.create_did_document( did_info=did_info, inbound_connection_id="dummy", - svc_endpoints=[self.test_endpoint] + svc_endpoints=[self.test_endpoint], ) async def test_create_did_document_no_service_endpoint(self): - did_info = DIDInfo( - self.test_did, self.test_verkey, None, - ) + did_info = DIDInfo(self.test_did, self.test_verkey, None) mock_conn = async_mock.MagicMock() mock_conn.connection_id = "dummy" @@ -909,20 +872,11 @@ async def test_create_did_document_no_service_endpoint(self): mock_conn.state = ConnectionRecord.STATE_ACTIVE x_did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) x_did_doc._service = {} x_did_doc.set( - Service( - self.test_target_did, - "dummy", - "IndyAgent", - [], - [], - "", - 0 - ) + Service(self.test_target_did, "dummy", "IndyAgent", [], [], "", 0) ) for i in range(2): # first cover store-record, then update-value await self.manager.store_did_document(x_did_doc) @@ -936,13 +890,11 @@ async def test_create_did_document_no_service_endpoint(self): await self.manager.create_did_document( did_info=did_info, inbound_connection_id="dummy", - svc_endpoints=[self.test_endpoint] + svc_endpoints=[self.test_endpoint], ) async def test_create_did_document_no_service_recip_keys(self): - did_info = DIDInfo( - self.test_did, self.test_verkey, None, - ) + did_info = DIDInfo(self.test_did, self.test_verkey, None) mock_conn = async_mock.MagicMock() mock_conn.connection_id = "dummy" @@ -951,8 +903,7 @@ async def test_create_did_document_no_service_recip_keys(self): mock_conn.state = ConnectionRecord.STATE_ACTIVE x_did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) x_did_doc._service = {} x_did_doc.set( @@ -963,7 +914,7 @@ async def test_create_did_document_no_service_recip_keys(self): [], [], self.test_endpoint, - 0 + 0, ) ) for i in range(2): # first cover store-record, then update-value @@ -978,22 +929,18 @@ async def test_create_did_document_no_service_recip_keys(self): await self.manager.create_did_document( did_info=did_info, inbound_connection_id="dummy", - svc_endpoints=[self.test_endpoint] + svc_endpoints=[self.test_endpoint], ) async def test_did_key_storage(self): - did_info = DIDInfo( - self.test_did, self.test_verkey, None, - ) + did_info = DIDInfo(self.test_did, self.test_verkey, None) did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) await self.manager.add_key_for_did( - did=self.test_target_did, - key=self.test_target_verkey + did=self.test_target_did, key=self.test_target_verkey ) did = await self.manager.find_did_for_key(key=self.test_target_verkey) @@ -1007,8 +954,7 @@ async def test_get_connection_targets_invitation_no_did(self): ) did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) await self.manager.store_did_document(did_doc) @@ -1031,8 +977,7 @@ async def test_get_connection_targets_invitation_no_did(self): ) targets = await self.manager.get_connection_targets( - connection_id=None, - connection=mock_conn, + connection_id=None, connection=mock_conn ) assert len(targets) == 1 target = targets[0] @@ -1045,8 +990,7 @@ async def test_get_connection_targets_invitation_no_did(self): # Next pass: exercise cache targets = await self.manager.get_connection_targets( - connection_id=None, - connection=mock_conn, + connection_id=None, connection=mock_conn ) assert len(targets) == 1 target = targets[0] @@ -1064,8 +1008,7 @@ async def test_get_connection_targets_retrieve_connection(self): ) did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) await self.manager.store_did_document(did_doc) @@ -1095,8 +1038,7 @@ async def test_get_connection_targets_retrieve_connection(self): mock_conn_rec_retrieve_by_id.return_value = mock_conn mock_conn_target_ser.return_value = {"serialized": "value"} targets = await self.manager.get_connection_targets( - connection_id="dummy", - connection=None, + connection_id="dummy", connection=None ) assert len(targets) == 1 target = targets[0] @@ -1105,7 +1047,9 @@ async def test_get_connection_targets_retrieve_connection(self): assert target.label == mock_invite.label assert target.recipient_keys == mock_invite.recipient_keys assert target.routing_keys == mock_invite.routing_keys - assert target.sender_key == (await wallet.get_local_did(self.test_did)).verkey + assert ( + target.sender_key == (await wallet.get_local_did(self.test_did)).verkey + ) async def test_get_connection_targets_no_cache(self): self.context.injector.clear_binding(BaseCache) @@ -1115,8 +1059,7 @@ async def test_get_connection_targets_no_cache(self): ) did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) await self.manager.store_did_document(did_doc) @@ -1138,8 +1081,7 @@ async def test_get_connection_targets_no_cache(self): ) targets = await self.manager.get_connection_targets( - connection_id=None, - connection=mock_conn, + connection_id=None, connection=mock_conn ) assert len(targets) == 1 target = targets[0] @@ -1238,10 +1180,7 @@ async def test_fetch_connection_targets_conn_initiator_multi_their_did(self): seed=self.test_seed, did=self.test_did, metadata=None ) - did_doc = self.make_did_doc( - did=self.test_did, - verkey=self.test_verkey - ) + did_doc = self.make_did_doc(did=self.test_did, verkey=self.test_verkey) await self.manager.store_did_document(did_doc) mock_conn = async_mock.MagicMock() @@ -1269,8 +1208,7 @@ async def test_diddoc_connection_targets_diddoc_underspecified(self): self.manager.diddoc_connection_targets(x_did_doc, self.test_verkey) x_did_doc = self.make_did_doc( - did=self.test_target_did, - verkey=self.test_target_verkey + did=self.test_target_did, verkey=self.test_target_verkey ) x_did_doc._service = {} with self.assertRaises(ConnectionManagerError): @@ -1288,7 +1226,7 @@ async def test_establish_inbound(self): mock_conn.save = async_mock.CoroutineMock() inbound_conn_id = "dummy" - + with async_mock.patch.object( ConnectionRecord, "retrieve_by_id", async_mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( @@ -1297,9 +1235,7 @@ async def test_establish_inbound(self): mock_conn_rec_retrieve_by_id.return_value = mock_conn state = await self.manager.establish_inbound( - mock_conn, - inbound_conn_id, - None + mock_conn, inbound_conn_id, None ) assert state == ConnectionRecord.ROUTING_STATE_REQUEST @@ -1315,7 +1251,7 @@ async def test_establish_inbound_conn_rec_no_my_did(self): mock_conn.save = async_mock.CoroutineMock() inbound_conn_id = "dummy" - + with async_mock.patch.object( ConnectionRecord, "retrieve_by_id", async_mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( @@ -1324,9 +1260,7 @@ async def test_establish_inbound_conn_rec_no_my_did(self): mock_conn_rec_retrieve_by_id.return_value = mock_conn state = await self.manager.establish_inbound( - mock_conn, - inbound_conn_id, - None + mock_conn, inbound_conn_id, None ) assert state == ConnectionRecord.ROUTING_STATE_REQUEST @@ -1342,7 +1276,7 @@ async def test_establish_inbound_no_conn_record(self): mock_conn.save = async_mock.CoroutineMock() inbound_conn_id = "dummy" - + with async_mock.patch.object( ConnectionRecord, "retrieve_by_id", async_mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( @@ -1351,11 +1285,7 @@ async def test_establish_inbound_no_conn_record(self): mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() with self.assertRaises(ConnectionManagerError): - await self.manager.establish_inbound( - mock_conn, - inbound_conn_id, - None - ) + await self.manager.establish_inbound(mock_conn, inbound_conn_id, None) async def test_establish_inbound_router_not_ready(self): wallet: BaseWallet = await self.context.inject(BaseWallet) @@ -1369,7 +1299,7 @@ async def test_establish_inbound_router_not_ready(self): mock_conn.save = async_mock.CoroutineMock() inbound_conn_id = "dummy" - + with async_mock.patch.object( ConnectionRecord, "retrieve_by_id", async_mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( @@ -1378,11 +1308,7 @@ async def test_establish_inbound_router_not_ready(self): mock_conn_rec_retrieve_by_id.return_value = mock_conn with self.assertRaises(ConnectionManagerError): - await self.manager.establish_inbound( - mock_conn, - inbound_conn_id, - None - ) + await self.manager.establish_inbound(mock_conn, inbound_conn_id, None) async def test_update_inbound(self): with async_mock.patch.object( @@ -1408,9 +1334,7 @@ async def test_update_inbound(self): verkey=self.test_verkey ) await self.manager.update_inbound( - "dummy", - self.test_verkey, - ConnectionRecord.STATE_ACTIVE + "dummy", self.test_verkey, ConnectionRecord.STATE_ACTIVE ) mock_conn_rec_query.return_value[1].save.assert_called_once_with( self.context diff --git a/aries_cloudagent/protocols/connections/tests/test_routes.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py similarity index 98% rename from aries_cloudagent/protocols/connections/tests/test_routes.py rename to aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py index 43d773f5ec..7bab9bb169 100644 --- a/aries_cloudagent/protocols/connections/tests/test_routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py @@ -3,11 +3,12 @@ from aiohttp import web as aio_web -from ....config.injection_context import InjectionContext -from ....connections.models.connection_record import ConnectionRecord -from ....storage.error import StorageNotFoundError -from ....holder.base import BaseHolder -from ....messaging.request_context import RequestContext +from aries_cloudagent.config.injection_context import InjectionContext +from aries_cloudagent.connections.models.connection_record import ConnectionRecord +from aries_cloudagent.storage.error import StorageNotFoundError +from aries_cloudagent.holder.base import BaseHolder +from aries_cloudagent.messaging.request_context import RequestContext + from .. import routes as test_module From aac49368380ee86eef0b163278593c7dd1a92bf4 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Wed, 25 Mar 2020 16:08:09 -0700 Subject: [PATCH 011/103] Refactor references to connections Signed-off-by: Nicholas Rempel --- .../connections/models/connection_record.py | 15 +++++++-------- aries_cloudagent/core/conductor.py | 9 +++++++-- aries_cloudagent/core/dispatcher.py | 3 ++- aries_cloudagent/core/tests/test_conductor.py | 3 ++- .../connections/v1_0/tests/test_manager.py | 2 +- .../handlers/forward_invitation_handler.py | 3 ++- .../handlers/invitation_request_handler.py | 4 +++- .../tests/test_forward_invitation_handler.py | 3 ++- .../handlers/tests/test_invitation_handler.py | 3 ++- .../tests/test_invitation_request_handler.py | 3 ++- .../introduction/messages/forward_invitation.py | 3 ++- .../protocols/introduction/messages/invitation.py | 3 ++- .../messages/tests/test_forward_invitation.py | 3 ++- .../messages/tests/test_invitation.py | 3 ++- .../protocols/introduction/tests/test_service.py | 3 ++- .../handlers/route_update_response_handler.py | 3 ++- 16 files changed, 42 insertions(+), 24 deletions(-) diff --git a/aries_cloudagent/connections/models/connection_record.py b/aries_cloudagent/connections/models/connection_record.py index ad84959915..882d293320 100644 --- a/aries_cloudagent/connections/models/connection_record.py +++ b/aries_cloudagent/connections/models/connection_record.py @@ -6,8 +6,12 @@ from ...config.injection_context import InjectionContext from ...messaging.models.base_record import BaseRecord, BaseRecordSchema from ...messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY, UUIDFour -from ...protocols.connections.messages.connection_invitation import ConnectionInvitation -from ...protocols.connections.messages.connection_request import ConnectionRequest + +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...protocols.connections.v1_0.messages.connection_invitation import ( + ConnectionInvitation, +) +from ...protocols.connections.v1_0.messages.connection_request import ConnectionRequest from ...storage.base import BaseStorage from ...storage.record import StorageRecord @@ -24,12 +28,7 @@ class Meta: WEBHOOK_TOPIC = "connections" LOG_STATE_FLAG = "debug.connections" CACHE_ENABLED = True - TAG_NAMES = { - "my_did", - "their_did", - "request_id", - "invitation_key", - } + TAG_NAMES = {"my_did", "their_did", "request_id", "invitation_key"} RECORD_TYPE = "connection" RECORD_TYPE_INVITATION = "connection_invitation" diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index 152c8b98a7..46ec0899cf 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -19,7 +19,12 @@ from ..config.logging import LoggingConfigurator from ..config.wallet import wallet_config from ..messaging.responder import BaseResponder -from ..protocols.connections.manager import ConnectionManager, ConnectionManagerError + +# FIXME: We shouldn't rely on a hardcoded message version here. +from ..protocols.connections.v1_0.manager import ( + ConnectionManager, + ConnectionManagerError, +) from ..transport.inbound.manager import InboundTransportManager from ..transport.inbound.message import InboundMessage from ..transport.outbound.base import OutboundDeliveryError @@ -73,7 +78,7 @@ async def setup(self): # Register all inbound transports self.inbound_transport_manager = InboundTransportManager( - context, self.inbound_message_router, self.handle_not_returned, + context, self.inbound_message_router, self.handle_not_returned ) await self.inbound_transport_manager.setup() diff --git a/aries_cloudagent/core/dispatcher.py b/aries_cloudagent/core/dispatcher.py index be6cceb248..90521bb223 100644 --- a/aries_cloudagent/core/dispatcher.py +++ b/aries_cloudagent/core/dispatcher.py @@ -20,7 +20,8 @@ from ..messaging.request_context import RequestContext from ..messaging.responder import BaseResponder from ..messaging.util import datetime_now -from ..protocols.connections.manager import ConnectionManager +# FIXME: We shouldn't rely on a hardcoded message version here. +from ..protocols.connections.v1_0.manager import ConnectionManager from ..protocols.problem_report.message import ProblemReport from ..transport.inbound.message import InboundMessage from ..transport.outbound.message import OutboundMessage diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index 1c395c05fd..d7d7f830c9 100644 --- a/aries_cloudagent/core/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -16,7 +16,8 @@ Service, ) from ...core.protocol_registry import ProtocolRegistry -from ...protocols.connections.manager import ConnectionManager +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...protocols.connections.v1_0.manager import ConnectionManager from ...storage.base import BaseStorage from ...storage.basic import BasicStorage from ...transport.inbound.base import InboundTransportConfiguration diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index 1e70385271..956dfa2a70 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -23,7 +23,7 @@ from aries_cloudagent.wallet.basic import BasicWallet from aries_cloudagent.wallet.error import WalletNotFoundError -from aries_cloudagentrouting.manager import RoutingManager +from ....routing.manager import RoutingManager from ..manager import ConnectionManager, ConnectionManagerError from ..messages.connection_invitation import ConnectionInvitation diff --git a/aries_cloudagent/protocols/introduction/handlers/forward_invitation_handler.py b/aries_cloudagent/protocols/introduction/handlers/forward_invitation_handler.py index 9c359f26f3..bf4713595a 100644 --- a/aries_cloudagent/protocols/introduction/handlers/forward_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/handlers/forward_invitation_handler.py @@ -7,7 +7,8 @@ RequestContext, ) -from ...connections.manager import ConnectionManager +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...connections.v1_0.manager import ConnectionManager from ..messages.forward_invitation import ForwardInvitation diff --git a/aries_cloudagent/protocols/introduction/handlers/invitation_request_handler.py b/aries_cloudagent/protocols/introduction/handlers/invitation_request_handler.py index 69f84701c4..2b55514b96 100644 --- a/aries_cloudagent/protocols/introduction/handlers/invitation_request_handler.py +++ b/aries_cloudagent/protocols/introduction/handlers/invitation_request_handler.py @@ -6,7 +6,9 @@ HandlerException, RequestContext, ) -from ...connections.manager import ConnectionManager + +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...connections.v1_0.manager import ConnectionManager from ..messages.invitation_request import InvitationRequest from ..messages.invitation import Invitation diff --git a/aries_cloudagent/protocols/introduction/handlers/tests/test_forward_invitation_handler.py b/aries_cloudagent/protocols/introduction/handlers/tests/test_forward_invitation_handler.py index 8b2826b80b..8977e0bebd 100644 --- a/aries_cloudagent/protocols/introduction/handlers/tests/test_forward_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/handlers/tests/test_forward_invitation_handler.py @@ -7,7 +7,8 @@ from .....messaging.request_context import RequestContext from .....messaging.responder import MockResponder -from ....connections.messages.connection_invitation import ConnectionInvitation +# FIXME: We shouldn't rely on a hardcoded message version here. +from ....connections.v1_0.messages.connection_invitation import ConnectionInvitation from ...messages.forward_invitation import ForwardInvitation diff --git a/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_handler.py b/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_handler.py index 2011898706..9d78c5ed4e 100644 --- a/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_handler.py @@ -9,7 +9,8 @@ from .....storage.base import BaseStorage from .....storage.basic import BasicStorage -from ....connections.messages.connection_invitation import ConnectionInvitation +# FIXME: We shouldn't rely on a hardcoded message version here. +from ....connections.v1_0.messages.connection_invitation import ConnectionInvitation from ...messages.invitation import Invitation from ...messages.invitation_request import InvitationRequest diff --git a/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_request_handler.py b/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_request_handler.py index 219794d7b6..346aaefb7d 100644 --- a/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_request_handler.py +++ b/aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_request_handler.py @@ -7,7 +7,8 @@ from .....messaging.request_context import RequestContext from .....messaging.responder import MockResponder -from ....connections.messages.connection_invitation import ConnectionInvitation +# FIXME: We shouldn't rely on a hardcoded message version here. +from ....connections.v1_0.messages.connection_invitation import ConnectionInvitation from ...messages.invitation import Invitation from ...messages.invitation_request import InvitationRequest diff --git a/aries_cloudagent/protocols/introduction/messages/forward_invitation.py b/aries_cloudagent/protocols/introduction/messages/forward_invitation.py index e07dddc10b..9cdaaf3b27 100644 --- a/aries_cloudagent/protocols/introduction/messages/forward_invitation.py +++ b/aries_cloudagent/protocols/introduction/messages/forward_invitation.py @@ -4,7 +4,8 @@ from ....messaging.agent_message import AgentMessage, AgentMessageSchema -from ...connections.messages.connection_invitation import ( +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...connections.v1_0.messages.connection_invitation import ( ConnectionInvitation, ConnectionInvitationSchema, ) diff --git a/aries_cloudagent/protocols/introduction/messages/invitation.py b/aries_cloudagent/protocols/introduction/messages/invitation.py index 2795849810..6f7da634fe 100644 --- a/aries_cloudagent/protocols/introduction/messages/invitation.py +++ b/aries_cloudagent/protocols/introduction/messages/invitation.py @@ -4,7 +4,8 @@ from ....messaging.agent_message import AgentMessage, AgentMessageSchema -from ...connections.messages.connection_invitation import ( +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...connections.v1_0.messages.connection_invitation import ( ConnectionInvitation, ConnectionInvitationSchema, ) diff --git a/aries_cloudagent/protocols/introduction/messages/tests/test_forward_invitation.py b/aries_cloudagent/protocols/introduction/messages/tests/test_forward_invitation.py index d02e67503f..4eb1334292 100644 --- a/aries_cloudagent/protocols/introduction/messages/tests/test_forward_invitation.py +++ b/aries_cloudagent/protocols/introduction/messages/tests/test_forward_invitation.py @@ -1,7 +1,8 @@ from unittest import mock, TestCase from asynctest import TestCase as AsyncTestCase -from ....connections.messages.connection_invitation import ConnectionInvitation +# FIXME: We shouldn't rely on a hardcoded message version here. +from ....connections.v1_0.messages.connection_invitation import ConnectionInvitation from ...message_types import FORWARD_INVITATION, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/introduction/messages/tests/test_invitation.py b/aries_cloudagent/protocols/introduction/messages/tests/test_invitation.py index 0c3538e560..44529f3505 100644 --- a/aries_cloudagent/protocols/introduction/messages/tests/test_invitation.py +++ b/aries_cloudagent/protocols/introduction/messages/tests/test_invitation.py @@ -1,7 +1,8 @@ from unittest import mock, TestCase from asynctest import TestCase as AsyncTestCase -from ....connections.messages.connection_invitation import ConnectionInvitation +# FIXME: We shouldn't rely on a hardcoded message version here. +from ....connections.v1_0.messages.connection_invitation import ConnectionInvitation from ..invitation import Invitation from ...message_types import INVITATION, PROTOCOL_PACKAGE diff --git a/aries_cloudagent/protocols/introduction/tests/test_service.py b/aries_cloudagent/protocols/introduction/tests/test_service.py index 7600bfd5a4..1af20bce99 100644 --- a/aries_cloudagent/protocols/introduction/tests/test_service.py +++ b/aries_cloudagent/protocols/introduction/tests/test_service.py @@ -9,7 +9,8 @@ from ....storage.basic import BasicStorage from ....storage.error import StorageNotFoundError -from ...connections.messages.connection_invitation import ConnectionInvitation +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...connections.v1_0.messages.connection_invitation import ConnectionInvitation from .. import base_service, demo_service diff --git a/aries_cloudagent/protocols/routing/handlers/route_update_response_handler.py b/aries_cloudagent/protocols/routing/handlers/route_update_response_handler.py index 6ce1e7c85b..23b88fc9c1 100644 --- a/aries_cloudagent/protocols/routing/handlers/route_update_response_handler.py +++ b/aries_cloudagent/protocols/routing/handlers/route_update_response_handler.py @@ -8,7 +8,8 @@ RequestContext, ) -from ...connections.manager import ConnectionManager +# FIXME: We shouldn't rely on a hardcoded message version here. +from ...connections.v1_0.manager import ConnectionManager from ..messages.route_update_response import RouteUpdateResponse from ..models.route_update import RouteUpdate From 6287168875128c62ca7455374f417b0fcf3141b9 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Wed, 25 Mar 2020 16:08:50 -0700 Subject: [PATCH 012/103] reformat code Signed-off-by: Nicholas Rempel --- aries_cloudagent/config/argparse.py | 30 +- aries_cloudagent/core/dispatcher.py | 1 + aries_cloudagent/core/tests/test_conductor.py | 2 +- aries_cloudagent/holder/tests/test_indy.py | 1 - aries_cloudagent/ledger/provider.py | 5 +- .../ledger/tests/test_provider.py | 24 +- aries_cloudagent/ledger/tests/test_routes.py | 6 +- aries_cloudagent/messaging/ack/message.py | 6 +- .../messaging/decorators/attach_decorator.py | 90 ++--- .../decorators/localization_decorator.py | 14 +- .../decorators/please_ack_decorator.py | 12 +- .../decorators/signature_decorator.py | 14 +- .../decorators/tests/test_attach_decorator.py | 71 ++-- .../tests/test_please_ack_decorator.py | 5 +- .../messaging/decorators/thread_decorator.py | 5 +- .../messaging/decorators/timing_decorator.py | 16 +- .../decorators/transport_decorator.py | 4 +- aries_cloudagent/messaging/responder.py | 4 +- aries_cloudagent/messaging/tests/test_util.py | 65 ++-- .../messaging/tests/test_valid.py | 66 ++-- aries_cloudagent/messaging/valid.py | 89 ++--- .../v1_0/handlers/tests/test_menu_handler.py | 2 +- .../tests/test_menu_request_handler.py | 12 +- .../handlers/tests/test_perform_handler.py | 8 +- .../actionmenu/v1_0/tests/test_controller.py | 7 +- .../actionmenu/v1_0/tests/test_routes.py | 1 - .../actionmenu/v1_0/tests/test_service.py | 11 +- .../actionmenu/v1_0/tests/test_util.py | 51 ++- .../handlers/connection_invitation_handler.py | 6 +- .../handlers/connection_request_handler.py | 6 +- .../handlers/connection_response_handler.py | 6 +- .../protocols/connections/v1_0/manager.py | 17 +- .../v1_0/messages/problem_report.py | 2 +- .../tests/test_connection_invitation.py | 7 +- .../messages/tests/test_connection_request.py | 1 - .../protocols/connections/v1_0/routes.py | 31 +- .../connections/v1_0/tests/test_routes.py | 19 +- .../protocols/credentials/routes.py | 27 +- .../credentials/tests/test_routes.py | 4 +- .../protocols/discovery/tests/test_routes.py | 15 +- .../protocols/introduction/demo_service.py | 3 +- .../tests/test_forward_invitation_handler.py | 4 +- .../handlers/tests/test_invitation_handler.py | 2 +- .../tests/test_invitation_request_handler.py | 5 +- .../introduction/tests/test_service.py | 44 +-- .../v1_0/handlers/credential_issue_handler.py | 3 +- .../handlers/credential_request_handler.py | 6 +- .../tests/test_credential_request_handler.py | 9 +- .../tests/test_credential_proposal.py | 6 +- .../handlers/presentation_request_handler.py | 4 +- .../test_presentation_request_handler.py | 337 ++++++------------ .../messages/inner/presentation_preview.py | 28 +- .../inner/tests/test_presentation_preview.py | 233 +++++------- .../messages/tests/test_presentation_ack.py | 14 +- .../protocols/present_proof/v1_0/routes.py | 2 +- .../protocols/present_proof/v1_0/util/indy.py | 40 +-- .../present_proof/v1_0/util/predicate.py | 42 ++- .../protocols/presentations/routes.py | 2 +- .../protocols/problem_report/message_types.py | 2 +- .../tests/test_query_update_handlers.py | 79 ++-- .../routing/tests/test_routing_manager.py | 64 ++-- .../tests/test_issuer_revocation_record.py | 1 - .../models/tests/test_revocation_registry.py | 29 +- .../revocation/tests/test_indy.py | 43 +-- .../revocation/tests/test_routes.py | 97 ++--- aries_cloudagent/transport/inbound/manager.py | 4 +- .../transport/inbound/tests/test_session.py | 6 +- aries_cloudagent/utils/http.py | 20 +- aries_cloudagent/verifier/tests/test_indy.py | 1 - aries_cloudagent/wallet/plugin.py | 4 +- aries_cloudagent/wallet/routes.py | 36 +- .../wallet/tests/test_indy_wallet.py | 8 +- aries_cloudagent/wallet/tests/test_util.py | 3 +- demo/runners/alice.py | 28 +- demo/runners/support/agent.py | 42 ++- docs/conf.py | 6 +- 76 files changed, 799 insertions(+), 1221 deletions(-) diff --git a/aries_cloudagent/config/argparse.py b/aries_cloudagent/config/argparse.py index 7a17e81729..7d22d50776 100644 --- a/aries_cloudagent/config/argparse.py +++ b/aries_cloudagent/config/argparse.py @@ -178,7 +178,7 @@ def add_arguments(self, parser: ArgumentParser): action="store_true", help="Enables a remote debugging service that can be accessed\ using ptvsd for Visual Studio Code. The framework will wait\ - for the debugger to connect at start-up. Default: false." + for the debugger to connect at start-up. Default: false.", ) parser.add_argument( "--debug-seed", @@ -215,30 +215,30 @@ def add_arguments(self, parser: ArgumentParser): dest="invite_role", type=str, metavar="", - help="Specify the role of the generated invitation." + help="Specify the role of the generated invitation.", ) parser.add_argument( "--invite-label", dest="invite_label", type=str, metavar="