mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-23 08:49:46 -04:00
ensure emails still accept emoji
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import re
|
||||
|
||||
import pytz
|
||||
from flask_login import current_user
|
||||
from flask_wtf import Form
|
||||
@@ -251,7 +253,7 @@ class ConfirmPasswordForm(Form):
|
||||
raise ValidationError('Invalid password')
|
||||
|
||||
|
||||
class SMSTemplateForm(Form):
|
||||
class BaseTemplateForm(Form):
|
||||
name = StringField(
|
||||
u'Template name',
|
||||
validators=[DataRequired(message="Can’t be empty")])
|
||||
@@ -260,8 +262,7 @@ class SMSTemplateForm(Form):
|
||||
u'Message',
|
||||
validators=[
|
||||
DataRequired(message="Can’t be empty"),
|
||||
NoCommasInPlaceHolders(),
|
||||
OnlyGSMCharacters()
|
||||
NoCommasInPlaceHolders()
|
||||
]
|
||||
)
|
||||
process_type = RadioField(
|
||||
@@ -275,7 +276,12 @@ class SMSTemplateForm(Form):
|
||||
)
|
||||
|
||||
|
||||
class EmailTemplateForm(SMSTemplateForm):
|
||||
class SMSTemplateForm(BaseTemplateForm):
|
||||
def validate_template_content(self, field):
|
||||
OnlyGSMCharacters()(None, field)
|
||||
|
||||
|
||||
class EmailTemplateForm(BaseTemplateForm):
|
||||
subject = TextAreaField(
|
||||
u'Subject',
|
||||
validators=[DataRequired(message="Can’t be empty")])
|
||||
@@ -480,7 +486,6 @@ class ServiceSmsSender(Form):
|
||||
)
|
||||
|
||||
def validate_sms_sender(form, field):
|
||||
import re
|
||||
if field.data and not re.match('^[a-zA-Z0-9\s]+$', field.data):
|
||||
raise ValidationError('Use letters and numbers only')
|
||||
|
||||
|
||||
@@ -163,11 +163,12 @@ def add_service_template(service_id, template_type):
|
||||
form.process_type.data
|
||||
)
|
||||
except HTTPError as e:
|
||||
if e.status_code == 400:
|
||||
if 'content' in e.message and any(['character count greater than' in x for x in e.message['content']]):
|
||||
form.template_content.errors.extend(e.message['content'])
|
||||
else:
|
||||
raise e
|
||||
if (
|
||||
e.status_code == 400 and
|
||||
'content' in e.message and
|
||||
any(['character count greater than' in x for x in e.message['content']])
|
||||
):
|
||||
form.template_content.errors.extend(e.message['content'])
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
|
||||
@@ -629,10 +629,31 @@ def test_get_human_readable_delta(from_time, until_time, message):
|
||||
assert get_human_readable_delta(from_time, until_time) == message
|
||||
|
||||
|
||||
def test_can_create_email_template_with_emoji(
|
||||
logged_in_client,
|
||||
service_one,
|
||||
mock_create_service_template
|
||||
):
|
||||
data = {
|
||||
'name': "new name",
|
||||
'subject': "Food incoming!",
|
||||
'template_content': "here's a burrito 🌯",
|
||||
'template_type': 'email',
|
||||
'service': service_one['id'],
|
||||
'process_type': 'normal'
|
||||
}
|
||||
resp = logged_in_client.post(url_for(
|
||||
'.add_service_template',
|
||||
service_id=service_one['id'],
|
||||
template_type='email'
|
||||
), data=data)
|
||||
|
||||
assert resp.status_code == 302
|
||||
|
||||
|
||||
def test_should_not_create_sms_template_with_emoji(
|
||||
logged_in_client,
|
||||
service_one,
|
||||
mock_get_service_template,
|
||||
mock_create_service_template
|
||||
):
|
||||
data = {
|
||||
|
||||
Reference in New Issue
Block a user