sms: ensure country code and prefix are numbers (#61813)
This commit is contained in:
parent
6392499957
commit
4baad9742b
|
@ -18,6 +18,7 @@ import re
|
|||
|
||||
from django.conf.urls import url
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils import six
|
||||
|
@ -66,10 +67,16 @@ class SMSResource(BaseResource):
|
|||
_can_send_messages_description = _('Sending messages is limited to the following API users:')
|
||||
|
||||
default_country_code = models.CharField(
|
||||
verbose_name=_('Default country code'), max_length=3, default=u'33'
|
||||
verbose_name=_('Default country code'),
|
||||
max_length=3,
|
||||
default=u'33',
|
||||
validators=[RegexValidator('^[0-9]*$', _('The country must only contain numbers'))],
|
||||
)
|
||||
default_trunk_prefix = models.CharField(
|
||||
verbose_name=_('Default trunk prefix'), max_length=2, default=u'0'
|
||||
verbose_name=_('Default trunk prefix'),
|
||||
max_length=2,
|
||||
default=u'0',
|
||||
validators=[RegexValidator('^[0-9]*$', _('The trunk prefix must only contain numbers'))],
|
||||
) # Yeah France first !
|
||||
max_message_length = models.IntegerField(
|
||||
_('Maximum message length'), help_text=_('Messages over this limit will be truncated.'), default=2000
|
||||
|
|
|
@ -620,10 +620,18 @@ def test_manager(admin_user, app, connector):
|
|||
path = '/manage/%s/%s/edit' % (connector.get_connector_slug(), connector.slug)
|
||||
resp = app.get(path)
|
||||
resp.form['authorized'] = []
|
||||
resp.form['default_country_code'] = '+33'
|
||||
resp.form['default_trunk_prefix'] = 'x'
|
||||
resp = resp.form.submit()
|
||||
assert resp.html.find('div', {'class': 'errornotice'}).p.text == 'There were errors processing your form.'
|
||||
assert resp.html.find('div', {'class': 'error'}).text.strip() == 'This field is required.'
|
||||
assert [x.text.strip() for x in resp.html.find_all('div', {'class': 'error'})] == [
|
||||
'The country must only contain numbers',
|
||||
'The trunk prefix must only contain numbers',
|
||||
'This field is required.',
|
||||
]
|
||||
resp.form['authorized'] = [SMSResource.FR_METRO, SMSResource.FR_DOMTOM]
|
||||
resp.form['default_country_code'] = '33'
|
||||
resp.form['default_trunk_prefix'] = '0'
|
||||
resp = resp.form.submit()
|
||||
resp = resp.follow()
|
||||
assert (
|
||||
|
|
Loading…
Reference in New Issue