mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
create, edit and use email branding instead of organisation
notable things that have been kept until migration is complete: * passing in `organisation` to update_service will update email branding * both `/email-branding` and `/organisation` hit the same code * service endpoints still return organisation as well as email branding
This commit is contained in:
44
tests/app/dao/test_email_branding_dao.py
Normal file
44
tests/app/dao/test_email_branding_dao.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from app.dao.email_branding_dao import (
|
||||
dao_get_email_branding_options,
|
||||
dao_get_email_branding_by_id,
|
||||
dao_update_email_branding,
|
||||
)
|
||||
from app.models import EmailBranding
|
||||
|
||||
from tests.app.db import create_email_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_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_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
|
||||
@@ -1,60 +0,0 @@
|
||||
from app.dao.organisations_dao import (
|
||||
dao_get_organisations,
|
||||
dao_get_organisation_by_id,
|
||||
dao_update_organisation,
|
||||
)
|
||||
from app.models import Organisation
|
||||
|
||||
from tests.app.db import create_organisation
|
||||
|
||||
|
||||
def test_create_organisation(notify_db, notify_db_session):
|
||||
organisation = create_organisation()
|
||||
|
||||
assert Organisation.query.count() == 1
|
||||
organisation_from_db = Organisation.query.first()
|
||||
assert organisation == organisation_from_db
|
||||
|
||||
|
||||
def test_create_organisation_without_name_or_colour_is_valid(notify_db, notify_db_session):
|
||||
organisation = create_organisation(logo=None, name=None, colour=None)
|
||||
|
||||
assert Organisation.query.count() == 1
|
||||
organisation_from_db = Organisation.query.first()
|
||||
assert organisation == organisation_from_db
|
||||
|
||||
|
||||
def test_get_organisations_gets_all_organisations(notify_db, notify_db_session):
|
||||
org_1 = create_organisation(name='test_org_1')
|
||||
org_2 = create_organisation(name='test_org_2')
|
||||
|
||||
organisations = dao_get_organisations()
|
||||
|
||||
assert len(organisations) == 2
|
||||
assert org_1 == organisations[0]
|
||||
assert org_2 == organisations[1]
|
||||
|
||||
|
||||
def test_get_organisation_by_id_gets_correct_organisation(notify_db, notify_db_session):
|
||||
organisation = create_organisation()
|
||||
|
||||
organisation_from_db = dao_get_organisation_by_id(organisation.id)
|
||||
|
||||
assert organisation_from_db == organisation
|
||||
|
||||
|
||||
def test_update_organisation(notify_db, notify_db_session):
|
||||
updated_name = 'new name'
|
||||
create_organisation()
|
||||
|
||||
organisations_1 = Organisation.query.all()
|
||||
|
||||
assert len(organisations_1) == 1
|
||||
assert organisations_1[0].name != updated_name
|
||||
|
||||
dao_update_organisation(organisations_1[0], name=updated_name)
|
||||
|
||||
organisations_2 = Organisation.query.all()
|
||||
|
||||
assert len(organisations_2) == 1
|
||||
assert organisations_2[0].name == updated_name
|
||||
@@ -13,7 +13,7 @@ from app.models import (
|
||||
Job,
|
||||
MonthlyBilling,
|
||||
Notification,
|
||||
Organisation,
|
||||
EmailBranding,
|
||||
Rate,
|
||||
Service,
|
||||
ServiceEmailReplyTo,
|
||||
@@ -40,7 +40,7 @@ from app.dao.templates_dao import dao_create_template
|
||||
from app.dao.services_dao import dao_create_service
|
||||
from app.dao.service_permissions_dao import dao_add_service_permission
|
||||
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
||||
from app.dao.organisations_dao import dao_create_organisation
|
||||
from app.dao.email_branding_dao import dao_create_email_branding
|
||||
|
||||
|
||||
def create_user(mobile_number="+447700900986", email="notify@digital.cabinet-office.gov.uk", state='active'):
|
||||
@@ -316,16 +316,16 @@ def create_service_callback_api(
|
||||
return service_callback_api
|
||||
|
||||
|
||||
def create_organisation(colour='blue', logo='test_x2.png', name='test_org_1'):
|
||||
def create_email_branding(colour='blue', logo='test_x2.png', name='test_org_1'):
|
||||
data = {
|
||||
'colour': colour,
|
||||
'logo': logo,
|
||||
'name': name
|
||||
}
|
||||
organisation = Organisation(**data)
|
||||
dao_create_organisation(organisation)
|
||||
email_branding = EmailBranding(**data)
|
||||
dao_create_email_branding(email_branding)
|
||||
|
||||
return organisation
|
||||
return email_branding
|
||||
|
||||
|
||||
def create_rate(start_date, value, notification_type):
|
||||
|
||||
@@ -15,7 +15,7 @@ from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_wit
|
||||
from app.delivery import send_to_providers
|
||||
from app.models import (
|
||||
Notification,
|
||||
Organisation,
|
||||
EmailBranding,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEST,
|
||||
KEY_TYPE_TEAM,
|
||||
@@ -439,9 +439,9 @@ def test_get_html_email_renderer_should_return_for_normal_service(sample_service
|
||||
])
|
||||
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])
|
||||
email_branding = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.email_branding = email_branding
|
||||
notify_db.session.add_all([sample_service, email_branding])
|
||||
notify_db.session.commit()
|
||||
|
||||
options = send_to_providers.get_html_email_options(sample_service)
|
||||
@@ -458,9 +458,9 @@ def test_get_html_email_renderer_with_branding_details(branding_type, govuk_bann
|
||||
|
||||
def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_only(notify_db, sample_service):
|
||||
sample_service.branding = BRANDING_GOVUK
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.organisation = org
|
||||
notify_db.session.add_all([sample_service, org])
|
||||
email_branding = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
sample_service.email_branding = email_branding
|
||||
notify_db.session.add_all([sample_service, email_branding])
|
||||
notify_db.session.commit()
|
||||
|
||||
options = send_to_providers.get_html_email_options(sample_service)
|
||||
@@ -469,23 +469,23 @@ def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_o
|
||||
|
||||
|
||||
def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
||||
Service = namedtuple('Service', ['branding', 'organisation'])
|
||||
Organisation = namedtuple('Organisation', ['colour', 'name', 'logo'])
|
||||
Service = namedtuple('Service', ['branding', 'email_branding'])
|
||||
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo'])
|
||||
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
service = Service(branding=BRANDING_ORG, organisation=org)
|
||||
email_branding = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
|
||||
|
||||
renderer = send_to_providers.get_html_email_options(service)
|
||||
|
||||
assert renderer['brand_logo'] == 'http://static-logos.notify.tools/justice-league.png'
|
||||
|
||||
|
||||
def test_get_html_email_renderer_handles_org_without_logo(notify_api):
|
||||
Service = namedtuple('Service', ['branding', 'organisation'])
|
||||
Organisation = namedtuple('Organisation', ['colour', 'name', 'logo'])
|
||||
def test_get_html_email_renderer_handles_email_branding_without_logo(notify_api):
|
||||
Service = namedtuple('Service', ['branding', 'email_branding'])
|
||||
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo'])
|
||||
|
||||
org = Organisation(colour='#000000', logo=None, name='Justice League')
|
||||
service = Service(branding=BRANDING_ORG, organisation=org)
|
||||
email_branding = EmailBranding(colour='#000000', logo=None, name='Justice League')
|
||||
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
|
||||
|
||||
renderer = send_to_providers.get_html_email_options(service)
|
||||
|
||||
|
||||
113
tests/app/email_branding/test_rest.py
Normal file
113
tests/app/email_branding/test_rest.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import pytest
|
||||
|
||||
from app.models import EmailBranding
|
||||
|
||||
|
||||
def test_get_email_branding_options(admin_request, notify_db, notify_db_session):
|
||||
email_branding1 = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Org1')
|
||||
email_branding2 = EmailBranding(colour='#000000', logo='/path/other.png', name='Org2')
|
||||
notify_db.session.add_all([email_branding1, email_branding2])
|
||||
notify_db.session.commit()
|
||||
|
||||
email_branding = admin_request.get(
|
||||
'email_branding.get_email_branding_options'
|
||||
)['email_branding']
|
||||
|
||||
assert len(email_branding) == 2
|
||||
assert {
|
||||
email_branding['id'] for email_branding in email_branding
|
||||
} == {
|
||||
str(email_branding1.id), str(email_branding2.id)
|
||||
}
|
||||
|
||||
|
||||
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')
|
||||
notify_db.session.add(email_branding)
|
||||
notify_db.session.commit()
|
||||
|
||||
response = admin_request.get(
|
||||
'email_branding.get_email_branding_by_id',
|
||||
_expected_status=200,
|
||||
email_branding_id=email_branding.id
|
||||
)
|
||||
|
||||
assert set(response['email_branding'].keys()) == {'colour', 'logo', 'name', 'id'}
|
||||
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']['id'] == str(email_branding.id)
|
||||
|
||||
|
||||
def test_post_create_email_branding(admin_request, notify_db_session):
|
||||
data = {
|
||||
'name': 'test email_branding',
|
||||
'colour': '#0000ff',
|
||||
'logo': '/images/test_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
assert data['name'] == response['data']['name']
|
||||
assert data['colour'] == response['data']['colour']
|
||||
assert data['logo'] == response['data']['logo']
|
||||
|
||||
|
||||
def test_post_create_email_branding_without_logo_is_ok(admin_request, notify_db_session):
|
||||
data = {
|
||||
'name': 'test email_branding',
|
||||
'colour': '#0000ff',
|
||||
}
|
||||
admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201,
|
||||
)
|
||||
|
||||
|
||||
def test_post_create_email_branding_without_name_or_colour_is_valid(admin_request, notify_db_session):
|
||||
data = {
|
||||
'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
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data_update', [
|
||||
({'name': 'test email_branding 1'}),
|
||||
({'logo': 'images/text_x3.png', 'colour': '#ffffff'}),
|
||||
])
|
||||
def test_post_update_email_branding_updates_field(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():
|
||||
assert getattr(email_branding[0], key) == data_update[key]
|
||||
@@ -1,109 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from app.models import Organisation
|
||||
|
||||
|
||||
def test_get_organisations(admin_request, notify_db, notify_db_session):
|
||||
org1 = Organisation(colour='#FFFFFF', logo='/path/image.png', name='Org1')
|
||||
org2 = Organisation(colour='#000000', logo='/path/other.png', name='Org2')
|
||||
notify_db.session.add_all([org1, org2])
|
||||
notify_db.session.commit()
|
||||
|
||||
organisations = admin_request.get(
|
||||
'organisation.get_organisations'
|
||||
)['organisations']
|
||||
|
||||
assert len(organisations) == 2
|
||||
assert {org['id'] for org in organisations} == {str(org1.id), str(org2.id)}
|
||||
|
||||
|
||||
def test_get_organisation_by_id(admin_request, notify_db, notify_db_session):
|
||||
org = Organisation(colour='#FFFFFF', logo='/path/image.png', name='My Org')
|
||||
notify_db.session.add(org)
|
||||
notify_db.session.commit()
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.get_organisation_by_id',
|
||||
_expected_status=200,
|
||||
org_id=org.id
|
||||
)
|
||||
|
||||
assert set(response['organisation'].keys()) == {'colour', 'logo', 'name', 'id'}
|
||||
assert response['organisation']['colour'] == '#FFFFFF'
|
||||
assert response['organisation']['logo'] == '/path/image.png'
|
||||
assert response['organisation']['name'] == 'My Org'
|
||||
assert response['organisation']['id'] == str(org.id)
|
||||
|
||||
|
||||
def test_post_create_organisation(admin_request, notify_db_session):
|
||||
data = {
|
||||
'name': 'test organisation',
|
||||
'colour': '#0000ff',
|
||||
'logo': '/images/test_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'organisation.create_organisation',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
assert data['name'] == response['data']['name']
|
||||
assert data['colour'] == response['data']['colour']
|
||||
assert data['logo'] == response['data']['logo']
|
||||
|
||||
|
||||
def test_post_create_organisation_without_logo_is_ok(admin_request, notify_db_session):
|
||||
data = {
|
||||
'name': 'test organisation',
|
||||
'colour': '#0000ff',
|
||||
}
|
||||
admin_request.post(
|
||||
'organisation.create_organisation',
|
||||
_data=data,
|
||||
_expected_status=201,
|
||||
)
|
||||
|
||||
|
||||
def test_post_create_organisation_without_name_or_colour_is_valid(admin_request, notify_db_session):
|
||||
data = {
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'organisation.create_organisation',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] is None
|
||||
assert response['data']['colour'] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data_update', [
|
||||
({'name': 'test organisation 1'}),
|
||||
({'logo': 'images/text_x3.png', 'colour': '#ffffff'}),
|
||||
])
|
||||
def test_post_update_organisation_updates_field(admin_request, notify_db_session, data_update):
|
||||
data = {
|
||||
'name': 'test organisation',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'organisation.create_organisation',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
org_id = response['data']['id']
|
||||
|
||||
response = admin_request.post(
|
||||
'organisation.update_organisation',
|
||||
_data=data_update,
|
||||
organisation_id=org_id
|
||||
)
|
||||
|
||||
organisations = Organisation.query.all()
|
||||
|
||||
assert len(organisations) == 1
|
||||
assert str(organisations[0].id) == org_id
|
||||
for key in data_update.keys():
|
||||
assert getattr(organisations[0], key) == data_update[key]
|
||||
Reference in New Issue
Block a user