Skip to content

Commit

Permalink
Anoncreds post api object handling (#3411)
Browse files Browse the repository at this point in the history
* Anoncreds post api object handling

Signed-off-by: jamshale <[email protected]>

* Update unit test

Signed-off-by: jamshale <[email protected]>

---------

Signed-off-by: jamshale <[email protected]>
Co-authored-by: Ian Costanzo <[email protected]>
  • Loading branch information
jamshale and ianco authored Dec 20, 2024
1 parent 1aacd1b commit fe87db7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 7 additions & 2 deletions acapy_agent/anoncreds/models/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Meta:
"example": ANONCREDS_DID_EXAMPLE,
},
data_key="issuerId",
required=True,
)
attr_names = fields.List(
fields.Str(
Expand All @@ -74,11 +75,15 @@ class Meta:
),
metadata={"description": "Schema attribute names"},
data_key="attrNames",
required=True,
)
name = fields.Str(
metadata={"description": "Schema name", "example": "Example schema"}
metadata={"description": "Schema name", "example": "Example schema"},
required=True,
)
version = fields.Str(
metadata={"description": "Schema version", "example": "1.0"}, required=True
)
version = fields.Str(metadata={"description": "Schema version", "example": "1.0"})


class GetSchemaResult(BaseModel):
Expand Down
9 changes: 7 additions & 2 deletions acapy_agent/anoncreds/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,23 +524,27 @@ class InnerRevRegDefSchema(OpenAPISchema):
"example": ANONCREDS_DID_EXAMPLE,
},
data_key="issuerId",
required=True,
)
cred_def_id = fields.Str(
metadata={
"description": "Credential definition identifier",
"example": ANONCREDS_SCHEMA_ID_EXAMPLE,
},
data_key="credDefId",
required=True,
)
tag = fields.Str(
metadata={"description": "tag for revocation registry", "example": "default"}
metadata={"description": "tag for revocation registry", "example": "default"},
required=True,
)
max_cred_num = fields.Int(
metadata={
"description": "Maximum number of credential revocations per registry",
"example": 777,
},
data_key="maxCredNum",
required=True,
)


Expand Down Expand Up @@ -649,7 +653,8 @@ class RevListCreateRequestSchema(OpenAPISchema):
metadata={
"description": "Revocation registry definition identifier",
"example": ANONCREDS_REV_REG_ID_EXAMPLE,
}
},
required=True,
)
options = fields.Nested(RevListOptionsSchema)

Expand Down
14 changes: 12 additions & 2 deletions acapy_agent/anoncreds/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ async def test_schemas_post(self, mock_create_and_register_schema):
},
{},
{"schema": {}},
{
"schema": {
"attrNames": ["score"],
"name": "Example Schema",
"version": "0.0.1",
}
},
]
)
result = await test_module.schemas_post(self.request)
Expand All @@ -105,9 +112,12 @@ async def test_schemas_post(self, mock_create_and_register_schema):
assert mock_create_and_register_schema.call_count == 1

with self.assertRaises(web.HTTPBadRequest):
# Empty body
await test_module.schemas_post(self.request)
# Empty schema
await test_module.schemas_post(self.request)
# Missing issuerId
await test_module.schemas_post(self.request)

await test_module.schemas_post(self.request)

async def test_get_schema(self):
self.request.match_info = {"schema_id": "schema_id"}
Expand Down

0 comments on commit fe87db7

Please sign in to comment.