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

feat: digital credentials queue helper tests #2334

Merged
merged 4 commits into from
Nov 28, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def issue_digital_credential(business: Business, user: User, credential_type: DC
digital_credentials.business_schema_id,
digital_credentials.business_cred_def_id)):
# pylint: disable=broad-exception-raised
raise Exception(f'Definition not found for credential type: {credential_type}')
raise Exception(f'Definition not found for credential type: {credential_type}.')

# pylint: disable=superfluous-parens
if not (connection := DCConnection.find_active_by(business_id=business.id)):
Expand Down Expand Up @@ -129,7 +129,7 @@ def replace_issued_digital_credential(business: Business,
if not (issued_business_user_credential := DCIssuedBusinessUserCredential.find_by_id(
dc_issued_business_user_id=issued_credential.credential_id)):
# pylint: disable=broad-exception-raised
raise Exception('Unable to find buisness user for issued credential.')
raise Exception('Unable to find business user for issued credential.')

if not (user := User.find_by_id(issued_business_user_credential.user_id)): # pylint: disable=superfluous-parens
# pylint: disable=broad-exception-raised
Expand Down
55 changes: 54 additions & 1 deletion queue_services/entity-digital-credentials/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""The Unit Tests and the helper routines."""

from legal_api.models import Business, Filing
from legal_api.models import Business, DCConnection, DCDefinition, DCIssuedCredential, Filing
from sqlalchemy_continuum import versioning_manager


Expand Down Expand Up @@ -47,3 +47,56 @@ def create_filing(session, business_id=None,

filing.save()
return filing


def create_dc_definition():
"""Create new dc_definition object."""
definition = DCDefinition(
credential_type=DCDefinition.CredentialType.business.name,
schema_name='test_business_schema',
schema_version='1.0.0',
schema_id='test_schema_id',
credential_definition_id='test_credential_definition_id'
)
definition.save()
return definition


def create_dc_connection(business, is_active=False):
"""Create new dc_connection object."""
connection = DCConnection(
connection_id='0d94e18b-3a52-4122-8adf-33e2ccff681f',
invitation_url="""http://192.168.65.3:8020?c_i=eyJAdHlwZSI6ICJodHRwczovL2RpZGNvbW0ub3JnL2Nvbm5lY3Rpb
25zLzEuMC9pbnZpdGF0aW9uIiwgIkBpZCI6ICIyZjU1M2JkZS01YWJlLTRkZDctODIwZi1mNWQ2Mjc1OWQxODgi
LCAicmVjaXBpZW50S2V5cyI6IFsiMkFHSjVrRDlVYU45OVpSeUFHZVZKNDkxclZhNzZwZGZYdkxXZkFyc2lKWjY
iXSwgImxhYmVsIjogImZhYmVyLmFnZW50IiwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwOi8vMTkyLjE2OC42NS4zOjgwMjAifQ==""",
is_active=is_active,
connection_state='active' if is_active else 'invitation',
business_id=business.id
)
connection.save()
return connection


def create_dc_issued_credential(business=None,
credential_exchange_id='test_credential_exchange_id',
credential_revocation_id='123',
revocation_registry_id='123',
is_issued=True, is_revoked=False):
"""Create new dc_issued_credential object."""
if not business:
identifier = 'FM1234567'
business = create_business(identifier)
definition = create_dc_definition()
connection = create_dc_connection(business, is_active=True)
issued_credential = DCIssuedCredential(
dc_definition_id=definition.id,
dc_connection_id=connection.id,
credential_exchange_id=credential_exchange_id,
credential_revocation_id=credential_revocation_id,
revocation_registry_id=revocation_registry_id,
is_issued=is_issued,
is_revoked=is_revoked
)
issued_credential.save()
return issued_credential
Loading
Loading