0002-base-log-sent-sms-time-39651.patch
passerelle/base/models.py | ||
---|---|---|
950 | 950 |
data['message'] = data['message'][:self.max_message_length] |
951 | 951 |
logging.info('sending message %r to %r with sending number %r', |
952 | 952 |
data['message'], data['to'], data['from']) |
953 |
if 'nostop' in request.GET: |
|
954 |
return {'data': self.send_msg(data['message'], data['from'], data['to'], stop=False)} |
|
955 |
return {'data': self.send_msg(data['message'], data['from'], data['to'], stop=True)} |
|
953 |
stop = not bool('nostop' in request.GET) |
|
954 |
result = {'data': self.send_msg(data['message'], data['from'], data['to'], stop=stop)} |
|
955 |
SMSLog.objects.create(appname=self.get_connector_slug(), slug=self.slug) |
|
956 |
return result |
|
956 | 957 | |
957 | 958 |
class Meta: |
958 | 959 |
abstract = True |
960 | ||
961 | ||
962 |
@six.python_2_unicode_compatible |
|
963 |
class SMSLog(models.Model): |
|
964 |
timestamp = models.DateTimeField(auto_now_add=True) |
|
965 |
appname = models.CharField(max_length=128, verbose_name='appname', null=True) |
|
966 |
slug = models.CharField(max_length=128, verbose_name='slug', null=True) |
|
967 | ||
968 |
def __str__(self): |
|
969 |
return '%s %s %s' % (self.timestamp, self.appname, self.slug) |
tests/test_sms.py | ||
---|---|---|
4 | 4 |
from django.contrib.contenttypes.models import ContentType |
5 | 5 | |
6 | 6 |
from passerelle.apps.ovh.models import OVHSMSGateway |
7 |
from passerelle.base.models import ApiUser, AccessRight, SMSResource |
|
7 |
from passerelle.base.models import ApiUser, AccessRight, SMSResource, SMSLog
|
|
8 | 8 | |
9 | 9 |
from test_manager import login, admin_user |
10 | 10 | |
... | ... | |
88 | 88 |
send_function.return_value = {} |
89 | 89 |
result = app.post_json(path, params=payload) |
90 | 90 |
assert send_function.call_args[0][0] == 'a' * connector.max_message_length |
91 | ||
92 | ||
93 |
@pytest.mark.parametrize('connector', [OVHSMSGateway], indirect=True) |
|
94 |
def test_sms_log(app, connector): |
|
95 |
path = '/%s/%s/send/' % (connector.get_connector_slug(), connector.slug) |
|
96 |
assert not SMSLog.objects.filter(appname=connector.get_connector_slug(), slug=connector.slug).exists() |
|
97 | ||
98 |
payload = { |
|
99 |
'message': 'plop', |
|
100 |
'from': '+33699999999', |
|
101 |
'to': ['+33688888888'], |
|
102 |
} |
|
103 |
with mock.patch.object(OVHSMSGateway, 'send_msg') as send_function: |
|
104 |
send_function.return_value = {} |
|
105 |
result = app.post_json(path, params=payload) |
|
106 |
assert SMSLog.objects.filter(appname=connector.get_connector_slug(), slug=connector.slug).exists() |
|
91 |
- |