Skip to content

Commit

Permalink
chore: rename exceptions to better match DID vs Did convention
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Feb 4, 2021
1 parent c78a75e commit 636a035
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions aries_cloudagent/resolver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class ResolverError(Exception):
"""Base class for resolver exceptions."""


class DidNotFound(ResolverError):
class DIDNotFound(ResolverError):
"""Raised when DID is not found in verifiable data registry."""


class DidMethodNotSupported(ResolverError):
class DIDMethodNotSupported(ResolverError):
"""Raised when no resolver is registered for a given did method."""


Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/resolver/default/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ...core.profile import ProfileSession
from ...ledger.indy import IndySdkLedger
from ...ledger.error import LedgerError
from ..base import BaseDIDResolver, DidNotFound, ResolverError, ResolverType
from ..base import BaseDIDResolver, DIDNotFound, ResolverError, ResolverType
from ..did import DID
from ..diddoc import ResolvedDIDDoc

Expand Down Expand Up @@ -46,7 +46,7 @@ async def resolve(self, session: ProfileSession, did: str) -> ResolvedDIDDoc:
recipient_key = await ledger.get_key_for_did(str(did))
endpoint = await ledger.get_endpoint_for_did(str(did))
except LedgerError as err:
raise DidNotFound(f"DID {did} could not be resolved") from err
raise DIDNotFound(f"DID {did} could not be resolved") from err

doc = ResolvedDIDDoc(
{
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/resolver/default/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ....ledger.indy import IndySdkLedger
from ....ledger.error import LedgerError
from ...tests.test_did import TEST_DID0
from ...base import ResolverError, DidNotFound
from ...base import ResolverError, DIDNotFound

# pylint: disable=W0621

Expand Down Expand Up @@ -63,5 +63,5 @@ async def test_resolve_x_did_not_found(
):
"""Test resolve method when no did is found."""
ledger.get_key_for_did.side_effect = LedgerError
with pytest.raises(DidNotFound):
with pytest.raises(DIDNotFound):
await resolver.resolve(session, TEST_DID0)
8 changes: 4 additions & 4 deletions aries_cloudagent/resolver/did_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Union

from ..core.profile import ProfileSession
from ..resolver.base import BaseDIDResolver, DidMethodNotSupported, DidNotFound
from ..resolver.base import BaseDIDResolver, DIDMethodNotSupported, DIDNotFound
from ..resolver.did import DID, DIDUrl # , DID_PATTERN
from ..resolver.diddoc import ResolvedDIDDoc # , ExternalResourceError
from .did_resolver_registry import DIDResolverRegistry
Expand All @@ -35,10 +35,10 @@ async def resolve(
try:
LOGGER.debug("Resolving DID %s with %s", did, resolver)
return await resolver.resolve(session, did)
except DidNotFound:
except DIDNotFound:
LOGGER.debug("DID %s not found by resolver %s", did, resolver)

raise DidNotFound(f"DID {did} could not be resolved.")
raise DIDNotFound(f"DID {did} could not be resolved.")

def _match_did_to_resolver(self, did: DID) -> BaseDIDResolver:
"""Generate supported DID Resolvers.
Expand All @@ -58,7 +58,7 @@ def _match_did_to_resolver(self, did: DID) -> BaseDIDResolver:
)
resolvers = list(chain(native_resolvers, non_native_resolvers))
if not resolvers:
raise DidMethodNotSupported(f"{did.method} not supported")
raise DIDMethodNotSupported(f"{did.method} not supported")
return resolvers

async def dereference_external(
Expand Down
1 change: 0 additions & 1 deletion aries_cloudagent/resolver/did_resolver_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DIDResolverRegistry:
def __init__(self):
"""Initialize list for did resolvers."""
self._resolvers = []
LOGGER.debug("Resolvers listed")

@property
def resolvers(
Expand Down
23 changes: 12 additions & 11 deletions aries_cloudagent/resolver/tests/test_did_resolver.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"""Test did resolver registry."""

import pytest
import unittest

import pytest
from asynctest import mock as async_mock
from ..did_resolver_registry import DIDResolverRegistry
from ..did_resolver import DIDResolver
from ...resolver.diddoc import ResolvedDIDDoc

from ...resolver.base import (
BaseDIDResolver,
DidMethodNotSupported,
DidNotFound,
DIDMethodNotSupported,
DIDNotFound,
ResolverType,
)
from ...resolver.did import DID

from ...resolver.diddoc import ResolvedDIDDoc
from ..did_resolver import DIDResolver
from ..did_resolver_registry import DIDResolverRegistry

TEST_DID0 = "did:sov:Kkyqu7CJFuQSvBp468uaDe"
TEST_DID1 = "did:btcr:8kyt-fzzq-qpqq-ljsc-5l"
Expand Down Expand Up @@ -147,7 +148,7 @@ def test_match_did_to_resolver(resolver, did, method):

def test_match_did_to_resolver_x_not_supported(resolver):
did = DID("did:cowsay:EiDahaOGH-liLLdDtTxEAdc8i-cfCz-WUcQdRJheMVNn3A")
with pytest.raises(DidMethodNotSupported):
with pytest.raises(DIDMethodNotSupported):
resolver._match_did_to_resolver(did)


Expand Down Expand Up @@ -203,16 +204,16 @@ async def test_resolve_did(resolver, session, did):
@pytest.mark.asyncio
async def test_resolve_did_x_not_supported(resolver, session):
did = DID("did:cowsay:EiDahaOGH-liLLdDtTxEAdc8i-cfCz-WUcQdRJheMVNn3A")
with pytest.raises(DidMethodNotSupported):
with pytest.raises(DIDMethodNotSupported):
await resolver.resolve(session, did)


@pytest.mark.asyncio
async def test_resolve_did_x_not_found(session):
did = DID("did:cowsay:EiDahaOGH-liLLdDtTxEAdc8i-cfCz-WUcQdRJheMVNn3A")
cowsay_resolver_not_found = MockResolver("cowsay", resolved=DidNotFound())
cowsay_resolver_not_found = MockResolver("cowsay", resolved=DIDNotFound())
registry = DIDResolverRegistry()
registry.register(cowsay_resolver_not_found)
resolver = DIDResolver(registry)
with pytest.raises(DidNotFound):
with pytest.raises(DIDNotFound):
await resolver.resolve(session, did)

0 comments on commit 636a035

Please sign in to comment.