diff --git a/app/commands.py b/app/commands.py index 8f5a8b15d..e36657812 100644 --- a/app/commands.py +++ b/app/commands.py @@ -49,7 +49,7 @@ from app.dao.users_dao import ( delete_user_verify_codes, get_user_by_email, ) -from app.enums import KeyType, NotificationStatus, NotificationType +from app.enums import AuthType, KeyType, NotificationStatus, NotificationType from app.models import ( AnnualBilling, Domain, @@ -238,7 +238,7 @@ def rebuild_ft_billing_for_day(service_id, day): "-a", "--auth_type", required=False, - help="The authentication type for the user, sms_auth or email_auth. Defaults to sms_auth if not provided", + help="The authentication type for the user, AuthType.SMS or AuthType.EMAIL. Defaults to AuthType.SMS if not provided", ) @click.option( "-p", "--permissions", required=True, help="Comma separated list of permissions." @@ -703,7 +703,7 @@ def validate_mobile(ctx, param, value): # noqa hide_input=True, confirmation_prompt=True, ) -@click.option("-a", "--auth_type", default="sms_auth") +@click.option("-a", "--auth_type", default=AuthType.SMS) @click.option("-s", "--state", default="active") @click.option("-d", "--admin", default=False, type=bool) def create_test_user(name, email, mobile_number, password, auth_type, state, admin): diff --git a/app/models.py b/app/models.py index e921ae97b..4f228ed17 100644 --- a/app/models.py +++ b/app/models.py @@ -155,7 +155,7 @@ class User(db.Model): # either email auth or a mobile number must be provided CheckConstraint( - "auth_type in ('email_auth', 'webauthn_auth') or mobile_number is not null" + "auth_type in (AuthType.EMAIL, AuthType.WEBAUTHN) or mobile_number is not null" ) services = db.relationship("Service", secondary="user_to_service", backref="users") @@ -182,7 +182,7 @@ class User(db.Model): if self.platform_admin: return True - if self.auth_type == "webauthn_auth": + if self.auth_type == AuthType.WEBAUTHN: return True return any( diff --git a/app/user/rest.py b/app/user/rest.py index 8ea746e4b..098d23de8 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -73,7 +73,7 @@ def handle_integrity_error(exc): return ( jsonify( result="error", - message="Mobile number must be set if auth_type is set to sms_auth", + message="Mobile number must be set if auth_type is set to AuthType.SMS", ), 400, ) diff --git a/app/webauthn/rest.py b/app/webauthn/rest.py index 97b7ab2ff..1dba333e7 100644 --- a/app/webauthn/rest.py +++ b/app/webauthn/rest.py @@ -62,9 +62,10 @@ def delete_webauthn_credential(user_id, webauthn_credential_id): user = get_user_by_id(user_id) if len(user.webauthn_credentials) == 1: - # TODO: Only raise an error if user has auth type webauthn_auth + # TODO: Only raise an error if user has auth type AuthType.WEBAUTHN raise InvalidRequest( - "Cannot delete last remaining webauthn credential for user", status_code=400 + "Cannot delete last remaining webauthn credential for user", + status_code=400, ) dao_delete_webauthn_credential(webauthn_credential) diff --git a/tests/app/dao/test_organization_dao.py b/tests/app/dao/test_organization_dao.py index 497b4a74a..a03b5fa8a 100644 --- a/tests/app/dao/test_organization_dao.py +++ b/tests/app/dao/test_organization_dao.py @@ -169,7 +169,9 @@ def test_update_organization_updates_the_service_org_type_if_org_type_is_provide sample_organization.services.append(sample_service) db.session.commit() - dao_update_organization(sample_organization.id, organization_type=OrganizationType.FEDERAL) + dao_update_organization( + sample_organization.id, organization_type=OrganizationType.FEDERAL + ) assert sample_organization.organization_type == OrganizationType.FEDERAL assert sample_service.organization_type == OrganizationType.FEDERAL diff --git a/tests/app/db.py b/tests/app/db.py index 0306ac299..06faf39c6 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -26,7 +26,13 @@ from app.dao.service_sms_sender_dao import ( from app.dao.services_dao import dao_add_user_to_service, dao_create_service from app.dao.templates_dao import dao_create_template, dao_update_template from app.dao.users_dao import save_model_user -from app.enums import KeyType, OrganizationType, RecipientType, ServicePermissionType, TemplateType +from app.enums import ( + KeyType, + OrganizationType, + RecipientType, + ServicePermissionType, + TemplateType, +) from app.models import ( AnnualBilling, ApiKey, diff --git a/tests/app/organization/test_rest.py b/tests/app/organization/test_rest.py index 7c0548db9..74bf7ac71 100644 --- a/tests/app/organization/test_rest.py +++ b/tests/app/organization/test_rest.py @@ -26,7 +26,9 @@ from tests.app.db import ( def test_get_all_organizations(admin_request, notify_db_session): - create_organization(name="inactive org", active=False, organization_type=OrganizationType.FEDERAL) + create_organization( + name="inactive org", active=False, organization_type=OrganizationType.FEDERAL + ) create_organization(name="active org", domains=["example.com"]) response = admin_request.get("organization.get_organizations", _expected_status=200) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 6957edfb1..51de304dc 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -14,7 +14,13 @@ from app.dao.service_user_dao import dao_get_service_user from app.dao.services_dao import dao_add_user_to_service, dao_remove_user_from_service from app.dao.templates_dao import dao_redact_template from app.dao.users_dao import save_model_user -from app.enums import KeyType, NotificationType, OrganizationType, ServicePermissionType, TemplateType +from app.enums import ( + KeyType, + NotificationType, + OrganizationType, + ServicePermissionType, + TemplateType, +) from app.models import ( AnnualBilling, EmailBranding, diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index 1032d6c69..0d6fe2dfb 100644 --- a/tests/app/test_commands.py +++ b/tests/app/test_commands.py @@ -20,7 +20,7 @@ from app.commands import ( ) from app.dao.inbound_numbers_dao import dao_get_available_inbound_numbers from app.dao.users_dao import get_user_by_email -from app.enums import KeyType, NotificationStatus, NotificationType, OrganizationType +from app.enums import KeyType, NotificationStatus, NotificationType, OrganizationType, TemplateType from app.models import ( AnnualBilling, Job, @@ -91,7 +91,7 @@ def test_purge_functional_test_data_bad_mobile(notify_db_session, notify_api): def test_update_jobs_archived_flag(notify_db_session, notify_api): service = create_service() - sms_template = create_template(service=service, template_type="sms") + sms_template = create_template(service=service, template_type=TemplateType.SMS) create_job(sms_template) right_now = datetime.datetime.utcnow() @@ -251,13 +251,14 @@ def test_insert_inbound_numbers_from_file(notify_db_session, notify_api, tmpdir) @pytest.mark.parametrize( - "organization_type, expected_allowance", [(OrganizationType.FEDERAL, 40000), (OrganizationType.STATE, 40000)] + "organization_type, expected_allowance", + [(OrganizationType.FEDERAL, 40000), (OrganizationType.STATE, 40000)], ) def test_populate_annual_billing_with_defaults( notify_db_session, notify_api, organization_type, expected_allowance ): service = create_service( - service_name=organization_type, organization_type=organization_type + service_name=organization_type.value, organization_type=organization_type ) notify_api.test_cli_runner().invoke( @@ -274,13 +275,14 @@ def test_populate_annual_billing_with_defaults( @pytest.mark.parametrize( - "organization_type, expected_allowance", [(OrganizationType.FEDERAL, 40000), (OrganizationType.STATE, 40000)] + "organization_type, expected_allowance", + [(OrganizationType.FEDERAL, 40000), (OrganizationType.STATE, 40000)], ) def test_populate_annual_billing_with_the_previous_years_allowance( notify_db_session, notify_api, organization_type, expected_allowance ): service = create_service( - service_name=organization_type, organization_type=organization_type + service_name=organization_type.value, organization_type=organization_type ) notify_api.test_cli_runner().invoke(