From 2a46c8e163168eadeb92f24b909d121d17ada3be Mon Sep 17 00:00:00 2001 From: Jamie Hale Date: Mon, 21 Oct 2024 22:23:29 +0000 Subject: [PATCH] Add a couple unit tests Signed-off-by: Jamie Hale --- acapy_agent/revocation/tests/test_manager.py | 63 ++++++++++++++++++++ acapy_agent/revocation/tests/test_routes.py | 27 +++++++++ 2 files changed, 90 insertions(+) diff --git a/acapy_agent/revocation/tests/test_manager.py b/acapy_agent/revocation/tests/test_manager.py index 801f14f941..7ce9dca582 100644 --- a/acapy_agent/revocation/tests/test_manager.py +++ b/acapy_agent/revocation/tests/test_manager.py @@ -93,6 +93,69 @@ async def test_revoke_credential_publish(self): ["2", "1"], ) + async def test_revoke_credential_notify(self): + CRED_EX_ID = "dummy-cxid" + CRED_REV_ID = "1" + mock_issuer_rev_reg_record = mock.MagicMock( + revoc_reg_id=REV_REG_ID, + tails_local_path=TAILS_LOCAL, + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), + pending_pub=["2"], + ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.revoke_credentials = mock.CoroutineMock( + return_value=( + json.dumps( + { + "ver": "1.0", + "value": { + "prevAccum": "1 ...", + "accum": "21 ...", + "issued": [1], + }, + } + ), + [], + ) + ) + self.profile.context.injector.bind_instance(IndyIssuer, issuer) + + with mock.patch.object( + test_module.IssuerCredRevRecord, + "retrieve_by_cred_ex_id", + mock.CoroutineMock(), + ) as mock_retrieve, mock.patch.object( + test_module, "IndyRevocation", autospec=True + ) as revoc, mock.patch.object( + test_module.IssuerRevRegRecord, + "retrieve_by_id", + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + ): + mock_retrieve.return_value = mock.MagicMock( + rev_reg_id="dummy-rr-id", cred_rev_id=CRED_REV_ID + ) + mock_rev_reg = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock() + ) + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( + return_value=mock_issuer_rev_reg_record + ) + revoc.return_value.get_ledger_registry = mock.CoroutineMock( + return_value=mock_rev_reg + ) + + await self.manager.revoke_credential_by_cred_ex_id( + CRED_EX_ID, publish=True, notify=True + ) + + issuer.revoke_credentials.assert_awaited_once_with( + mock_issuer_rev_reg_record.cred_def_id, + mock_issuer_rev_reg_record.revoc_reg_id, + mock_issuer_rev_reg_record.tails_local_path, + ["2", "1"], + ) + async def test_revoke_credential_publish_endorser(self): conn_record = ConnRecord( their_label="Hello", diff --git a/acapy_agent/revocation/tests/test_routes.py b/acapy_agent/revocation/tests/test_routes.py index 216e770964..f48d48b93c 100644 --- a/acapy_agent/revocation/tests/test_routes.py +++ b/acapy_agent/revocation/tests/test_routes.py @@ -11,10 +11,14 @@ from ...admin.request_context import AdminRequestContext from ...askar.profile_anon import AskarAnoncredsProfile +from ...ledger.base import BaseLedger +from ...ledger.multiple_ledger.base_manager import BaseMultipleLedgerManager from ...protocols.endorse_transaction.v1_0.manager import TransactionManagerError +from ...revocation.manager import RevocationManager from ...storage.error import StorageError from ...storage.in_memory import InMemoryStorage from .. import routes as test_module +from ..models.issuer_rev_reg_record import IssuerRevRegRecord class TestRevocationRoutes(IsolatedAsyncioTestCase): @@ -1189,6 +1193,29 @@ async def test_post_process_routes(self): assert "tags" in mock_app._state["swagger_dict"] + @mock.patch.object( + IssuerRevRegRecord, "retrieve_by_revoc_reg_id", return_value=mock.MagicMock() + ) + @mock.patch.object( + RevocationManager, "update_rev_reg_revoked_state", return_value=(True, True, True) + ) + async def test_update_rev_reg_revoked_state(self, *_): + self.request.query = {"apply_ledger_update": "true"} + self.request.match_info = {"rev_reg_id": "rev_reg_id"} + + mock_ledger_manager = mock.MagicMock(BaseMultipleLedgerManager, autospec=True) + mock_ledger_manager.get_write_ledgers = mock.CoroutineMock("ledger") + self.context.injector.bind_instance( + BaseMultipleLedgerManager, mock_ledger_manager + ) + + mock_ledger = mock.MagicMock(BaseLedger, autospec=True) + mock_ledger.pool = mock.MagicMock(genesis_txns="genesis_txns") + self.context.injector.bind_instance(BaseLedger, mock_ledger) + + result = await test_module.update_rev_reg_revoked_state(self.request) + assert result.status == 200 + class TestDeleteTails(IsolatedAsyncioTestCase): def setUp(self):