Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Dec 2, 2024
1 parent aed9986 commit b60f20f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
40 changes: 4 additions & 36 deletions acapy_agent/anoncreds/tests/test_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ def __init__(self, bad_schema=False, bad_cred_def=False):
self.schema_id = "Sc886XPwD1gDcHwmmLDeR2:2:degree schema:45.101.94"
self.cred_def_id = "Sc886XPwD1gDcHwmmLDeR2:3:CL:229975:faber.agent.degree_schema"

if bad_schema:
self.schema_id = "bad-schema-id"
if bad_cred_def:
self.cred_def_id = "bad-cred-def-id"

schema_id = "Sc886XPwD1gDcHwmmLDeR2:2:degree schema:45.101.94"
cred_def_id = "Sc886XPwD1gDcHwmmLDeR2:3:CL:229975:faber.agent.degree_schema"
rev_reg_id = None
Expand All @@ -72,15 +67,10 @@ def to_dict(self):


class MockCredReceivedW3C:
def __init__(self, bad_schema=False, bad_cred_def=False):
def __init__(self):
self.schema_id = "Sc886XPwD1gDcHwmmLDeR2:2:degree schema:45.101.94"
self.cred_def_id = "Sc886XPwD1gDcHwmmLDeR2:3:CL:229975:faber.agent.degree_schema"

if bad_schema:
self.schema_id = "bad-schema-id"
if bad_cred_def:
self.cred_def_id = "bad-cred-def-id"

def to_json_buffer(self):
return b"credential"

Expand All @@ -89,9 +79,7 @@ def to_dict(self):


class MockCredential:
def __init__(self, bad_schema=False, bad_cred_def=False):
self.bad_schema = bad_schema
self.bad_cred_def = bad_cred_def
def __init__(self):
self.rev_reg_id = "rev-reg-id"
self.rev_reg_index = 0

Expand All @@ -101,21 +89,17 @@ def to_dict(self):
return MOCK_CRED

def process(self, *args, **kwargs):
return MockCredReceived(self.bad_schema, self.bad_cred_def)
return MockCredReceived()


class MockW3Credential:
def __init__(self, bad_schema=False, bad_cred_def=False):
self.bad_schema = bad_schema
self.bad_cred_def = bad_cred_def

cred = mock.AsyncMock(auto_spec=W3cCredential)

def to_dict(self):
return MOCK_W3C_CRED

def process(self, *args, **kwargs):
return MockCredReceivedW3C(self.bad_schema, self.bad_cred_def)
return MockCredReceivedW3C()


class MockMasterSecret:
Expand Down Expand Up @@ -285,8 +269,6 @@ async def test_store_credential_fails_to_load_raises_x(self, mock_master_secret)
side_effect=[
MockCredential(),
MockCredential(),
MockCredential(bad_schema=True),
MockCredential(bad_cred_def=True),
],
)
async def test_store_credential(self, mock_load, mock_master_secret):
Expand Down Expand Up @@ -321,20 +303,6 @@ async def test_store_credential(self, mock_load, mock_master_secret):
{"cred-req-meta": "cred-req-meta"},
)

# Test bad id's
with self.assertRaises(AnonCredsHolderError):
await self.holder.store_credential(
MOCK_CRED_DEF,
MOCK_PRES,
{"cred-req-meta": "cred-req-meta"},
)
with self.assertRaises(AnonCredsHolderError):
await self.holder.store_credential(
MOCK_CRED_DEF,
MOCK_CRED,
{"cred-req-meta": "cred-req-meta"},
)

@mock.patch.object(AnonCredsHolder, "get_master_secret", return_value="master-secret")
@mock.patch.object(
W3cCredential,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"nonce": "1234567890",
}
ANONCREDS_CRED_REQ = {
"prover_did": TEST_DID,
"entropy": TEST_DID,
"cred_def_id": CRED_DEF_ID,
"blinded_ms": {
"u": "12345",
Expand Down

0 comments on commit b60f20f

Please sign in to comment.