Move brandings sort into email_branding_client

This commit is contained in:
Tom Byers
2018-08-16 13:40:24 +01:00
parent bdde98e9ba
commit f85a9306a6
3 changed files with 24 additions and 12 deletions

View File

@@ -26,10 +26,10 @@ from app.utils import get_cdn_domain, user_is_platform_admin
@login_required
@user_is_platform_admin
def email_branding():
brandings = email_branding_client.get_all_email_branding()
brandings = email_branding_client.get_all_email_branding(sort_key='name')
form = ServiceSelectEmailBranding()
email_brandings = sorted(get_branding_as_value_and_label(brandings), key=lambda tup: tup[1].lower())
email_brandings = get_branding_as_value_and_label(brandings)
form.email_branding.choices = email_brandings + [('None', 'Create a new email branding')]
if form.validate_on_submit():

View File

@@ -9,8 +9,11 @@ class EmailBrandingClient(NotifyAdminAPIClient):
def get_email_branding(self, branding_id):
return self.get(url='/email-branding/{}'.format(branding_id))
def get_all_email_branding(self):
return self.get(url='/email-branding')['email_branding']
def get_all_email_branding(self, sort_key=None):
brandings = self.get(url='/email-branding')['email_branding']
if sort_key and sort_key in brandings[0]:
brandings.sort(key=lambda branding: branding[sort_key].lower())
return brandings
def get_letter_email_branding(self):
return self.get(url='/dvla_organisations')

View File

@@ -2430,14 +2430,23 @@ def mock_send_already_registered_email(mocker):
@pytest.fixture(scope='function')
def mock_get_all_email_branding(mocker):
def _get_all_email_branding():
return [
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png'},
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png'},
{'id': '3', 'name': 'org 3', 'text': None, 'colour': None, 'logo': 'logo3.png'},
{'id': '5', 'name': 'org 5', 'text': None, 'colour': 'blue', 'logo': 'logo5.png'},
{'id': '4', 'name': 'org 4', 'text': 'org 4', 'colour': None, 'logo': 'logo4.png'},
]
def _get_all_email_branding(sort_key=None):
if sort_key:
return [
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png'},
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png'},
{'id': '3', 'name': 'org 3', 'text': None, 'colour': None, 'logo': 'logo3.png'},
{'id': '4', 'name': 'org 4', 'text': 'org 4', 'colour': None, 'logo': 'logo4.png'},
{'id': '5', 'name': 'org 5', 'text': None, 'colour': 'blue', 'logo': 'logo5.png'},
]
else:
return [
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png'},
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png'},
{'id': '3', 'name': 'org 3', 'text': None, 'colour': None, 'logo': 'logo3.png'},
{'id': '5', 'name': 'org 5', 'text': None, 'colour': 'blue', 'logo': 'logo5.png'},
{'id': '4', 'name': 'org 4', 'text': 'org 4', 'colour': None, 'logo': 'logo4.png'},
]
return mocker.patch(
'app.email_branding_client.get_all_email_branding', side_effect=_get_all_email_branding