diff --git a/migrations/versions/0410_enums_for_everything.py b/migrations/versions/0410_enums_for_everything.py index 33ffec277..d385bfe69 100644 --- a/migrations/versions/0410_enums_for_everything.py +++ b/migrations/versions/0410_enums_for_everything.py @@ -581,7 +581,9 @@ def downgrade(): ) enum_create(values=["email", "sms", "letter"], name="notification_type") enum_create(values=["mobile", "email"], name="recipient_type") - enum_create(values=["sms", "email", "letter", "broadcast"], name="template_type") + enum_create( + values=["sms", "email", "letter", "broadcast"], name="template_type" + ) enum_create(values=["email", "sms"], name="verify_code_types") # Alter columns back diff --git a/tests/app/dao/test_annual_billing_dao.py b/tests/app/dao/test_annual_billing_dao.py index 383e42734..182d94efc 100644 --- a/tests/app/dao/test_annual_billing_dao.py +++ b/tests/app/dao/test_annual_billing_dao.py @@ -8,6 +8,7 @@ from app.dao.annual_billing_dao import ( set_default_free_allowance_for_service, ) from app.dao.date_util import get_current_calendar_year_start_year +from app.enums import OrganizationType from app.models import AnnualBilling from tests.app.db import create_annual_billing, create_service @@ -114,7 +115,7 @@ def test_set_default_free_allowance_for_service_updates_existing_year(sample_ser assert annual_billing[0].service_id == sample_service.id assert annual_billing[0].free_sms_fragment_limit == 150000 - sample_service.organization_type = "federal" + sample_service.organization_type = OrganizationType.FEDERAL set_default_free_allowance_for_service(service=sample_service, year_start=None) annual_billing = AnnualBilling.query.all() diff --git a/tests/app/dao/test_organization_dao.py b/tests/app/dao/test_organization_dao.py index dc958cbe1..497b4a74a 100644 --- a/tests/app/dao/test_organization_dao.py +++ b/tests/app/dao/test_organization_dao.py @@ -16,6 +16,7 @@ from app.dao.organization_dao import ( dao_get_users_for_organization, dao_update_organization, ) +from app.enums import OrganizationType from app.models import Organization, Service from tests.app.db import ( create_domain, @@ -62,7 +63,7 @@ def test_update_organization(notify_db_session): data = { "name": "new name", - "organization_type": "state", + "organization_type": OrganizationType.STATE, "agreement_signed": True, "agreement_signed_at": datetime.datetime.utcnow(), "agreement_signed_by_id": user.id, @@ -138,8 +139,8 @@ def test_update_organization_does_not_update_the_service_if_certain_attributes_n ): email_branding = create_email_branding() - sample_service.organization_type = "state" - sample_organization.organization_type = "federal" + sample_service.organization_type = OrganizationType.STATE + sample_organization.organization_type = OrganizationType.FEDERAL sample_organization.email_branding = email_branding sample_organization.services.append(sample_service) @@ -151,8 +152,8 @@ def test_update_organization_does_not_update_the_service_if_certain_attributes_n assert sample_organization.name == "updated org name" - assert sample_organization.organization_type == "federal" - assert sample_service.organization_type == "state" + assert sample_organization.organization_type == OrganizationType.FEDERAL + assert sample_service.organization_type == OrganizationType.STATE assert sample_organization.email_branding == email_branding assert sample_service.email_branding is None @@ -162,22 +163,22 @@ def test_update_organization_updates_the_service_org_type_if_org_type_is_provide sample_service, sample_organization, ): - sample_service.organization_type = "state" - sample_organization.organization_type = "state" + sample_service.organization_type = OrganizationType.STATE + sample_organization.organization_type = OrganizationType.STATE sample_organization.services.append(sample_service) db.session.commit() - dao_update_organization(sample_organization.id, organization_type="federal") + dao_update_organization(sample_organization.id, organization_type=OrganizationType.FEDERAL) - assert sample_organization.organization_type == "federal" - assert sample_service.organization_type == "federal" + assert sample_organization.organization_type == OrganizationType.FEDERAL + assert sample_service.organization_type == OrganizationType.FEDERAL assert ( Service.get_history_model() .query.filter_by(id=sample_service.id, version=2) .one() .organization_type - == "federal" + == OrganizationType.FEDERAL ) @@ -217,8 +218,8 @@ def test_update_organization_does_not_override_service_branding( def test_add_service_to_organization(sample_service, sample_organization): assert sample_organization.services == [] - sample_service.organization_type = "federal" - sample_organization.organization_type = "state" + sample_service.organization_type = OrganizationType.FEDERAL + sample_organization.organization_type = OrganizationType.STATE dao_add_service_to_organization(sample_service, sample_organization.id) diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index cf59d5287..44be3c50e 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -40,7 +40,7 @@ from app.dao.services_dao import ( get_services_by_partial_name, ) from app.dao.users_dao import create_user_code, save_model_user -from app.enums import KeyType +from app.enums import KeyType, OrganizationType from app.models import ( ApiKey, InvitedUser, @@ -85,7 +85,7 @@ def test_create_service(notify_db_session): email_from="email_from", message_limit=1000, restricted=False, - organization_type="federal", + organization_type=OrganizationType.FEDERAL, created_by=user, ) dao_create_service(service, user) @@ -97,7 +97,7 @@ def test_create_service(notify_db_session): assert service_db.prefix_sms is True assert service.active is True assert user in service_db.users - assert service_db.organization_type == "federal" + assert service_db.organization_type == OrganizationType.FEDERAL assert not service.organization_id @@ -105,7 +105,7 @@ def test_create_service_with_organization(notify_db_session): user = create_user(email="local.authority@local-authority.gov.uk") organization = create_organization( name="Some local authority", - organization_type="state", + organization_type=OrganizationType.STATE, domains=["local-authority.gov.uk"], ) assert Service.query.count() == 0 @@ -114,7 +114,7 @@ def test_create_service_with_organization(notify_db_session): email_from="email_from", message_limit=1000, restricted=False, - organization_type="federal", + organization_type=OrganizationType.FEDERAL, created_by=user, ) dao_create_service(service, user) @@ -127,7 +127,7 @@ def test_create_service_with_organization(notify_db_session): assert service_db.prefix_sms is True assert service.active is True assert user in service_db.users - assert service_db.organization_type == "state" + assert service_db.organization_type == OrganizationType.STATE assert service.organization_id == organization.id assert service.organization == organization @@ -136,7 +136,7 @@ def test_fetch_service_by_id_with_api_keys(notify_db_session): user = create_user(email="local.authority@local-authority.gov.uk") organization = create_organization( name="Some local authority", - organization_type="state", + organization_type=OrganizationType.STATE, domains=["local-authority.gov.uk"], ) assert Service.query.count() == 0 @@ -145,7 +145,7 @@ def test_fetch_service_by_id_with_api_keys(notify_db_session): email_from="email_from", message_limit=1000, restricted=False, - organization_type="federal", + organization_type=OrganizationType.FEDERAL, created_by=user, ) dao_create_service(service, user) @@ -158,7 +158,7 @@ def test_fetch_service_by_id_with_api_keys(notify_db_session): assert service_db.prefix_sms is True assert service.active is True assert user in service_db.users - assert service_db.organization_type == "state" + assert service_db.organization_type == OrganizationType.STATE assert service.organization_id == organization.id assert service.organization == organization @@ -491,7 +491,7 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user( @freeze_time("2019-04-23T10:00:00") def test_dao_fetch_live_services_data(sample_user): - org = create_organization(organization_type="federal") + org = create_organization(organization_type=OrganizationType.FEDERAL) service = create_service(go_live_user=sample_user, go_live_at="2014-04-20T10:00:00") sms_template = create_template(service=service) service_2 = create_service( @@ -530,7 +530,7 @@ def test_dao_fetch_live_services_data(sample_user): "service_id": mock.ANY, "service_name": "Sample service", "organization_name": "test_org_1", - "organization_type": "federal", + "organization_type": OrganizationType.FEDERAL, "consent_to_research": None, "contact_name": "Test User", "contact_email": "notify@digital.fake.gov", diff --git a/tests/app/db.py b/tests/app/db.py index 7f18de861..0306ac299 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -26,7 +26,7 @@ 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, RecipientType, ServicePermissionType, TemplateType +from app.enums import KeyType, OrganizationType, RecipientType, ServicePermissionType, TemplateType from app.models import ( AnnualBilling, ApiKey, @@ -107,7 +107,7 @@ def create_service( prefix_sms=True, message_limit=1000, total_message_limit=250000, - organization_type="federal", + organization_type=OrganizationType.FEDERAL, check_if_service_exists=False, go_live_user=None, go_live_at=None, diff --git a/tests/app/organization/test_rest.py b/tests/app/organization/test_rest.py index 25f25ec43..7c0548db9 100644 --- a/tests/app/organization/test_rest.py +++ b/tests/app/organization/test_rest.py @@ -11,6 +11,7 @@ from app.dao.organization_dao import ( dao_add_user_to_organization, ) from app.dao.services_dao import dao_archive_service +from app.enums import OrganizationType from app.models import AnnualBilling, Organization from tests.app.db import ( create_annual_billing, @@ -25,7 +26,7 @@ from tests.app.db import ( def test_get_all_organizations(admin_request, notify_db_session): - create_organization(name="inactive org", active=False, organization_type="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) @@ -52,7 +53,7 @@ def test_get_all_organizations(admin_request, notify_db_session): assert response[1]["active"] is False assert response[1]["count_of_live_services"] == 0 assert response[1]["domains"] == [] - assert response[1]["organization_type"] == "federal" + assert response[1]["organization_type"] == OrganizationType.FEDERAL def test_get_organization_by_id(admin_request, notify_db_session): @@ -163,7 +164,7 @@ def test_post_create_organization(admin_request, notify_db_session): data = { "name": "test organization", "active": True, - "organization_type": "state", + "organization_type": OrganizationType.STATE, } response = admin_request.post( @@ -213,7 +214,7 @@ def test_post_create_organization_existing_name_raises_400( data = { "name": sample_organization.name, "active": True, - "organization_type": "federal", + "organization_type": OrganizationType.FEDERAL, } response = admin_request.post( @@ -233,7 +234,7 @@ def test_post_create_organization_works(admin_request, sample_organization): data = { "name": "org 2", "active": True, - "organization_type": "federal", + "organization_type": OrganizationType.FEDERAL, } admin_request.post( @@ -251,7 +252,7 @@ def test_post_create_organization_works(admin_request, sample_organization): ( { "active": False, - "organization_type": "federal", + "organization_type": OrganizationType.FEDERAL, }, "name is a required property", ), @@ -295,7 +296,7 @@ def test_post_update_organization_updates_fields( data = { "name": "new organization name", "active": False, - "organization_type": "federal", + "organization_type": OrganizationType.FEDERAL, } admin_request.post( @@ -312,7 +313,7 @@ def test_post_update_organization_updates_fields( assert organization[0].name == data["name"] assert organization[0].active == data["active"] assert organization[0].domains == [] - assert organization[0].organization_type == "federal" + assert organization[0].organization_type == OrganizationType.FEDERAL @pytest.mark.parametrize( @@ -568,7 +569,7 @@ def test_post_update_organization_set_mou_emails_signed_by( def test_post_link_service_to_organization(admin_request, sample_service): data = {"service_id": str(sample_service.id)} - organization = create_organization(organization_type="federal") + organization = create_organization(organization_type=OrganizationType.FEDERAL) admin_request.post( "organization.link_service_to_organization", @@ -585,7 +586,7 @@ def test_post_link_service_to_organization_inserts_annual_billing( admin_request, sample_service ): data = {"service_id": str(sample_service.id)} - organization = create_organization(organization_type="federal") + organization = create_organization(organization_type=OrganizationType.FEDERAL) assert len(organization.services) == 0 assert len(AnnualBilling.query.all()) == 0 admin_request.post( @@ -610,7 +611,7 @@ def test_post_link_service_to_organization_rollback_service_if_annual_billing_up data = {"service_id": str(sample_service.id)} assert not sample_service.organization_type - organization = create_organization(organization_type="federal") + organization = create_organization(organization_type=OrganizationType.FEDERAL) assert len(organization.services) == 0 assert len(AnnualBilling.query.all()) == 0 with pytest.raises(expected_exception=SQLAlchemyError): @@ -641,7 +642,7 @@ def test_post_link_service_to_another_org( assert len(sample_organization.services) == 1 assert not sample_service.organization_type - new_org = create_organization(organization_type="federal") + new_org = create_organization(organization_type=OrganizationType.FEDERAL) admin_request.post( "organization.link_service_to_organization", _data=data, @@ -650,7 +651,7 @@ def test_post_link_service_to_another_org( ) assert not sample_organization.services assert len(new_org.services) == 1 - assert sample_service.organization_type == "federal" + assert sample_service.organization_type == OrganizationType.FEDERAL annual_billing = AnnualBilling.query.all() assert len(annual_billing) == 1 assert annual_billing[0].free_sms_fragment_limit == 150000 diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index c7cf7e87d..6957edfb1 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -14,7 +14,7 @@ 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, ServicePermissionType, TemplateType +from app.enums import KeyType, NotificationType, OrganizationType, ServicePermissionType, TemplateType from app.models import ( AnnualBilling, EmailBranding, @@ -684,7 +684,7 @@ def test_update_service(client, notify_db_session, sample_service): "email_from": "updated.service.name", "created_by": str(sample_service.created_by.id), "email_branding": str(brand.id), - "organization_type": "federal", + "organization_type": OrganizationType.FEDERAL, } auth_header = create_admin_authorization_header() @@ -699,7 +699,7 @@ def test_update_service(client, notify_db_session, sample_service): assert result["data"]["name"] == "updated service name" assert result["data"]["email_from"] == "updated.service.name" assert result["data"]["email_branding"] == str(brand.id) - assert result["data"]["organization_type"] == "federal" + assert result["data"]["organization_type"] == OrganizationType.FEDERAL def test_cant_update_service_org_type_to_random_value(client, sample_service): diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index 858039ee0..1032d6c69 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 +from app.enums import KeyType, NotificationStatus, NotificationType, OrganizationType from app.models import ( AnnualBilling, Job, @@ -251,7 +251,7 @@ def test_insert_inbound_numbers_from_file(notify_db_session, notify_api, tmpdir) @pytest.mark.parametrize( - "organization_type, expected_allowance", [("federal", 40000), ("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 @@ -274,7 +274,7 @@ def test_populate_annual_billing_with_defaults( @pytest.mark.parametrize( - "organization_type, expected_allowance", [("federal", 40000), ("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 @@ -328,7 +328,7 @@ def test_fix_billable_units(notify_db_session, notify_api, sample_template): def test_populate_annual_billing_with_defaults_sets_free_allowance_to_zero_if_previous_year_is_zero( notify_db_session, notify_api ): - service = create_service(organization_type="federal") + service = create_service(organization_type=OrganizationType.FEDERAL) create_annual_billing( service_id=service.id, free_sms_fragment_limit=0, financial_year_start=2021 )