mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Merge pull request #589 from alphagov/org-rendering
Render organisational branding in emails
This commit is contained in:
@@ -16,7 +16,16 @@ from app.clients.sms import SmsClientException
|
||||
from app.dao import notifications_dao, provider_details_dao
|
||||
from app.dao import provider_statistics_dao
|
||||
from app.dao.provider_statistics_dao import get_provider_statistics
|
||||
from app.models import Notification, NotificationStatistics, Job, KEY_TYPE_NORMAL, KEY_TYPE_TEST
|
||||
from app.models import (
|
||||
Notification,
|
||||
NotificationStatistics,
|
||||
Job,
|
||||
Organisation,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEST,
|
||||
BRANDING_ORG,
|
||||
BRANDING_BOTH
|
||||
)
|
||||
from tests.app.conftest import sample_notification
|
||||
|
||||
|
||||
@@ -503,6 +512,44 @@ def test_should_not_set_billable_units_if_research_mode(notify_db, sample_servic
|
||||
assert persisted_notification.billable_units == 0
|
||||
|
||||
|
||||
def test_get_html_email_renderer_should_return_for_normal_service(sample_service):
|
||||
renderer = provider_tasks.get_html_email_renderer(sample_service)
|
||||
assert renderer.govuk_banner
|
||||
assert renderer.brand_colour is None
|
||||
assert renderer.brand_logo is None
|
||||
assert renderer.brand_name is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('branding_type, govuk_banner', [
|
||||
(BRANDING_ORG, False),
|
||||
(BRANDING_BOTH, True)
|
||||
])
|
||||
def test_get_html_email_renderer_with_branding_details(branding_type, govuk_banner, notify_db, sample_service):
|
||||
sample_service.branding = branding_type
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.organisation = org
|
||||
notify_db.session.add_all([sample_service, org])
|
||||
notify_db.session.commit()
|
||||
|
||||
renderer = provider_tasks.get_html_email_renderer(sample_service)
|
||||
|
||||
assert renderer.govuk_banner == govuk_banner
|
||||
assert renderer.brand_colour == '000000'
|
||||
assert renderer.brand_name == 'Justice League'
|
||||
|
||||
|
||||
def test_get_html_email_renderer_prepends_logo_path(notify_db, sample_service):
|
||||
sample_service.branding = BRANDING_ORG
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.organisation = org
|
||||
notify_db.session.add_all([sample_service, org])
|
||||
notify_db.session.commit()
|
||||
|
||||
renderer = provider_tasks.get_html_email_renderer(sample_service)
|
||||
|
||||
assert renderer.brand_logo == 'http://localhost:6012/static/images/email-template/crests/justice-league.png'
|
||||
|
||||
|
||||
def _get_provider_statistics(service, **kwargs):
|
||||
query = ProviderStatistics.query.filter_by(service=service)
|
||||
if 'providers' in kwargs:
|
||||
|
||||
@@ -7,7 +7,7 @@ from freezegun import freeze_time
|
||||
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.dao.services_dao import dao_remove_user_from_service
|
||||
from app.models import User
|
||||
from app.models import User, Organisation
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import (
|
||||
sample_service as create_sample_service,
|
||||
@@ -108,6 +108,8 @@ def test_get_service_by_id(notify_api, sample_service):
|
||||
assert json_resp['data']['name'] == sample_service.name
|
||||
assert json_resp['data']['id'] == str(sample_service.id)
|
||||
assert not json_resp['data']['research_mode']
|
||||
assert json_resp['data']['organisation'] is None
|
||||
assert json_resp['data']['branding'] == 'govuk'
|
||||
|
||||
|
||||
def test_get_service_by_id_should_404_if_no_service(notify_api, notify_db):
|
||||
@@ -339,7 +341,11 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email
|
||||
assert "Duplicate service name '{}'".format(service_name) in json_resp['message']['name']
|
||||
|
||||
|
||||
def test_update_service(notify_api, sample_service):
|
||||
def test_update_service(notify_api, notify_db, sample_service):
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
notify_db.session.add(org)
|
||||
notify_db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
@@ -354,7 +360,8 @@ def test_update_service(notify_api, sample_service):
|
||||
data = {
|
||||
'name': 'updated service name',
|
||||
'email_from': 'updated.service.name',
|
||||
'created_by': str(sample_service.created_by.id)
|
||||
'created_by': str(sample_service.created_by.id),
|
||||
'organisation': str(org.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
@@ -368,6 +375,7 @@ def test_update_service(notify_api, sample_service):
|
||||
assert resp.status_code == 200
|
||||
assert result['data']['name'] == 'updated service name'
|
||||
assert result['data']['email_from'] == 'updated.service.name'
|
||||
assert result['data']['organisation'] == str(org.id)
|
||||
|
||||
|
||||
def test_update_service_research_mode(notify_api, sample_service):
|
||||
|
||||
Reference in New Issue
Block a user