mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 12:59:48 -04:00
Move brandings sort into email_branding_client
This commit is contained in:
@@ -26,10 +26,10 @@ from app.utils import get_cdn_domain, user_is_platform_admin
|
|||||||
@login_required
|
@login_required
|
||||||
@user_is_platform_admin
|
@user_is_platform_admin
|
||||||
def email_branding():
|
def email_branding():
|
||||||
brandings = email_branding_client.get_all_email_branding()
|
brandings = email_branding_client.get_all_email_branding(sort_key='name')
|
||||||
|
|
||||||
form = ServiceSelectEmailBranding()
|
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')]
|
form.email_branding.choices = email_brandings + [('None', 'Create a new email branding')]
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ class EmailBrandingClient(NotifyAdminAPIClient):
|
|||||||
def get_email_branding(self, branding_id):
|
def get_email_branding(self, branding_id):
|
||||||
return self.get(url='/email-branding/{}'.format(branding_id))
|
return self.get(url='/email-branding/{}'.format(branding_id))
|
||||||
|
|
||||||
def get_all_email_branding(self):
|
def get_all_email_branding(self, sort_key=None):
|
||||||
return self.get(url='/email-branding')['email_branding']
|
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):
|
def get_letter_email_branding(self):
|
||||||
return self.get(url='/dvla_organisations')
|
return self.get(url='/dvla_organisations')
|
||||||
|
|||||||
@@ -2430,14 +2430,23 @@ def mock_send_already_registered_email(mocker):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_all_email_branding(mocker):
|
def mock_get_all_email_branding(mocker):
|
||||||
def _get_all_email_branding():
|
def _get_all_email_branding(sort_key=None):
|
||||||
return [
|
if sort_key:
|
||||||
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png'},
|
return [
|
||||||
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png'},
|
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png'},
|
||||||
{'id': '3', 'name': 'org 3', 'text': None, 'colour': None, 'logo': 'logo3.png'},
|
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png'},
|
||||||
{'id': '5', 'name': 'org 5', 'text': None, 'colour': 'blue', 'logo': 'logo5.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': '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(
|
return mocker.patch(
|
||||||
'app.email_branding_client.get_all_email_branding', side_effect=_get_all_email_branding
|
'app.email_branding_client.get_all_email_branding', side_effect=_get_all_email_branding
|
||||||
|
|||||||
Reference in New Issue
Block a user