0002-base-add-maximum-sms-length-option-39654.patch
passerelle/base/models.py | ||
---|---|---|
908 | 908 | |
909 | 909 |
_can_send_messages_description = _('Sending messages is limited to the following API users:') |
910 | 910 | |
911 |
max_message_length = models.IntegerField(_('Maximum message length'), default=160) |
|
912 | ||
911 | 913 |
@classmethod |
912 | 914 |
def clean_numbers(cls, destinations, default_country_code='33', |
913 | 915 |
default_trunk_prefix='0'): # Yeah France first ! |
... | ... | |
945 | 947 |
'to is not a list of strings' |
946 | 948 |
except (ValueError, AssertionError) as e: |
947 | 949 |
raise APIError('Payload error: %s' % e) |
950 |
data['message'] = data['message'][:self.max_message_length] |
|
948 | 951 |
logging.info('sending message %r to %r with sending number %r', |
949 | 952 |
data['message'], data['to'], data['from']) |
950 | 953 |
if 'nostop' in request.GET: |
tests/test_sms.py | ||
---|---|---|
1 |
import mock |
|
1 | 2 |
import pytest |
2 | 3 | |
3 | 4 |
from django.contrib.contenttypes.models import ContentType |
4 | 5 | |
6 |
from passerelle.apps.ovh.models import OVHSMSGateway |
|
5 | 7 |
from passerelle.base.models import ApiUser, AccessRight, SMSResource |
6 | 8 | |
7 | 9 |
from test_manager import login, admin_user |
... | ... | |
70 | 72 |
resp = app.get(url) |
71 | 73 |
assert 'Endpoints' in resp.text |
72 | 74 |
assert 'accessright/add' in resp.text |
75 | ||
76 | ||
77 |
@pytest.mark.parametrize('connector', [OVHSMSGateway], indirect=True) |
|
78 |
def test_sms_max_message_length(app, connector): |
|
79 |
path = '/%s/%s/send/' % (connector.get_connector_slug(), connector.slug) |
|
80 | ||
81 |
message_above_limit = 'a' * (connector.max_message_length + 1) |
|
82 |
payload = { |
|
83 |
'message': message_above_limit, |
|
84 |
'from': '+33699999999', |
|
85 |
'to': ['+33688888888'], |
|
86 |
} |
|
87 |
with mock.patch.object(OVHSMSGateway, 'send_msg') as send_function: |
|
88 |
send_function.return_value = {} |
|
89 |
result = app.post_json(path, params=payload) |
|
90 |
assert send_function.call_args[0][0] == 'a' * connector.max_message_length |
|
73 |
- |