mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 05:28:49 -04:00
Merge pull request #1989 from alphagov/email_branding_name_and_text
Email branding name and text
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from app.dao.email_branding_dao import (
|
||||
dao_get_email_branding_options,
|
||||
dao_get_email_branding_by_id,
|
||||
dao_get_email_branding_by_name,
|
||||
dao_update_email_branding,
|
||||
)
|
||||
from app.models import EmailBranding
|
||||
@@ -27,6 +28,14 @@ def test_get_email_branding_by_id_gets_correct_email_branding(notify_db, notify_
|
||||
assert email_branding_from_db == email_branding
|
||||
|
||||
|
||||
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_update_email_branding(notify_db, notify_db_session):
|
||||
updated_name = 'new name'
|
||||
create_email_branding()
|
||||
|
||||
@@ -329,11 +329,12 @@ def create_service_callback_api(
|
||||
return service_callback_api
|
||||
|
||||
|
||||
def create_email_branding(colour='blue', logo='test_x2.png', name='test_org_1'):
|
||||
def create_email_branding(colour='blue', logo='test_x2.png', name='test_org_1', text='DisplayName'):
|
||||
data = {
|
||||
'colour': colour,
|
||||
'logo': logo,
|
||||
'name': name
|
||||
'name': name,
|
||||
'text': text,
|
||||
}
|
||||
email_branding = EmailBranding(**data)
|
||||
dao_create_email_branding(email_branding)
|
||||
|
||||
@@ -22,7 +22,7 @@ def test_get_email_branding_options(admin_request, notify_db, notify_db_session)
|
||||
|
||||
|
||||
def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session):
|
||||
email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='My Org')
|
||||
email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Some Org', text='My Org')
|
||||
notify_db.session.add(email_branding)
|
||||
notify_db.session.commit()
|
||||
|
||||
@@ -32,10 +32,11 @@ def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session):
|
||||
email_branding_id=email_branding.id
|
||||
)
|
||||
|
||||
assert set(response['email_branding'].keys()) == {'colour', 'logo', 'name', 'id'}
|
||||
assert set(response['email_branding'].keys()) == {'colour', 'logo', 'name', 'id', 'text'}
|
||||
assert response['email_branding']['colour'] == '#FFFFFF'
|
||||
assert response['email_branding']['logo'] == '/path/image.png'
|
||||
assert response['email_branding']['name'] == 'My Org'
|
||||
assert response['email_branding']['name'] == 'Some Org'
|
||||
assert response['email_branding']['text'] == 'My Org'
|
||||
assert response['email_branding']['id'] == str(email_branding.id)
|
||||
|
||||
|
||||
@@ -53,6 +54,7 @@ def test_post_create_email_branding(admin_request, notify_db_session):
|
||||
assert data['name'] == response['data']['name']
|
||||
assert data['colour'] == response['data']['colour']
|
||||
assert data['logo'] == response['data']['logo']
|
||||
assert data['name'] == response['data']['text']
|
||||
|
||||
|
||||
def test_post_create_email_branding_without_logo_is_ok(admin_request, notify_db_session):
|
||||
@@ -80,6 +82,42 @@ def test_post_create_email_branding_without_name_or_colour_is_valid(admin_reques
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] is None
|
||||
assert response['data']['colour'] is None
|
||||
assert response['data']['text'] is None
|
||||
|
||||
|
||||
def test_post_create_email_branding_with_text(admin_request, notify_db_session):
|
||||
data = {
|
||||
'text': 'text for brand',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] is None
|
||||
assert response['data']['colour'] is None
|
||||
assert response['data']['text'] == 'text for brand'
|
||||
|
||||
|
||||
def test_post_create_email_branding_with_text_and_name(admin_request, notify_db_session):
|
||||
data = {
|
||||
'name': 'name for brand',
|
||||
'text': 'text for brand',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] == 'name for brand'
|
||||
assert response['data']['colour'] is None
|
||||
assert response['data']['text'] == 'text for brand'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data_update', [
|
||||
@@ -107,6 +145,38 @@ def test_post_update_email_branding_updates_field(admin_request, notify_db_sessi
|
||||
|
||||
email_branding = EmailBranding.query.all()
|
||||
|
||||
assert len(email_branding) == 1
|
||||
assert str(email_branding[0].id) == email_branding_id
|
||||
for key in data_update.keys():
|
||||
assert getattr(email_branding[0], key) == data_update[key]
|
||||
assert email_branding[0].text == email_branding[0].name
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data_update', [
|
||||
({'text': 'text email branding'}),
|
||||
({'text': 'new text', 'name': 'new name'}),
|
||||
])
|
||||
def test_post_update_email_branding_updates_field_with_text(admin_request, notify_db_session, data_update):
|
||||
data = {
|
||||
'name': 'test email_branding',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
email_branding_id = response['data']['id']
|
||||
|
||||
response = admin_request.post(
|
||||
'email_branding.update_email_branding',
|
||||
_data=data_update,
|
||||
email_branding_id=email_branding_id
|
||||
)
|
||||
|
||||
email_branding = EmailBranding.query.all()
|
||||
|
||||
assert len(email_branding) == 1
|
||||
assert str(email_branding[0].id) == email_branding_id
|
||||
for key in data_update.keys():
|
||||
|
||||
Reference in New Issue
Block a user