Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Akiff Manji <amanji@petridish.dev>
  • Loading branch information
amanji committed Oct 31, 2023
1 parent c55cebc commit 8ad8cb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def send_credential(identifier, credential_type):
response = digital_credentials.issue_credential(
connection_id=connection.connection_id,
definition=definition,
data=_get_data_for_credential(definition.credential_type, business, user)
data=credential_data
)
if not response:
return jsonify({'message': 'Failed to issue credential.'}), HTTPStatus.INTERNAL_SERVER_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from unittest.mock import patch

from legal_api.services.authz import BASIC_USER
from legal_api.models import DCDefinition
from legal_api.models import DCDefinition, User
from legal_api.services.digital_credentials import DigitalCredentialsService

from tests.unit.models import factory_business
Expand Down Expand Up @@ -89,17 +89,20 @@ def test_send_credential(session, client, jwt): # pylint:disable=unused-argumen
headers = create_header(jwt, [BASIC_USER])
identifier = 'FM1234567'
business = factory_business(identifier)

create_dc_definition()
definition = create_dc_definition()
test_user = User(username='test-user', firstname='test', lastname='test')
test_user.save()
create_dc_connection(business, is_active=True)
cred_ex_id = '3fa85f64-5717-4562-b3fc-2c963f66afa6'

with patch.object(DigitalCredentialsService, 'issue_credential', return_value={
'cred_ex_id': '3fa85f64-5717-4562-b3fc-2c963f66afa6'}):
rv = client.post(
f'/api/v2/businesses/{identifier}/digitalCredentials/{DCDefinition.CredentialType.business.name}',
headers=headers, content_type=content_type)
assert rv.status_code == HTTPStatus.OK
assert rv.json.get('message') == 'Credential offer has been sent.'
with patch.object(User, 'find_by_jwt_token', return_value=test_user):
with patch.object(DCDefinition, 'find_by', return_value=definition):
with patch.object(DigitalCredentialsService, 'issue_credential', return_value={'cred_ex_id': cred_ex_id}):
rv = client.post(
f'/api/v2/businesses/{identifier}/digitalCredentials/{DCDefinition.CredentialType.business.name}',
headers=headers, content_type=content_type)
assert rv.status_code == HTTPStatus.OK
assert rv.json.get('credentialExchangeId') == cred_ex_id


def test_get_issued_credentials(session, client, jwt): # pylint:disable=unused-argument
Expand Down

0 comments on commit 8ad8cb9

Please sign in to comment.