Merge pull request #3510 from alphagov/nhs_branding_default_for_nhs_org

When creating a new NHS org, set default email branding to NHS
This commit is contained in:
Pea Tyczynska
2022-04-19 15:33:03 +01:00
committed by GitHub
5 changed files with 118 additions and 4 deletions

View File

@@ -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):
"""

View File

@@ -502,13 +502,17 @@ def create_service_callback_api(
return service_callback_api
def create_email_branding(colour='blue', logo='test_x2.png', name='test_org_1', text='DisplayName'):
def create_email_branding(
id=None, colour='blue', logo='test_x2.png', name='test_org_1', text='DisplayName'
):
data = {
'colour': colour,
'logo': logo,
'name': name,
'text': text,
}
if id:
data['id'] = id
email_branding = EmailBranding(**data)
dao_create_email_branding(email_branding)
@@ -671,6 +675,7 @@ def create_organisation(
billing_contact_names=None,
billing_contact_email_addresses=None,
billing_reference=None,
email_branding_id=None,
):
data = {
'id': organisation_id,
@@ -681,6 +686,7 @@ def create_organisation(
'billing_contact_names': billing_contact_names,
'billing_contact_email_addresses': billing_contact_email_addresses,
'billing_reference': billing_reference,
'email_branding_id': email_branding_id
}
organisation = Organisation(**data)
dao_create_organisation(organisation)

View File

@@ -2,6 +2,7 @@ import uuid
from datetime import datetime
import pytest
from flask import current_app
from freezegun import freeze_time
from sqlalchemy.exc import SQLAlchemyError
@@ -177,14 +178,39 @@ def test_post_create_organisation(admin_request, notify_db_session, crown):
_expected_status=201
)
organisation = Organisation.query.all()
organisations = Organisation.query.all()
assert data['name'] == response['name']
assert data['active'] == response['active']
assert data['crown'] == response['crown']
assert data['organisation_type'] == response['organisation_type']
assert len(organisation) == 1
assert len(organisations) == 1
# check that for non-nhs orgs, default branding is not set
assert organisations[0].email_branding_id is None
@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, nhs_email_branding, org_type
):
data = {
'name': 'test organisation',
'active': True,
'crown': False,
'organisation_type': org_type,
}
admin_request.post(
'organisation.create_organisation',
_data=data,
_expected_status=201
)
organisations = Organisation.query.all()
assert len(organisations) == 1
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):
@@ -344,6 +370,64 @@ 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
):
org = create_organisation(organisation_type='central')
data = {
'organisation_type': new_org_type,
}
admin_request.post(
'organisation.update_organisation',
_data=data,
organisation_id=org.id,
_expected_status=204
)
organisation = Organisation.query.all()
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(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
):
current_branding = create_email_branding(
logo='example.png',
name='custom branding'
)
org = create_organisation(organisation_type='central', email_branding_id=current_branding.id)
data = {
'organisation_type': new_org_type,
}
admin_request.post(
'organisation.update_organisation',
_data=data,
organisation_id=org.id,
_expected_status=204
)
organisation = Organisation.query.all()
assert len(organisation) == 1
assert organisation[0].id == org.id
assert organisation[0].organisation_type == new_org_type
assert organisation[0].email_branding_id == current_branding.id
def test_update_organisation_default_branding(
admin_request,
notify_db_session,