Skip to content

Commit

Permalink
clean up warnings during unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Aug 22, 2021
1 parent 49f707e commit e853da2
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 60 deletions.
9 changes: 4 additions & 5 deletions aries_cloudagent/core/tests/test_dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import asyncio
import json

import pytest

from asynctest import TestCase as AsyncTestCase, mock as async_mock
from marshmallow import EXCLUDE

from ...config.injection_context import InjectionContext
from ...connections.models.conn_record import ConnRecord
from ...core.event_bus import EventBus
from ...core.in_memory import InMemoryProfile
from ...core.profile import Profile
from ...core.protocol_registry import ProtocolRegistry
from ...messaging.agent_message import AgentMessage, AgentMessageSchema
from ...messaging.responder import MockResponder
from ...messaging.request_context import RequestContext
from ...messaging.util import datetime_now
from ...protocols.didcomm_prefix import DIDCommPrefix
from ...protocols.issue_credential.v2_0.message_types import CRED_20_PROBLEM_REPORT
from ...protocols.issue_credential.v2_0.messages.cred_problem_report import (
Expand Down Expand Up @@ -393,7 +391,8 @@ async def test_create_send_webhook(self):
context = RequestContext(profile)
message = StubAgentMessage()
responder = test_module.DispatcherResponder(context, message, None)
await responder.send_webhook("topic", {"pay": "load"})
with pytest.deprecated_call():
await responder.send_webhook("topic", {"pay": "load"})

async def test_create_enc_outbound(self):
profile = make_profile()
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/core/tests/test_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from asynctest import TestCase as AsyncTestCase, mock as async_mock
from asynctest import TestCase as AsyncTestCase

from ..error import BaseError

Expand Down
10 changes: 6 additions & 4 deletions aries_cloudagent/resolver/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Base Class for DID Resolvers."""

import re
import warnings

from abc import ABC, abstractmethod
from enum import Enum
import re
from typing import NamedTuple, Pattern, Sequence, Union
import warnings

from pydid import DID

Expand Down Expand Up @@ -116,7 +117,8 @@ async def supports(self, profile: Profile, did: str) -> bool:
try:
supported_did_regex = self.supported_did_regex
except NotImplementedError as error:
if not self.supported_methods:
methods = self.supported_methods
if not methods:
raise error
warnings.warn(
"BaseResolver.supported_methods is deprecated; "
Expand All @@ -125,7 +127,7 @@ async def supports(self, profile: Profile, did: str) -> bool:
)

supported_did_regex = re.compile(
"^did:(?:{}):.*$".format("|".join(self.supported_methods))
"^did:(?:{}):.*$".format("|".join(methods))
)

return bool(supported_did_regex.match(did))
Expand Down
11 changes: 1 addition & 10 deletions aries_cloudagent/resolver/default/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Resolution is performed using the IndyLedger class.
"""

from typing import Sequence, Pattern
from typing import Pattern

from pydid import DID, DIDDocumentBuilder
from pydid.verification_method import Ed25519VerificationKey2018
Expand Down Expand Up @@ -34,15 +34,6 @@ def __init__(self):
async def setup(self, context: InjectionContext):
"""Perform required setup for Indy DID resolution."""

@property
def supported_methods(self) -> Sequence[str]:
"""
Return supported methods of Indy DID Resolver.
DEPRECATED: Use supported_did_regex instead.
"""
return ["sov"]

@property
def supported_did_regex(self) -> Pattern:
"""Return supported_did_regex of Indy DID Resolver."""
Expand Down
11 changes: 1 addition & 10 deletions aries_cloudagent/resolver/default/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Resolution is performed using the IndyLedger class.
"""

from typing import Sequence, Pattern
from typing import Pattern

from ...did.did_key import DIDKey
from ...config.injection_context import InjectionContext
Expand All @@ -23,15 +23,6 @@ def __init__(self):
async def setup(self, context: InjectionContext):
"""Perform required setup for Key DID resolution."""

@property
def supported_methods(self) -> Sequence[str]:
"""
Return supported methods of Key DID Resolver.
DEPRECATED: Use supported_did_regex instead.
"""
return ["key"]

@property
def supported_did_regex(self) -> Pattern:
"""Return supported_did_regex of Key DID Resolver."""
Expand Down
6 changes: 0 additions & 6 deletions aries_cloudagent/resolver/default/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ def profile(ledger):


class TestIndyResolver:
@pytest.mark.asyncio
async def test_supported_methods(self, profile, resolver: IndyDIDResolver):
"""Test the supported_methods."""
assert resolver.supported_methods == ["sov"]
assert await resolver.supports(profile, TEST_DID0)

@pytest.mark.asyncio
async def test_supported_did_regex(self, profile, resolver: IndyDIDResolver):
"""Test the supported_did_regex."""
Expand Down
10 changes: 0 additions & 10 deletions aries_cloudagent/resolver/default/tests/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ def profile():
yield profile


@pytest.mark.asyncio
async def test_supported_methods(profile, resolver: KeyDIDResolver):
"""Test the supported_methods."""
assert resolver.supported_methods == ["key"]
assert await resolver.supports(
profile,
TEST_DID0,
)


@pytest.mark.asyncio
async def test_supported_did_regex(profile, resolver: KeyDIDResolver):
"""Test the supported_did_regex."""
Expand Down
6 changes: 1 addition & 5 deletions aries_cloudagent/resolver/default/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import urllib.parse

from typing import Sequence, Pattern
from typing import Pattern

import aiohttp

Expand Down Expand Up @@ -35,10 +35,6 @@ def supported_did_regex(self) -> Pattern:
"""Return supported_did_regex of Web DID Resolver."""
return DIDWeb.PATTERN

def supported_methods(self) -> Sequence[str]:
"""Return list of supported methods."""
return ["web"]

def __transform_to_url(self, did):
"""
Transform did to url.
Expand Down
23 changes: 19 additions & 4 deletions aries_cloudagent/resolver/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def __init__(self):
async def setup(self, context):
pass

@property
def supported_methods(self):
return ["test"]

@property
def supported_did_regex(self):
return re.compile("^did:example:[a-zA-Z0-9_.-]+$")
Expand Down Expand Up @@ -66,3 +62,22 @@ async def test_resolve_x(native_resolver):
with pytest.raises(DIDMethodNotSupported) as x_did:
await native_resolver.resolve(None, "did:nosuchmethod:xxx")
assert "does not support DID method" in str(x_did.value)


@pytest.mark.asyncio
async def test_supported_methods():
class TestDIDResolver(BaseDIDResolver):
async def setup(self, context):
pass

@property
def supported_methods(self):
return ["example"]

async def _resolve(self, profile, did) -> DIDDocument:
return DIDDocument("did:example:123")

with pytest.deprecated_call():
assert await TestDIDResolver().supports(
profile, "did:example:WgWxqztrNooG92RXvxSTWv"
)
16 changes: 11 additions & 5 deletions aries_cloudagent/resolver/tests/test_did_resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Test did resolver registry."""

from typing import Pattern

import re

import pytest

from asynctest import mock as async_mock
Expand Down Expand Up @@ -64,16 +68,18 @@
class MockResolver(BaseDIDResolver):
def __init__(self, supported_methods, resolved=None, native: bool = False):
super().__init__(ResolverType.NATIVE if native else ResolverType.NON_NATIVE)
self._supported_methods = supported_methods
self._did_regex = re.compile(
"^did:(?:{}):.*$".format("|".join(supported_methods))
)
self.resolved = resolved

@property
def supported_did_regex(self) -> Pattern:
return self._did_regex

async def setup(self, context):
pass

@property
def supported_methods(self):
return self._supported_methods

async def _resolve(self, profile, did):
if isinstance(self.resolved, Exception):
raise self.resolved
Expand Down

0 comments on commit e853da2

Please sign in to comment.