mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Validate name field on ServiceUpdateEmailBranding form
This introduces a validator to validate that the name field is not empty on the ServiceUpdateEmailBranding form, but only if the form details are being submitted. If a file is being uploaded, the name is allowed to be empty.
This commit is contained in:
@@ -848,6 +848,11 @@ class ServiceUpdateEmailBranding(StripWhitespaceForm):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_name(form, name):
|
||||||
|
op = request.form.get('operation')
|
||||||
|
if op == 'email-branding-details' and not form.name.data:
|
||||||
|
raise ValidationError('This field is required')
|
||||||
|
|
||||||
|
|
||||||
class PDFUploadForm(StripWhitespaceForm):
|
class PDFUploadForm(StripWhitespaceForm):
|
||||||
file = FileField_wtf(
|
file = FileField_wtf(
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
{{ radios(form.brand_type) }}
|
{{ radios(form.brand_type) }}
|
||||||
{{ page_footer(
|
{{ page_footer(
|
||||||
'Save',
|
'Save',
|
||||||
|
button_name='operation',
|
||||||
|
button_value='email-branding-details',
|
||||||
back_link=url_for('.email_branding'),
|
back_link=url_for('.email_branding'),
|
||||||
back_link_text='Back to email branding selection',
|
back_link_text='Back to email branding selection',
|
||||||
) }}
|
) }}
|
||||||
|
|||||||
@@ -218,6 +218,60 @@ def test_rejects_non_canonical_domain_when_adding_email_branding(
|
|||||||
assert mock_create_email_branding.called is False
|
assert mock_create_email_branding.called is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_email_branding_requires_a_name_when_submitting_logo_details(
|
||||||
|
client_request,
|
||||||
|
mocker,
|
||||||
|
fake_uuid,
|
||||||
|
mock_create_email_branding,
|
||||||
|
):
|
||||||
|
mocker.patch('app.main.views.email_branding.persist_logo')
|
||||||
|
mocker.patch('app.main.views.email_branding.delete_temp_files_created_by')
|
||||||
|
data = {
|
||||||
|
'operation': 'email-branding-details',
|
||||||
|
'logo': '',
|
||||||
|
'colour': '#ff0000',
|
||||||
|
'text': 'new text',
|
||||||
|
'name': '',
|
||||||
|
'domain': '',
|
||||||
|
'brand_type': 'org',
|
||||||
|
}
|
||||||
|
client_request.login(platform_admin_user(fake_uuid))
|
||||||
|
page = client_request.post(
|
||||||
|
'.create_email_branding',
|
||||||
|
content_type='multipart/form-data',
|
||||||
|
_data=data,
|
||||||
|
_expected_status=200,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert page.select_one('.error-message').text.strip() == 'This field is required'
|
||||||
|
assert mock_create_email_branding.called is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_email_branding_does_not_require_a_name_when_uploading_a_file(
|
||||||
|
client_request,
|
||||||
|
mocker,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
mocker.patch('app.main.views.email_branding.upload_logo', return_value='temp_filename')
|
||||||
|
data = {
|
||||||
|
'file': (BytesIO(''.encode('utf-8')), 'test.png'),
|
||||||
|
'colour': '',
|
||||||
|
'text': '',
|
||||||
|
'name': '',
|
||||||
|
'domain': '',
|
||||||
|
'brand_type': 'org',
|
||||||
|
}
|
||||||
|
client_request.login(platform_admin_user(fake_uuid))
|
||||||
|
page = client_request.post(
|
||||||
|
'.create_email_branding',
|
||||||
|
content_type='multipart/form-data',
|
||||||
|
_data=data,
|
||||||
|
_follow_redirects=True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert not page.find('.error-message')
|
||||||
|
|
||||||
|
|
||||||
def test_create_new_email_branding_when_branding_saved(
|
def test_create_new_email_branding_when_branding_saved(
|
||||||
logged_in_platform_admin_client,
|
logged_in_platform_admin_client,
|
||||||
mocker,
|
mocker,
|
||||||
|
|||||||
Reference in New Issue
Block a user