Skip to content

Commit

Permalink
chore: swap session for profile
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 636a035 commit 28049d1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions aries_cloudagent/resolver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Sequence

from .diddoc import ResolvedDIDDoc
from ..core.profile import ProfileSession
from ..core.profile import Profile


class ResolverError(Exception):
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(self, type_: ResolverType = None):
self.type = type_ or ResolverType.NON_NATIVE

@abstractmethod
async def setup(self, session: ProfileSession):
async def setup(self, profile: Profile):
"""Do asynchronous resolver setup."""

@property
Expand All @@ -57,5 +57,5 @@ def supports(self, method: str):
return method in self.supported_methods

@abstractmethod
async def resolve(self, session: ProfileSession, did: str) -> ResolvedDIDDoc:
async def resolve(self, profile: Profile, did: str) -> ResolvedDIDDoc:
"""Resolve a DID using this resolver."""
8 changes: 4 additions & 4 deletions aries_cloudagent/resolver/default/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from typing import Sequence

from ...core.profile import ProfileSession
from ...core.profile import Profile
from ...ledger.indy import IndySdkLedger
from ...ledger.error import LedgerError
from ..base import BaseDIDResolver, DIDNotFound, ResolverError, ResolverType
Expand All @@ -25,17 +25,17 @@ def __init__(self):
"""Initialize Indy Resolver."""
super().__init__(ResolverType.NATIVE)

async def setup(self, session: ProfileSession):
async def setup(self, profile: Profile):
"""Perform required setup for Indy DID resolution."""

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

async def resolve(self, session: ProfileSession, did: str) -> ResolvedDIDDoc:
async def resolve(self, profile: Profile, did: str) -> ResolvedDIDDoc:
"""Resolve an indy DID."""
ledger = session.inject(IndySdkLedger, required=False)
ledger = profile.inject(IndySdkLedger, required=False)
if not ledger:
raise NoIndyLedger("No Indy ledger isntance is configured.")

Expand Down
26 changes: 13 additions & 13 deletions aries_cloudagent/resolver/default/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..indy import IndyDIDResolver
from ....core.in_memory import InMemoryProfile
from ....core.profile import ProfileSession
from ....core.profile import Profile
from ....ledger.indy import IndySdkLedger
from ....ledger.error import LedgerError
from ...tests.test_did import TEST_DID0
Expand All @@ -30,11 +30,11 @@ def ledger():


@pytest.fixture
def session(ledger):
"""Session fixture."""
session = InMemoryProfile.test_session()
session.context.injector.bind_instance(IndySdkLedger, ledger)
yield session
def profile(ledger):
"""Profile fixture."""
profile = InMemoryProfile.test_profile()
profile.context.injector.bind_instance(IndySdkLedger, ledger)
yield profile


def test_supported_methods(resolver: IndyDIDResolver):
Expand All @@ -44,24 +44,24 @@ def test_supported_methods(resolver: IndyDIDResolver):


@pytest.mark.asyncio
async def test_resolve(resolver: IndyDIDResolver, session: ProfileSession):
async def test_resolve(resolver: IndyDIDResolver, profile: Profile):
"""Test resolve method."""
assert await resolver.resolve(session, TEST_DID0)
assert await resolver.resolve(profile, TEST_DID0)


@pytest.mark.asyncio
async def test_resolve_x_no_ledger(resolver: IndyDIDResolver, session: ProfileSession):
async def test_resolve_x_no_ledger(resolver: IndyDIDResolver, profile: Profile):
"""Test resolve method with no ledger."""
session.context.injector.clear_binding(IndySdkLedger)
profile.context.injector.clear_binding(IndySdkLedger)
with pytest.raises(ResolverError):
await resolver.resolve(session, TEST_DID0)
await resolver.resolve(profile, TEST_DID0)


@pytest.mark.asyncio
async def test_resolve_x_did_not_found(
resolver: IndyDIDResolver, ledger: IndySdkLedger, session: ProfileSession
resolver: IndyDIDResolver, ledger: IndySdkLedger, profile: Profile
):
"""Test resolve method when no did is found."""
ledger.get_key_for_did.side_effect = LedgerError
with pytest.raises(DIDNotFound):
await resolver.resolve(session, TEST_DID0)
await resolver.resolve(profile, TEST_DID0)
10 changes: 5 additions & 5 deletions aries_cloudagent/resolver/did_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from itertools import chain
from typing import Union

from ..core.profile import ProfileSession
from ..core.profile import Profile
from ..resolver.base import BaseDIDResolver, DIDMethodNotSupported, DIDNotFound
from ..resolver.did import DID, DIDUrl # , DID_PATTERN
from ..resolver.diddoc import ResolvedDIDDoc # , ExternalResourceError
Expand All @@ -26,15 +26,15 @@ def __init__(self, registry: DIDResolverRegistry):
self.did_resolver_registry = registry

async def resolve(
self, session: ProfileSession, did: Union[str, DID]
self, profile: Profile, did: Union[str, DID]
) -> ResolvedDIDDoc:
"""Retrieve did doc from public registry."""
if isinstance(did, str):
did = DID(did)
for resolver in self._match_did_to_resolver(did):
try:
LOGGER.debug("Resolving DID %s with %s", did, resolver)
return await resolver.resolve(session, did)
return await resolver.resolve(profile, did)
except DIDNotFound:
LOGGER.debug("DID %s not found by resolver %s", did, resolver)

Expand Down Expand Up @@ -62,9 +62,9 @@ def _match_did_to_resolver(self, did: DID) -> BaseDIDResolver:
return resolvers

async def dereference_external(
self, session: ProfileSession, did_url: str
self, profile: Profile, did_url: str
) -> ResolvedDIDDoc:
"""Retrieve an external did in doc service from a public registry."""
did_url = DIDUrl.parse(did_url)
doc = await self.resolve(session, did_url.did)
doc = await self.resolve(profile, did_url.did)
return doc.dereference(did_url)
4 changes: 2 additions & 2 deletions aries_cloudagent/resolver/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class ExampleDIDResolver(BaseDIDResolver):
def __init__(self):
super().__init__()

async def setup(self, session):
async def setup(self, profile):
pass

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

async def resolve(self, session, did: str) -> ResolvedDIDDoc:
async def resolve(self, profile, did: str) -> ResolvedDIDDoc:
return ResolvedDIDDoc({"id": "did:example:123"})


Expand Down
26 changes: 13 additions & 13 deletions aries_cloudagent/resolver/tests/test_did_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ def __init__(self, supported_methods, resolved=None, native: bool = False):
self._supported_methods = supported_methods
self.resolved = resolved

async def setup(self, session):
async def setup(self, profile):
pass

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

async def resolve(self, session, did):
async def resolve(self, profile, did):
if isinstance(self.resolved, Exception):
raise self.resolved
return self.resolved
Expand All @@ -131,7 +131,7 @@ def resolver():


@pytest.fixture
def session():
def profile():
yield async_mock.MagicMock()


Expand Down Expand Up @@ -179,41 +179,41 @@ def test_match_did_to_resolver_registration_order():


@pytest.mark.asyncio
async def test_dereference_external(resolver, session):
async def test_dereference_external(resolver, profile):
url = "did:example:1234abcd#4"
assert DOC["verificationMethod"][1] == await resolver.dereference_external(
session, url
profile, url
)


@pytest.mark.asyncio
@pytest.mark.parametrize("did", TEST_DIDS)
async def test_resolve(resolver, session, did):
did_doc = await resolver.resolve(session, did)
async def test_resolve(resolver, profile, did):
did_doc = await resolver.resolve(profile, did)
assert isinstance(did_doc, ResolvedDIDDoc)


@pytest.mark.asyncio
@pytest.mark.parametrize("did", TEST_DIDS)
async def test_resolve_did(resolver, session, did):
async def test_resolve_did(resolver, profile, did):
did = DID(did)
did_doc = await resolver.resolve(session, did)
did_doc = await resolver.resolve(profile, did)
assert isinstance(did_doc, ResolvedDIDDoc)


@pytest.mark.asyncio
async def test_resolve_did_x_not_supported(resolver, session):
async def test_resolve_did_x_not_supported(resolver, profile):
did = DID("did:cowsay:EiDahaOGH-liLLdDtTxEAdc8i-cfCz-WUcQdRJheMVNn3A")
with pytest.raises(DIDMethodNotSupported):
await resolver.resolve(session, did)
await resolver.resolve(profile, did)


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

0 comments on commit 28049d1

Please sign in to comment.