Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make long strings look like elsewhere in aca-py; cover new routes code #1118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 49 additions & 32 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,6 @@ async def transaction_create_request(request: web.BaseRequest):
transaction_record = await TransactionRecord.retrieve_by_id(
session, transaction_id
)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except BaseModelError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

try:
async with context.session() as session:
connection_record = await ConnRecord.retrieve_by_id(
session, transaction_record.connection_id
)
Expand All @@ -231,18 +224,24 @@ async def transaction_create_request(request: web.BaseRequest):
jobs = await connection_record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if "transaction_my_job" not in jobs.keys():
raise web.HTTPForbidden(
reason='The "transaction_my_job" is not set in "transaction_jobs"'
" in connection metadata for this connection record"
reason=(
'The "transaction_my_job" is not set in "transaction_jobs" '
"connection metadata for this connection record"
)
)
if "transaction_their_job" not in jobs.keys():
raise web.HTTPForbidden(
reason='Ask the other agent to set up "transaction_my_job" '
' in "transaction_jobs" in connection metadata for their connection record'
reason=(
'Ask the other agent to set up "transaction_my_job" in '
'"transaction_jobs" in connection metadata for their connection record'
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_AUTHOR.name:
raise web.HTTPForbidden(reason="Only a TRANSACTION_AUTHOR can create a request")
Expand Down Expand Up @@ -319,8 +318,10 @@ async def endorse_transaction_response(request: web.BaseRequest):
jobs = await connection_record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_ENDORSER.name:
raise web.HTTPForbidden(
Expand Down Expand Up @@ -418,8 +419,10 @@ async def refuse_transaction_response(request: web.BaseRequest):
jobs = await connection_record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_ENDORSER.name:
raise web.HTTPForbidden(
Expand Down Expand Up @@ -485,8 +488,10 @@ async def cancel_transaction(request: web.BaseRequest):
jobs = await connection_record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_AUTHOR.name:
raise web.HTTPForbidden(
Expand Down Expand Up @@ -550,8 +555,10 @@ async def transaction_resend(request: web.BaseRequest):
jobs = await connection_record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_AUTHOR.name:
raise web.HTTPForbidden(
Expand Down Expand Up @@ -652,27 +659,35 @@ async def set_endorser_info(request: web.BaseRequest):
jobs = await record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if "transaction_my_job" not in jobs.keys():
raise web.HTTPForbidden(
reason='The "transaction_my_job" is not set in "transaction_jobs"'
" in connection metadata for this connection record"
reason=(
'The "transaction_my_job" is not set in "transaction_jobs"'
" in connection metadata for this connection record"
)
)
if "transaction_their_job" not in jobs.keys():
raise web.HTTPForbidden(
reason='Ask the other agent to set up "transaction_my_job" '
' in "transaction_jobs" in connection metadata for their connection record'
reason=(
'Ask the other agent to set up "transaction_my_job" in '
'"transaction_jobs" in connection metadata for their connection record'
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_AUTHOR.name:
raise web.HTTPForbidden(
reason="Only a TRANSACTION_AUTHOR can add endorser_info "
"to metadata of it's connection record"
reason=(
"Only a TRANSACTION_AUTHOR can add endorser_info "
"to metadata of its connection record"
)
)
if jobs["transaction_their_job"] != TransactionJob.TRANSACTION_ENDORSER.name:
raise web.HTTPForbidden(
reason="The Other agent should have a job of " "TRANSACTION_ENDORSER"
reason="The Other agent should have job TRANSACTION_ENDORSER"
)
value = await record.metadata_get(session, "endorser_info")
if value:
Expand Down Expand Up @@ -725,8 +740,10 @@ async def transaction_write(request: web.BaseRequest):
jobs = await connection_record.metadata_get(session, "transaction_jobs")
if not jobs:
raise web.HTTPForbidden(
reason="The transaction related jobs are not set up in "
"connection metadata for this connection record"
reason=(
"The transaction related jobs are not set up in "
"connection metadata for this connection record"
)
)
if jobs["transaction_my_job"] != TransactionJob.TRANSACTION_AUTHOR.name:
raise web.HTTPForbidden(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,43 @@ async def test_set_endorser_info(self):
}
)

async def test_set_endorser_info_no_prior_value(self):
self.request.match_info = {"conn_id": "dummy"}
self.request.query = {"endorser_did": "did", "endorser_name": "name"}
with async_mock.patch.object(
ConnRecord, "retrieve_by_id", async_mock.CoroutineMock()
) as mock_conn_rec_retrieve, async_mock.patch.object(
test_module.web, "json_response"
) as mock_response:
mock_conn_rec_retrieve.return_value = async_mock.MagicMock(
metadata_get=async_mock.CoroutineMock(
side_effect=[
{
"transaction_my_job": (
test_module.TransactionJob.TRANSACTION_AUTHOR.name
),
"transaction_their_job": (
test_module.TransactionJob.TRANSACTION_ENDORSER.name
),
},
None,
{
"endorser_did": "did",
"endorser_name": "name",
},
]
),
metadata_set=async_mock.CoroutineMock(),
)
await test_module.set_endorser_info(self.request)

mock_response.assert_called_once_with(
{
"endorser_did": "did",
"endorser_name": "name",
}
)

async def test_set_endorser_info_not_found_x(self):
self.request.match_info = {"conn_id": "dummy"}
self.request.query = {"endorser_did": "did", "endorser_name": "name"}
Expand Down