def test_update_organisation_does_not_override_service_branding( sample_service, sample_organisation, ): email_branding = create_email_branding() custom_email_branding = create_email_branding(name='custom') letter_branding = create_letter_branding() custom_letter_branding = create_letter_branding(name='custom', filename='custom') sample_service.email_branding = custom_email_branding sample_service.letter_branding = custom_letter_branding sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id) dao_update_organisation(sample_organisation.id, letter_branding_id=letter_branding.id) assert sample_organisation.email_branding == email_branding assert sample_organisation.letter_branding == letter_branding assert sample_service.email_branding == custom_email_branding assert sample_service.letter_branding == custom_letter_branding
def test_get_email_branding_options_gets_all_email_branding(notify_db, notify_db_session): email_branding_1 = create_email_branding(name='test_email_branding_1') email_branding_2 = create_email_branding(name='test_email_branding_2') email_branding = dao_get_email_branding_options() assert len(email_branding) == 2 assert email_branding_1 == email_branding[0] assert email_branding_2 == email_branding[1]
def test_update_email_branding(notify_db, notify_db_session): updated_name = "new name" create_email_branding() email_branding = EmailBranding.query.all() assert len(email_branding) == 1 assert email_branding[0].name != updated_name dao_update_email_branding(email_branding[0], name=updated_name) email_branding = EmailBranding.query.all() assert len(email_branding) == 1 assert email_branding[0].name == updated_name
def test_create_nhs_service_get_default_branding_based_on_email_address( notify_db_session, branding_name_to_create, expected_branding, email_address, organisation_type, ): user = create_user(email=email_address) letter_branding = create_letter_branding(name=branding_name_to_create) email_branding = create_email_branding(name=branding_name_to_create) service = Service( name="service_name", email_from="email_from", message_limit=1000, restricted=False, organisation_type=organisation_type, created_by=user, ) dao_create_service(service, user) service_db = Service.query.one() if expected_branding: assert service_db.letter_branding == letter_branding assert service_db.email_branding == email_branding else: assert service_db.letter_branding is None assert service_db.email_branding is None
def test_update_organisation(notify_db_session): create_organisation() organisation = Organisation.query.one() user = create_user() email_branding = create_email_branding() letter_branding = create_letter_branding() data = { 'name': 'new name', "crown": True, "organisation_type": 'local', "agreement_signed": True, "agreement_signed_at": datetime.datetime.utcnow(), "agreement_signed_by_id": user.id, "agreement_signed_version": 999.99, "letter_branding_id": letter_branding.id, "email_branding_id": email_branding.id, } for attribute, value in data.items(): assert getattr(organisation, attribute) != value assert organisation.updated_at is None dao_update_organisation(organisation.id, **data) organisation = Organisation.query.one() for attribute, value in data.items(): assert getattr(organisation, attribute) == value assert organisation.updated_at
def test_get_email_branding_by_name_gets_correct_email_branding( notify_db, notify_db_session): email_branding = create_email_branding(name="Crystal Gems") email_branding_from_db = dao_get_email_branding_by_name("Crystal Gems") assert email_branding_from_db == email_branding
def test_get_email_branding_by_id_gets_correct_email_branding( notify_db, notify_db_session): email_branding = create_email_branding() email_branding_from_db = dao_get_email_branding_by_id(email_branding.id) assert email_branding_from_db == email_branding
def test_update_organisation_does_not_update_the_service_if_certain_attributes_not_provided( sample_service, sample_organisation, ): email_branding = create_email_branding() letter_branding = create_letter_branding() sample_service.organisation_type = 'local' sample_organisation.organisation_type = 'central' sample_organisation.email_branding = email_branding sample_organisation.letter_branding = letter_branding sample_organisation.services.append(sample_service) db.session.commit() assert sample_organisation.name == 'sample organisation' dao_update_organisation(sample_organisation.id, name='updated org name') assert sample_organisation.name == 'updated org name' assert sample_organisation.organisation_type == 'central' assert sample_service.organisation_type == 'local' assert sample_organisation.email_branding == email_branding assert sample_service.email_branding is None assert sample_organisation.letter_branding == letter_branding assert sample_service.letter_branding is None
def test_update_organisation_default_branding( admin_request, notify_db_session, ): org = create_organisation(name="Test Organisation") email_branding = create_email_branding() letter_branding = create_letter_branding() assert org.email_branding is None assert org.letter_branding is None admin_request.post( "organisation.update_organisation", _data={ "email_branding_id": str(email_branding.id), "letter_branding_id": str(letter_branding.id), }, organisation_id=org.id, _expected_status=204, ) assert org.email_branding == email_branding assert org.letter_branding == letter_branding
def test_update_email_branding_reject_invalid_brand_type( admin_request, notify_db_session): email_branding = create_email_branding() data = {'brand_type': 'NOT A TYPE'} response = admin_request.post('email_branding.update_email_branding', _data=data, _expected_status=400, email_branding_id=email_branding.id) expect = 'brand_type NOT A TYPE is not one of [org, both, org_banner, no_branding]' assert response['errors'][0]['message'] == expect
def test_update_email_branding_reject_invalid_brand_type( admin_request, notify_db_session): email_branding = create_email_branding() data = {'brand_type': 'NOT A TYPE'} response = admin_request.post('email_branding.update_email_branding', _data=data, _expected_status=400, email_branding_id=email_branding.id) expect = 'brand_type NOT A TYPE is not one of '\ '[custom_logo, both_english, both_french, custom_logo_with_background_colour, no_branding]' assert response['errors'][0]['message'] == expect
def test_update_email_branding_reject_invalid_brand_type( admin_request, notify_db_session): email_branding = create_email_branding() data = {"brand_type": "NOT A TYPE"} response = admin_request.post( "email_branding.update_email_branding", _data=data, _expected_status=400, email_branding_id=email_branding.id, ) expect = ( "brand_type NOT A TYPE is not one of " "[custom_logo, both_english, both_french, custom_logo_with_background_colour, no_branding]" ) assert response["errors"][0]["message"] == expect
def test_update_organisation_updates_the_service_branding_if_branding_is_provided( sample_service, sample_organisation, ): email_branding = create_email_branding() letter_branding = create_letter_branding() sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id) dao_update_organisation(sample_organisation.id, letter_branding_id=letter_branding.id) assert sample_organisation.email_branding == email_branding assert sample_organisation.letter_branding == letter_branding assert sample_service.email_branding == email_branding assert sample_service.letter_branding == letter_branding
def test_get_html_email_options_add_email_branding_from_service( sample_service): branding = create_email_branding() sample_service.email_branding = branding email_options = get_html_email_options(sample_service) assert email_options is not None assert email_options == { 'govuk_banner': branding.brand_type == BRANDING_BOTH, 'brand_banner': branding.brand_type == BRANDING_ORG_BANNER, 'brand_colour': branding.colour, 'brand_logo': get_logo_url(current_app.config['ADMIN_BASE_URL'], branding.logo), 'brand_text': branding.text, 'brand_name': branding.name, }
def test_email_branding_has_no_domain(notify_db, notify_db_session): create_email_branding() email_branding = EmailBranding.query.all() assert not hasattr(email_branding, "domain")