-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jamie Hale <jamiehalebc@gmail.com>
- Loading branch information
Showing
6 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from unittest import IsolatedAsyncioTestCase | ||
|
||
from aries_cloudagent.admin.request_context import AdminRequestContext | ||
from aries_cloudagent.core.in_memory.profile import InMemoryProfile | ||
from aries_cloudagent.did.tdw.routes import resolve_did_tdw | ||
from aries_cloudagent.resolver.did_resolver import DIDResolver | ||
from aries_cloudagent.tests import mock | ||
|
||
mock_response = { | ||
"@context": [ | ||
"https://www.w3.org/ns/did/v1", | ||
"https://w3id.org/security/multikey/v1", | ||
], | ||
"id": "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example", # noqa: E501 | ||
} | ||
|
||
|
||
class TestAnoncredsRoutes(IsolatedAsyncioTestCase): | ||
async def asyncSetUp(self) -> None: | ||
self.session_inject = {} | ||
self.profile = InMemoryProfile.test_profile( | ||
settings={ | ||
"admin.admin_api_key": "secret-key", | ||
}, | ||
) | ||
self.context = AdminRequestContext.test_context(self.session_inject, self.profile) | ||
self.request_dict = { | ||
"context": self.context, | ||
} | ||
self.request = mock.MagicMock( | ||
app={}, | ||
match_info={}, | ||
query={}, | ||
__getitem__=lambda _, k: self.request_dict[k], | ||
context=self.context, | ||
headers={"x-api-key": "secret-key"}, | ||
json=mock.AsyncMock( | ||
return_value={ | ||
"did": "did:tdw:QmRHpkso6BM1jRvGee5VoiS3a6wUfPAfuPnyGRBFo4rL6k:example.com" | ||
} | ||
), | ||
) | ||
|
||
async def test_resolve_did_tdw(self): | ||
self.profile.context.injector.bind_instance( | ||
DIDResolver, | ||
mock.MagicMock(resolve=mock.CoroutineMock(return_value=mock_response)), | ||
) | ||
response = await resolve_did_tdw(self.request) | ||
assert response.body | ||
|
||
async def test_resolve_did_tdw_error(self): | ||
self.profile.context.injector.bind_instance( | ||
DIDResolver, | ||
mock.MagicMock( | ||
resolve=mock.CoroutineMock( | ||
return_value={ | ||
"error": "error", | ||
"errorMessage": "error message", | ||
} | ||
) | ||
), | ||
) | ||
response = await resolve_did_tdw(self.request) | ||
assert response.status == 400 | ||
assert response.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from aries_cloudagent.core.in_memory.profile import InMemoryProfile | ||
from aries_cloudagent.did.tdw.tdw_manager import DidTdwManager | ||
from aries_cloudagent.resolver.did_resolver import DIDResolver | ||
from aries_cloudagent.tests import mock | ||
|
||
|
||
class TestTdwManager: | ||
def test_init(self): | ||
manager = DidTdwManager(InMemoryProfile.test_profile()) | ||
assert manager | ||
|
||
async def test_resolve(self): | ||
profile = InMemoryProfile.test_profile() | ||
profile.context.injector.bind_instance( | ||
DIDResolver, | ||
mock.MagicMock( | ||
resolve=mock.CoroutineMock(return_value={"did_doc": "resolved"}) | ||
), | ||
) | ||
await DidTdwManager(profile).resolve( | ||
"did:tdw:QmRHpkso6BM1jRvGee5VoiS3a6wUfPAfuPnyGRBFo4rL6k:example.com" | ||
) | ||
assert profile.context.injector.get_provider(DIDResolver)._instance.resolve.called |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
from ....core.in_memory import InMemoryProfile | ||
from ....core.profile import Profile | ||
from ....messaging.valid import DIDTdw | ||
from ..tdw import TdwDIDResolver | ||
|
||
TEST_DID = "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example" | ||
|
||
|
||
@pytest.fixture | ||
def resolver(): | ||
"""Resolver fixture.""" | ||
yield TdwDIDResolver() | ||
|
||
|
||
@pytest.fixture | ||
def profile(): | ||
"""Profile fixture.""" | ||
profile = InMemoryProfile.test_profile() | ||
yield profile | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_supported_did_regex(profile, resolver: TdwDIDResolver): | ||
"""Test the supported_did_regex.""" | ||
assert resolver.supported_did_regex == DIDTdw.PATTERN | ||
assert await resolver.supports( | ||
profile, | ||
TEST_DID, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_resolve(resolver: TdwDIDResolver, profile: Profile): | ||
"""Test resolve method.""" | ||
assert await resolver.resolve(profile, TEST_DID) |