Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed May 7, 2024
1 parent 291b7cd commit d19dc20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions aries_cloudagent/wallet/anoncreds_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,17 @@ async def convert_records_to_anoncreds(profile) -> None:
cred_def_upgrade_objs.append(cred_def_upgrade_obj)

# Link secret
record = None
link_secret_record = None
try:
record = await session.handle.fetch(
link_secret_record = await session.handle.fetch(
CATEGORY_LINK_SECRET, IndyCredxHolder.LINK_SECRET_ID
)
except AskarError:
pass

link_secret = None
if record:
link_secret = LinkSecret.load(record.raw_value)
if link_secret_record:
link_secret = LinkSecret.load(link_secret_record.raw_value)

async with profile.transaction() as txn:
try:
Expand Down
24 changes: 20 additions & 4 deletions aries_cloudagent/wallet/tests/test_anoncreds_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from aries_cloudagent.wallet import singletons

from ...anoncreds.issuer import CATEGORY_CRED_DEF_PRIVATE
from ...cache.base import BaseCache
from ...core.in_memory.profile import InMemoryProfile, InMemoryProfileSession
from ...indy.credx.issuer import CATEGORY_CRED_DEF_KEY_PROOF
from ...messaging.credential_definitions.util import CRED_DEF_SENT_RECORD_TYPE
Expand All @@ -31,10 +32,15 @@ def setUp(self) -> None:
self.context.injector.bind_instance(
BaseMultitenantManager, mock.MagicMock(MultitenantManager, autospec=True)
)
self.context.injector.bind_instance(
BaseCache, mock.MagicMock(BaseCache, autospec=True)
)

async def test_convert_records_to_anoncreds(self):
@mock.patch.object(InMemoryProfileSession, "handle")
async def test_convert_records_to_anoncreds(self, mock_handle):
async with self.profile.session() as session:
storage = session.inject(BaseStorage)
mock_handle.fetch = mock.CoroutineMock(return_value=None)

schema_id = "GHjSbphAcdsrZrLjSvsjMp:2:faber-simple:1.1"
schema_id_parts = schema_id.split(":")
Expand Down Expand Up @@ -113,7 +119,9 @@ async def test_convert_records_to_anoncreds(self):
):
await anoncreds_upgrade.convert_records_to_anoncreds(self.profile)

async def test_retry_converting_records(self):
@mock.patch.object(InMemoryProfileSession, "handle")
async def test_retry_converting_records(self, mock_handle):
mock_handle.fetch = mock.CoroutineMock(return_value=None)
with mock.patch.object(
anoncreds_upgrade, "convert_records_to_anoncreds", mock.CoroutineMock()
) as mock_convert_records_to_anoncreds:
Expand Down Expand Up @@ -147,7 +155,10 @@ async def test_retry_converting_records(self):
)
assert "test-profile" in singletons.IsAnoncredsSingleton().wallets

async def test_upgrade_wallet_to_anoncreds(self):
@mock.patch.object(InMemoryProfileSession, "handle")
async def test_upgrade_wallet_to_anoncreds(self, mock_handle):
mock_handle.fetch = mock.CoroutineMock(return_value=None)

# upgrading record not present
await anoncreds_upgrade.upgrade_wallet_to_anoncreds_if_requested(self.profile)

Expand Down Expand Up @@ -219,6 +230,9 @@ async def test_update_if_subwallet_and_set_storage_type_with_subwallet(self):
)
_, storage_type_record = next(iter(self.profile.records.items()))
assert storage_type_record.value == STORAGE_TYPE_VALUE_ANONCREDS
assert self.profile.context.injector.get_provider(
BaseCache
)._instance.flush.called

async def test_update_if_subwallet_and_set_storage_type_with_base_wallet(self):

Expand All @@ -228,7 +242,9 @@ async def test_update_if_subwallet_and_set_storage_type_with_base_wallet(self):
_, storage_type_record = next(iter(self.profile.records.items()))
assert storage_type_record.value == STORAGE_TYPE_VALUE_ANONCREDS

async def test_failed_upgrade(self):
@mock.patch.object(InMemoryProfileSession, "handle")
async def test_failed_upgrade(self, mock_handle):
mock_handle.fetch = mock.CoroutineMock(return_value=None)
async with self.profile.session() as session:
storage = session.inject(BaseStorage)

Expand Down

0 comments on commit d19dc20

Please sign in to comment.