From ef515400f3870a3a428121611dda253c966ae414 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 22 Mar 2019 15:38:28 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20automatic=20inheritance=20of=20org?= =?UTF-8?q?=E2=80=99s=20branding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When creating a service it should inherit it’s organisation’s branding, if that organisation has branding. This wasn’t working because we were referring to the ID of the branding when making the association, not the branding itself. --- app/dao/services_dao.py | 8 ++++---- tests/app/service/test_rest.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 4bef1e99c..dae5f4f82 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -194,11 +194,11 @@ def dao_create_service( service.organisation = organisation - if organisation.email_branding_id: - service.email_branding = organisation.email_branding_id + if organisation.email_branding: + service.email_branding = organisation.email_branding - if organisation.letter_branding_id and not service.letter_branding: - service.letter_branding = organisation.letter_branding_id + if organisation.letter_branding and not service.letter_branding: + service.letter_branding = organisation.letter_branding db.session.add(service) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 80d4eff42..d8032cfbb 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -49,6 +49,7 @@ from tests.app.db import ( create_letter_branding, create_organisation, create_domain, + create_email_branding, ) from tests.app.db import create_user @@ -306,6 +307,37 @@ def test_create_service_with_domain_sets_organisation( assert json_resp['data']['organisation'] is None +def test_create_service_inherits_branding_from_organisation( + admin_request, + sample_user, +): + + org = create_organisation() + email_branding = create_email_branding() + org.email_branding = email_branding + letter_branding = create_letter_branding() + org.letter_branding = letter_branding + create_domain('example.gov.uk', org.id) + sample_user.email_address = 'test@example.gov.uk' + + json_resp = admin_request.post( + 'service.create_service', + _data={ + 'name': 'created service', + 'user_id': str(sample_user.id), + 'message_limit': 1000, + 'restricted': False, + 'active': False, + 'email_from': 'created.service', + 'created_by': str(sample_user.id), + }, + _expected_status=201 + ) + + assert json_resp['data']['email_branding'] == str(email_branding.id) + assert json_resp['data']['letter_branding'] == str(letter_branding.id) + + def test_create_service_with_domain_sets_letter_branding(admin_request, sample_user): letter_branding = create_letter_branding( name='test domain', filename='test-domain', domain='test.domain'