Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: DaevMithran <[email protected]>
  • Loading branch information
DaevMithran committed Jan 10, 2025
1 parent a3e81af commit 23dcab4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 35 deletions.
12 changes: 6 additions & 6 deletions cheqd/cheqd/anoncreds/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async def register_schema(
_options: Optional[dict] = None,
) -> SchemaResult:
"""Register a schema on the registry."""
resource_type = CheqdAnoncredsResourceType.schema
resource_type = CheqdAnoncredsResourceType.schema.value
resource_name = f"{schema.name}"
resource_version = schema.version

Expand Down Expand Up @@ -230,7 +230,7 @@ async def register_credential_definition(
_options: Optional[dict] = None,
) -> CredDefResult:
"""Register a credential definition on the registry."""
resource_type = CheqdAnoncredsResourceType.credentialDefinition
resource_type = CheqdAnoncredsResourceType.credentialDefinition.value
# TODO: max chars are 31 for resource, on exceeding this should be hashed
resource_name = f"{schema.schema_value.name}-{credential_definition.tag}"

Expand Down Expand Up @@ -319,7 +319,7 @@ async def register_revocation_registry_definition(
cred_def_res = cred_def_result.credential_definition_metadata.get("resourceName")
# TODO: max chars are 31 for resource name, on exceeding this should be hashed
resource_name = f"{cred_def_res}-{revocation_registry_definition.tag}"
resource_type = CheqdAnoncredsResourceType.revocationRegistryDefinition
resource_type = CheqdAnoncredsResourceType.revocationRegistryDefinition.value

rev_reg_def = ResourceCreateRequestOptions(
name=resource_name,
Expand Down Expand Up @@ -380,7 +380,7 @@ async def get_revocation_list(
)
(did, resource_id) = self.split_schema_id(revocation_registry_id)

resource_type = CheqdAnoncredsResourceType.revocationStatusList
resource_type = CheqdAnoncredsResourceType.revocationStatusList.value
epoch_time = timestamp_to or int(time.time())
dt_object = datetime.fromtimestamp(epoch_time, tz=timezone.utc)

Expand Down Expand Up @@ -432,7 +432,7 @@ async def register_revocation_list(
resource_name = revocation_registry_definition.revocation_registry_metadata.get(
"resourceName"
)
resource_type = CheqdAnoncredsResourceType.revocationStatusList
resource_type = CheqdAnoncredsResourceType.revocationStatusList.value
rev_status_list = ResourceCreateRequestOptions(
name=resource_name,
type=resource_type,
Expand Down Expand Up @@ -488,7 +488,7 @@ async def update_revocation_list(
resource_name = revocation_registry_definition.revocation_registry_metadata.get(
"resourceName"
)
resource_type = CheqdAnoncredsResourceType.revocationStatusList
resource_type = CheqdAnoncredsResourceType.revocationStatusList.value
rev_status_list = ResourceUpdateRequestOptions(
name=resource_name,
type=resource_type,
Expand Down
4 changes: 2 additions & 2 deletions cheqd/cheqd/anoncreds/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ async def test_register_revocation_registry_definition(
== mock_rev_reg_def
)
assert result.registration_metadata["resource_id"] == "MOCK_RESOURCE_ID"
assert result.registration_metadata["resource_name"] == "MOCK_TAG"
assert result.registration_metadata["resource_name"] == "MOCK_RESOURCE_NAME-MOCK_TAG"
assert result.registration_metadata["resource_type"] == "anonCredsRevocRegDef"
assert result.revocation_registry_definition_metadata == {}
mock.assert_called_once_with(
Expand Down Expand Up @@ -387,7 +387,7 @@ async def test_get_schema_info_by_id(mock_resolver, mock_profile):
"cheqd.cheqd.anoncreds.registry.CheqdDIDResolver", return_value=mock_resolver
):
registry = DIDCheqdRegistry()
result = await registry.get_schema_info_by_id(mock_profile, schema_id)
result = await registry.get_schema_info_by_id(schema_id)

# Assert
assert isinstance(result, AnoncredsSchemaInfo)
Expand Down
30 changes: 5 additions & 25 deletions cheqd/cheqd/did/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,14 @@ def __init__(self, registrar_url: str = None) -> None:
if registrar_url:
self.DID_REGISTRAR_BASE_URL = registrar_url

async def generate_did_doc(self, network: str, public_key_hex: str) -> dict | None:
"""Generates a did_document with the provided params."""
async with ClientSession() as session:
try:
async with session.get(
self.DID_REGISTRAR_BASE_URL + "did-document",
params={
"verificationMethod": "Ed25519VerificationKey2020",
"methodSpecificIdAlgo": "uuid",
"network": network,
"publicKeyHex": public_key_hex,
},
) as response:
if response.status == 200:
return await response.json()
else:
raise Exception(response)
except Exception:
raise

async def create(
self, options: DidCreateRequestOptions | SubmitSignatureOptions
) -> dict | None:
"""Create a DID Document."""
async with ClientSession() as session:
try:
async with session.post(
self.DID_REGISTRAR_BASE_URL + "create", json=options
self.DID_REGISTRAR_BASE_URL + "create", json=options.json()
) as response:
if response.status == 200 or response.status == 201:
return await response.json()
Expand All @@ -67,7 +47,7 @@ async def update(
async with ClientSession() as session:
try:
async with session.post(
self.DID_REGISTRAR_BASE_URL + "update", json=options
self.DID_REGISTRAR_BASE_URL + "update", json=options.json()
) as response:
if response.status == 200:
return await response.json()
Expand All @@ -83,7 +63,7 @@ async def deactivate(
async with ClientSession() as session:
try:
async with session.post(
self.DID_REGISTRAR_BASE_URL + "deactivate", json=options
self.DID_REGISTRAR_BASE_URL + "deactivate", json=options.json()
) as response:
if response.status == 200:
return await response.json()
Expand All @@ -99,7 +79,7 @@ async def create_resource(
async with ClientSession() as session:
try:
async with session.post(
self.DID_REGISTRAR_BASE_URL + "/createResource", json=options
self.DID_REGISTRAR_BASE_URL + "/createResource", json=options.json()
) as response:
if response.status == 200 or response.status == 201:
return await response.json()
Expand All @@ -115,7 +95,7 @@ async def update_resource(
async with ClientSession() as session:
try:
async with session.post(
self.DID_REGISTRAR_BASE_URL + "/updateResource", json=options
self.DID_REGISTRAR_BASE_URL + "/updateResource", json=options.json()
) as response:
if response.status == 200:
return await response.json()
Expand Down
4 changes: 2 additions & 2 deletions cheqd/cheqd/did/tests/test_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def test_create_resource(
):
# Arrange
did = "did:cheqd:testnet:123"
create_resource_url = registrar_url + did + "/create-resource"
create_resource_url = registrar_url + "/createResource"

with aioresponses() as mocked:
mocked.post(create_resource_url, status=status, payload=mock_response)
Expand All @@ -131,7 +131,7 @@ async def test_create_resource(
async def test_create_resource_unhappy(registrar_url, registrar, mock_options):
# Arrange
did = "did:cheqd:testnet:123"
create_resource_url = registrar_url + did + "/create-resource"
create_resource_url = registrar_url + "/createResource"

with aioresponses() as mocked:
mocked.post(create_resource_url, status=404)
Expand Down

0 comments on commit 23dcab4

Please sign in to comment.