Skip to content

Commit

Permalink
Add a couple unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jamie Hale <[email protected]>
  • Loading branch information
jamshale authored and cl0ete committed Oct 29, 2024
1 parent 12305de commit 2a46c8e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
63 changes: 63 additions & 0 deletions acapy_agent/revocation/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions acapy_agent/revocation/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2a46c8e

Please sign in to comment.