From 124562b50af90c0ec9a8436c592a414fb075af48 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 19 Apr 2022 12:25:11 +0100 Subject: [PATCH] Refactor creating nhs branding in tests into a fixture --- tests/app/conftest.py | 14 ++++++++++++ tests/app/organisation/test_rest.py | 35 +++++------------------------ 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/tests/app/conftest.py b/tests/app/conftest.py index c8653e75f..71ab86795 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -53,6 +53,7 @@ from app.models import ( from tests import create_admin_authorization_header from tests.app.db import ( create_api_key, + create_email_branding, create_inbound_number, create_invited_org_user, create_job, @@ -919,6 +920,19 @@ def broadcast_organisation(notify_db_session): return org +@pytest.fixture +def nhs_email_branding(notify_db_session): + # we wipe email_branding table in test db between the tests, so we have to recreate this branding + # that is normally present on all environments and applied through migration + nhs_email_branding_id = current_app.config['NHS_EMAIL_BRANDING_ID'] + + return create_email_branding( + id=nhs_email_branding_id, + logo='1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png', + name='NHS' + ) + + @pytest.fixture def restore_provider_details(notify_db, notify_db_session): """ diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index 1eef23ae8..478571edc 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -192,17 +192,8 @@ def test_post_create_organisation(admin_request, notify_db_session, crown): @pytest.mark.parametrize('org_type', ["nhs_central", "nhs_local", "nhs_gp"]) def test_post_create_organisation_sets_default_nhs_branding_for_nhs_orgs( - admin_request, notify_db_session, org_type + admin_request, notify_db_session, nhs_email_branding, org_type ): - # we wipe email_branding table in test db between the tests, so we have to recreate this branding - # that is normally present on all environments and applied through migration - nhs_email_branding_id = current_app.config['NHS_EMAIL_BRANDING_ID'] - create_email_branding( - id=nhs_email_branding_id, - logo='1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png', - name='NHS' - ) - data = { 'name': 'test organisation', 'active': True, @@ -219,7 +210,7 @@ def test_post_create_organisation_sets_default_nhs_branding_for_nhs_orgs( organisations = Organisation.query.all() assert len(organisations) == 1 - assert organisations[0].email_branding_id == uuid.UUID(nhs_email_branding_id) + assert organisations[0].email_branding_id == uuid.UUID(current_app.config['NHS_EMAIL_BRANDING_ID']) def test_post_create_organisation_existing_name_raises_400(admin_request, sample_organisation): @@ -382,18 +373,10 @@ def test_update_other_organisation_attributes_doesnt_clear_domains( @pytest.mark.parametrize('new_org_type', ["nhs_central", "nhs_local", "nhs_gp"]) def test_post_update_organisation_to_nhs_type_updates_branding_if_none_present( admin_request, + nhs_email_branding, notify_db_session, new_org_type ): - # we wipe email_branding table in test db between the tests, so we have to recreate this branding - # that is normally present on all environments and applied through migration - nhs_email_branding_id = current_app.config['NHS_EMAIL_BRANDING_ID'] - create_email_branding( - id=nhs_email_branding_id, - logo='1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png', - name='NHS' - ) - org = create_organisation(organisation_type='central') data = { 'organisation_type': new_org_type, @@ -411,24 +394,16 @@ def test_post_update_organisation_to_nhs_type_updates_branding_if_none_present( assert len(organisation) == 1 assert organisation[0].id == org.id assert organisation[0].organisation_type == new_org_type - assert organisation[0].email_branding_id == uuid.UUID(nhs_email_branding_id) + assert organisation[0].email_branding_id == uuid.UUID(current_app.config['NHS_EMAIL_BRANDING_ID']) @pytest.mark.parametrize('new_org_type', ["nhs_central", "nhs_local", "nhs_gp"]) def test_post_update_organisation_to_nhs_type_does_not_update_branding_if_default_branding_set( admin_request, + nhs_email_branding, notify_db_session, new_org_type ): - # we wipe email_branding table in test db between the tests, so we have to recreate this branding - # that is normally present on all environment and applied through migration - nhs_email_branding_id = current_app.config['NHS_EMAIL_BRANDING_ID'] - create_email_branding( - id=nhs_email_branding_id, - logo='1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png', - name='NHS' - ) - current_branding = create_email_branding( logo='example.png', name='custom branding'