-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into demo-tails-server
- Loading branch information
Showing
33 changed files
with
1,158 additions
and
210 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
Empty file.
118 changes: 118 additions & 0 deletions
118
aries_cloudagent/messaging/credential_definitions/tests/test_routes.py
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,118 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from aiohttp import web as aio_web | ||
|
||
from ....config.injection_context import InjectionContext | ||
from ....issuer.base import BaseIssuer | ||
from ....ledger.base import BaseLedger | ||
from ....storage.base import BaseStorage | ||
from ....messaging.request_context import RequestContext | ||
|
||
from .. import routes as test_module | ||
|
||
|
||
SCHEMA_ID = "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0" | ||
CRED_DEF_ID = "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag" | ||
|
||
|
||
class TestCredentialDefinitionRoutes(AsyncTestCase): | ||
def setUp(self): | ||
self.context = InjectionContext(enforce_typing=False) | ||
|
||
self.ledger = async_mock.create_autospec(BaseLedger) | ||
self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) | ||
self.ledger.create_and_send_credential_definition = async_mock.CoroutineMock( | ||
return_value=(CRED_DEF_ID, {"cred": "def"}) | ||
) | ||
self.ledger.get_credential_definition = async_mock.CoroutineMock( | ||
return_value={"cred": "def"} | ||
) | ||
self.context.injector.bind_instance(BaseLedger, self.ledger) | ||
|
||
self.issuer = async_mock.create_autospec(BaseIssuer) | ||
self.context.injector.bind_instance(BaseIssuer, self.issuer) | ||
|
||
self.storage = async_mock.create_autospec(BaseStorage) | ||
self.storage.search_records = async_mock.MagicMock( | ||
return_value=async_mock.MagicMock( | ||
fetch_all=async_mock.CoroutineMock( | ||
return_value=[async_mock.MagicMock(value=CRED_DEF_ID)] | ||
) | ||
) | ||
) | ||
self.context.injector.bind_instance(BaseStorage, self.storage) | ||
|
||
self.app = { | ||
"request_context": self.context, | ||
} | ||
|
||
async def test_send_credential_definition(self): | ||
mock_request = async_mock.MagicMock( | ||
app=self.app, | ||
json=async_mock.CoroutineMock( | ||
return_value={ | ||
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", | ||
"support_revocation": False, | ||
"tag": "tag", | ||
} | ||
), | ||
) | ||
|
||
with async_mock.patch.object(test_module.web, "json_response") as mock_response: | ||
result = await test_module.credential_definitions_send_credential_definition( | ||
mock_request | ||
) | ||
assert result == mock_response.return_value | ||
mock_response.assert_called_once_with( | ||
{"credential_definition_id": CRED_DEF_ID} | ||
) | ||
|
||
async def test_created(self): | ||
mock_request = async_mock.MagicMock( | ||
app=self.app, | ||
json=async_mock.CoroutineMock( | ||
return_value={ | ||
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", | ||
"support_revocation": False, | ||
"tag": "tag", | ||
} | ||
), | ||
match_info={"cred_def_id": CRED_DEF_ID}, | ||
) | ||
|
||
with async_mock.patch.object(test_module.web, "json_response") as mock_response: | ||
result = await test_module.credential_definitions_created(mock_request) | ||
assert result == mock_response.return_value | ||
mock_response.assert_called_once_with( | ||
{"credential_definition_ids": [CRED_DEF_ID]} | ||
) | ||
|
||
async def test_get_credential_definition(self): | ||
mock_request = async_mock.MagicMock( | ||
app=self.app, | ||
json=async_mock.CoroutineMock( | ||
return_value={ | ||
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", | ||
"support_revocation": False, | ||
"tag": "tag", | ||
} | ||
), | ||
match_info={"cred_def_id": CRED_DEF_ID}, | ||
) | ||
|
||
with async_mock.patch.object(test_module.web, "json_response") as mock_response: | ||
result = await test_module.credential_definitions_get_credential_definition( | ||
mock_request | ||
) | ||
assert result == mock_response.return_value | ||
mock_response.assert_called_once_with( | ||
{"credential_definition": {"cred": "def"}} | ||
) | ||
|
||
async def test_register(self): | ||
mock_app = async_mock.MagicMock() | ||
mock_app.add_routes = async_mock.MagicMock() | ||
|
||
await test_module.register(mock_app) | ||
mock_app.add_routes.assert_called_once() |
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,72 @@ | ||
import json | ||
import pytest | ||
import uuid | ||
|
||
from copy import deepcopy | ||
from datetime import datetime, timezone | ||
from time import time | ||
from unittest import TestCase | ||
|
||
from marshmallow import fields | ||
|
||
from ....messaging.models.base import BaseModel, BaseModelSchema | ||
|
||
from ..base import BaseDecoratorSet, DECORATOR_PREFIX | ||
|
||
|
||
class SampleDecorator(BaseModel): | ||
"""Sample model for base decorator tests.""" | ||
|
||
class Meta: | ||
"""Sample decorator metadata.""" | ||
|
||
schema_class = "SampleDecoratorSchema" | ||
|
||
def __init__(self, score: int, **kwargs): | ||
"""Initializer.""" | ||
super().__init__(**kwargs) | ||
self.score = score | ||
|
||
|
||
class SampleDecoratorSchema(BaseModelSchema): | ||
"""Sample schema decorator for base decorator tests.""" | ||
|
||
class Meta: | ||
model_class = SampleDecorator | ||
|
||
score = fields.Int(required=True) | ||
|
||
|
||
class TestBaseDecoratorSet(TestCase): | ||
def test_base_decorator_set(self): | ||
MODELS = {"a": SampleDecorator} | ||
deco_set = BaseDecoratorSet(MODELS) | ||
assert type(deco_set) == BaseDecoratorSet | ||
assert not deco_set.fields | ||
assert deco_set.models == MODELS | ||
assert deco_set.prefix == DECORATOR_PREFIX | ||
assert BaseDecoratorSet.__name__ in str(deco_set) | ||
|
||
deco_set_copy = deco_set.copy() | ||
assert type(deco_set_copy) == BaseDecoratorSet | ||
assert not deco_set_copy.fields | ||
assert deco_set_copy.models == MODELS | ||
assert deco_set_copy.prefix == DECORATOR_PREFIX | ||
|
||
assert not deco_set.has_field("x") | ||
deco_set.field("x") | ||
assert not deco_set.has_field("x") # empty | ||
assert not len(deco_set.field("x")) | ||
deco_set.remove_field("x") | ||
assert not deco_set.has_field("x") | ||
|
||
deco_set.add_model("c", SampleDecorator) | ||
assert "c" in deco_set.models | ||
deco_set.remove_model("c") | ||
assert "c" not in deco_set.models | ||
|
||
with pytest.raises(ValueError): | ||
deco_set["a"] = None | ||
deco_set["a"] = {"score": 23} | ||
deco_set["a"] = SampleDecorator(23) | ||
deco_set.load_decorator("a", None) |
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
39 changes: 39 additions & 0 deletions
39
aries_cloudagent/messaging/decorators/tests/test_localization_decorator.py
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,39 @@ | ||
from ..localization_decorator import LocalizationDecorator | ||
|
||
from unittest import TestCase | ||
|
||
|
||
class TestThreadDecorator(TestCase): | ||
|
||
LOCALE = "en-ca" | ||
LOCALIZABLE = ["a", "b"] | ||
CATALOGS = ["http://192.168.56.111/my-project/catalog.json"] | ||
|
||
def test_init(self): | ||
decorator = LocalizationDecorator() | ||
assert decorator.locale is None | ||
assert decorator.localizable == [] | ||
assert decorator.catalogs == [] | ||
|
||
decorator = LocalizationDecorator( | ||
locale=TestThreadDecorator.LOCALE, | ||
localizable=TestThreadDecorator.LOCALIZABLE, | ||
catalogs=TestThreadDecorator.CATALOGS, | ||
) | ||
assert decorator.locale == TestThreadDecorator.LOCALE | ||
assert decorator.localizable == TestThreadDecorator.LOCALIZABLE | ||
assert decorator.catalogs == TestThreadDecorator.CATALOGS | ||
|
||
def test_serialize_load(self): | ||
decorator = LocalizationDecorator( | ||
locale=TestThreadDecorator.LOCALE, | ||
localizable=TestThreadDecorator.LOCALIZABLE, | ||
catalogs=TestThreadDecorator.CATALOGS, | ||
) | ||
|
||
dumped = decorator.serialize() | ||
loaded = LocalizationDecorator.deserialize(dumped) | ||
|
||
assert loaded.locale == self.LOCALE | ||
assert loaded.localizable == self.LOCALIZABLE | ||
assert loaded.catalogs == self.CATALOGS |
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
23 changes: 23 additions & 0 deletions
23
aries_cloudagent/messaging/decorators/tests/test_timing_decorator.py
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 datetime import datetime | ||
from unittest import TestCase | ||
|
||
from ...util import datetime_to_str | ||
from ..timing_decorator import TimingDecorator, TimingDecoratorSchema | ||
|
||
|
||
NOW = datetime.now() | ||
|
||
|
||
class TestTimingDecorator(TestCase): | ||
def test_serialize_load(self): | ||
deco = TimingDecorator(in_time=NOW, out_time=NOW,) | ||
|
||
assert deco.in_time == datetime_to_str(NOW) | ||
assert deco.out_time == datetime_to_str(NOW) | ||
assert not deco.stale_time | ||
assert not deco.expires_time | ||
assert not deco.delay_milli | ||
assert not deco.wait_until_time | ||
|
||
dumped = deco.serialize() | ||
loaded = TimingDecorator.deserialize(dumped) |
20 changes: 20 additions & 0 deletions
20
aries_cloudagent/messaging/decorators/tests/test_transport_decorator.py
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,20 @@ | ||
from unittest import TestCase | ||
|
||
from ...valid import UUIDFour | ||
from ..transport_decorator import TransportDecorator, TransportDecoratorSchema | ||
|
||
|
||
class TestTransportDecorator(TestCase): | ||
def test_serialize_load(self): | ||
deco = TransportDecorator( | ||
return_route="all", | ||
return_route_thread=UUIDFour.EXAMPLE, | ||
queued_message_count=23, | ||
) | ||
|
||
assert deco.return_route == "all" | ||
assert deco.return_route_thread == UUIDFour.EXAMPLE | ||
assert deco.queued_message_count == 23 | ||
|
||
dumped = deco.serialize() | ||
loaded = TransportDecorator.deserialize(dumped) |
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
Oops, something went wrong.