Skip to content

Commit

Permalink
🎨 Apply formatting (#448)
Browse files Browse the repository at this point in the history
* 🎨 apply isort import organisation

Signed-off-by: ff137 <ff137@proton.me>

* 🎨 apply black formatting

Signed-off-by: ff137 <ff137@proton.me>

---------

Signed-off-by: ff137 <ff137@proton.me>
  • Loading branch information
ff137 committed May 14, 2024
1 parent d957b01 commit 3725a70
Show file tree
Hide file tree
Showing 88 changed files with 572 additions and 550 deletions.
11 changes: 6 additions & 5 deletions basicmessage_storage/basicmessage_storage/v1_0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import re

from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.core.event_bus import EventBus, Event
from aries_cloudagent.core.event_bus import Event, EventBus
from aries_cloudagent.core.profile import Profile
from aries_cloudagent.core.protocol_registry import ProtocolRegistry
from aries_cloudagent.multitenant.admin.routes import (
ACAPY_LIFECYCLE_CONFIG_FLAG_ARGS_MAP,
)
from .models import BasicMessageRecord

from .config import get_config
from .models import BasicMessageRecord

LOGGER = logging.getLogger(__name__)

Expand All @@ -29,9 +30,9 @@ async def setup(context: InjectionContext):
# acapy should create a separate map for plugin settings
# add subwallet config, acapy will accept any child under basicmessage-storage
# but will get filtered with `.config.get_config`
ACAPY_LIFECYCLE_CONFIG_FLAG_ARGS_MAP[
"basicmessage-storage"
] = "basicmessage_storage"
ACAPY_LIFECYCLE_CONFIG_FLAG_ARGS_MAP["basicmessage-storage"] = (
"basicmessage_storage"
)

event_bus.subscribe(BASIC_MESSAGE_EVENT_PATTERN, basic_message_event_handler)
LOGGER.info("< basicmessage_storage plugin setup.")
Expand Down
2 changes: 1 addition & 1 deletion basicmessage_storage/basicmessage_storage/v1_0/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Configuration classes for multitenant_provider."""

import logging
from typing import Any, Mapping

from mergedeep import merge
from pydantic import BaseModel


LOGGER = logging.getLogger(__name__)


Expand Down
5 changes: 2 additions & 3 deletions basicmessage_storage/basicmessage_storage/v1_0/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Basic Messages Storage Model classes and schemas."""

from aries_cloudagent.core.profile import ProfileSession
from aries_cloudagent.messaging.models.base_record import BaseRecord, BaseRecordSchema
from aries_cloudagent.messaging.valid import (
INDY_ISO8601_DATETIME_EXAMPLE,
INDY_ISO8601_DATETIME_VALIDATE,
)
from marshmallow import fields
from aries_cloudagent.storage.base import BaseStorage
from marshmallow import fields


class BasicMessageRecord(BaseRecord):
Expand Down Expand Up @@ -63,7 +64,6 @@ def record_tags(self) -> dict:
"""Get tags for record."""
return {"connection_id": self.connection_id, "message_id": self.message_id}


async def delete_record(self, session: ProfileSession):
"""Perform connection record deletion actions.
Expand All @@ -81,7 +81,6 @@ async def delete_record(self, session: ProfileSession):
{"message_id": self.message_id},
)


@classmethod
async def retrieve_by_message_id(
cls, session: ProfileSession, message_id: str
Expand Down
12 changes: 6 additions & 6 deletions basicmessage_storage/basicmessage_storage/v1_0/routes.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
"""Basic Messages Storage API Routes."""

import functools
import logging
import uuid

from aiohttp import web
from aiohttp_apispec import (
docs,
response_schema,
querystring_schema,
match_info_schema,
querystring_schema,
request_schema,
response_schema,
)
from aries_cloudagent.admin.request_context import AdminRequestContext
from aries_cloudagent.messaging.models.base import BaseModelError
from aries_cloudagent.messaging.models.openapi import OpenAPISchema
from aries_cloudagent.messaging.util import time_now, str_to_epoch
from aries_cloudagent.messaging.util import str_to_epoch, time_now
from aries_cloudagent.messaging.valid import UUID4_EXAMPLE
from aries_cloudagent.multitenant.error import WalletKeyMissingError
from aries_cloudagent.protocols.basicmessage.v1_0.message_types import SPEC_URI
from aries_cloudagent.protocols.basicmessage.v1_0.routes import (
BasicConnIdMatchInfoSchema,
SendMessageSchema,
BasicMessageModuleResponseSchema,
SendMessageSchema,
connections_send_message,
)
from aries_cloudagent.storage.error import StorageError, StorageNotFoundError
from marshmallow import fields, validate

from .models import BasicMessageRecord, BasicMessageRecordSchema
from .config import get_config

from .models import BasicMessageRecord, BasicMessageRecordSchema

LOGGER = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asynctest
import basicmessage_storage.v1_0 as test_module

from aries_cloudagent.core.event_bus import Event
from aries_cloudagent.core.in_memory import InMemoryProfile
from asynctest import TestCase as AsyncTestCase
from asynctest import mock as async_mock
from pydantic import BaseModel

import basicmessage_storage.v1_0 as test_module

from .. import basic_message_event_handler, setup
from ..models import BasicMessageRecord

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

# pylint: disable=redefined-outer-name

import pytest
import time

from . import Agent, BOB, ALICE
import pytest

from . import ALICE, BOB, Agent


@pytest.fixture(scope="session")
Expand Down
6 changes: 4 additions & 2 deletions connection_update/connection_update/v1_0/routes.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
"""v1.0 connection update protocol routes."""

import functools
import logging

from aiohttp import web
from aiohttp_apispec import docs, match_info_schema, response_schema, request_schema
from aiohttp_apispec import docs, match_info_schema, request_schema, response_schema
from aries_cloudagent.admin.request_context import AdminRequestContext
from aries_cloudagent.connections.models.conn_record import ConnRecord, ConnRecordSchema
from aries_cloudagent.messaging.models.base import BaseModelError
from aries_cloudagent.messaging.models.openapi import OpenAPISchema
from aries_cloudagent.protocols.connections.v1_0.routes import (
ConnectionsConnIdMatchInfoSchema,
)
from aries_cloudagent.storage.error import StorageNotFoundError, StorageError
from aries_cloudagent.storage.error import StorageError, StorageNotFoundError
from marshmallow import fields

LOGGER = logging.getLogger(__name__)


def error_handler(func):
"""Handle connection update errors."""

@functools.wraps(func)
async def wrapper(request):
try:
Expand Down
10 changes: 4 additions & 6 deletions connection_update/connection_update/v1_0/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ async def setUp(self) -> None:
@asynctest.patch.object(ConnRecord, "retrieve_by_id")
async def test_connections_update_saves_with_alias_from_body(self, mock_retrieve):
self.request.json = async_mock.CoroutineMock()
self.request.json.return_value = {
'alias': 'test-alias'

}
self.request.json.return_value = {"alias": "test-alias"}
self.request.match_info = {"conn_id": self.test_conn_id}

mock_retrieve.return_value = async_mock.CoroutineMock(
save=async_mock.CoroutineMock(), alias="", serialize=lambda: {})
save=async_mock.CoroutineMock(), alias="", serialize=lambda: {}
)

await test_module.connections_update(self.request)

mock_retrieve.return_value.save.assert_called
assert mock_retrieve.return_value.alias == 'test-alias'
assert mock_retrieve.return_value.alias == "test-alias"

async def test_register(self):
mock_app = async_mock.MagicMock()
Expand Down
14 changes: 7 additions & 7 deletions connection_update/integration/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ def get(agent: str, path: str, **kwargs):
"""Get."""
return requests.get(f"{agent}{path}", **kwargs)


def post(agent: str, path: str, **kwargs):
"""Post."""
return requests.post(f"{agent}{path}", **kwargs)


def put(agent: str, path: str, **kwargs):
"""Put."""
return requests.put(f"{agent}{path}", **kwargs)
Expand Down Expand Up @@ -79,7 +81,7 @@ def accept_invite(self, connection_id: str):
self.url,
f"/connections/{connection_id}/accept-invitation",
)

@unwrap_json_response
@fail_if_not_ok("Failed to send basic message")
def connections_update(self, connection_id, alias):
Expand All @@ -89,7 +91,7 @@ def connections_update(self, connection_id, alias):
f"/connections/{connection_id}",
json={"alias": alias},
)

@unwrap_json_response
@fail_if_not_ok("Failed to send basic message")
def get_connection(self, connection_id):
Expand Down Expand Up @@ -120,15 +122,13 @@ def post(
wrapped_post = unwrap_json_response(wrapped_post)

return wrapped_post(self.url, path, **kwargs)

def put(
self, path: str, return_json: bool = True, fail_with: str = None, **kwargs
):

def put(self, path: str, return_json: bool = True, fail_with: str = None, **kwargs):
"""Do get to agent endpoint."""
wrapped_put = put
if fail_with:
wrapped_put = fail_if_not_ok(fail_with)(wrapped_put)
if return_json:
wrapped_put = unwrap_json_response(wrapped_put)

return wrapped_put(self.url, path, **kwargs)
return wrapped_put(self.url, path, **kwargs)
13 changes: 7 additions & 6 deletions connection_update/integration/tests/test_connection_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

# pylint: disable=redefined-outer-name

import pytest
import time

from . import Agent, BOB, ALICE
import pytest

from . import ALICE, BOB, Agent


@pytest.fixture(scope="session")
Expand All @@ -27,14 +28,14 @@ def established_connection(bob, alice):
resp = alice.receive_invite(invite, auto_accept="true")
yield resp["connection_id"]


def test_send_message(bob, alice, established_connection):
# make sure connection is active...
time.sleep(2)

test_alias = 'test-alias'
test_alias = "test-alias"
update_response = alice.connections_update(established_connection, alias=test_alias)
get_response = alice.get_connection(established_connection)

assert update_response['alias'] == test_alias
assert get_response['alias'] == test_alias

assert update_response["alias"] == test_alias
assert get_response["alias"] == test_alias
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""This module contains the constants used in the project."""

# Acapy
FORWARDING_EVENT = 'acapy::forward::received'
FORWARDING_EVENT = "acapy::forward::received"

# Firebase
SCOPES = ['https://www.googleapis.com/auth/firebase.messaging']
BASE_URL = 'https://fcm.googleapis.com'
ENDPOINT_PREFIX = 'v1/projects/'
ENDPOINT_SUFFIX = '/messages:send'
SCOPES = ["https://www.googleapis.com/auth/firebase.messaging"]
BASE_URL = "https://fcm.googleapis.com"
ENDPOINT_PREFIX = "v1/projects/"
ENDPOINT_SUFFIX = "/messages:send"

# Configs
MAX_SEND_RATE_MINUTES = 0
MAX_SEND_RATE_MINUTES = 0
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Handler for push notifications."""

import logging

from aries_cloudagent.messaging.base_handler import (
Expand All @@ -7,8 +8,8 @@
RequestContext,
)

from ..messages.set_device_info import SetDeviceInfo
from ..manager import save_device_token
from ..messages.set_device_info import SetDeviceInfo

LOGGER = logging.getLogger(__name__)

Expand All @@ -20,7 +21,8 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle set-device-info message."""
connection_id = context.connection_record.connection_id
LOGGER.info(
f'set-device-info protocol handler called for connection: {connection_id}')
f"set-device-info protocol handler called for connection: {connection_id}"
)
assert isinstance(context.message, SetDeviceInfo)

device_token = context.message.device_token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the logic for sending push notifications to the user's device using the Firebase Cloud Messaging service.""" # noqa: E501

import json
import logging
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Message type identifiers for push-notifications-fcm v1.0."""

from aries_cloudagent.protocols.didcomm_prefix import DIDCommPrefix

ARIES_PROTOCOL = "push-notifications-fcm/1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Message type for setting device info."""

from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema
from marshmallow import EXCLUDE, fields

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Model for Firebase Push Notifications."""

from aries_cloudagent.core.profile import ProfileSession
from aries_cloudagent.messaging.models.base_record import BaseRecord, BaseRecordSchema
from aries_cloudagent.messaging.valid import INDY_ISO8601_DATETIME_VALIDATE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""API for Firebase push notifications."""

import logging
import re

from aiohttp import web
from aiohttp_apispec import (docs, match_info_schema, request_schema,
response_schema)
from aiohttp_apispec import docs, match_info_schema, request_schema, response_schema
from aries_cloudagent.admin.request_context import AdminRequestContext
from aries_cloudagent.connections.models.conn_record import ConnRecord
from aries_cloudagent.core.event_bus import Event, EventBus
Expand Down
5 changes: 3 additions & 2 deletions firebase_push_notifications/integration/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import time

from . import Agent, BOB, ALICE
import pytest

from . import ALICE, BOB, Agent


@pytest.fixture(scope="session")
Expand Down
Loading

0 comments on commit 3725a70

Please sign in to comment.