0001-sms-allow-to-send-sms-synchronously-for-testing-pupo.patch
passerelle/sms/models.py | ||
---|---|---|
72 | 72 |
assert all(map(lambda x: isinstance(x, six.text_type), data['to'])), \ |
73 | 73 |
'to is not a list of strings' |
74 | 74 |
except (ValueError, AssertionError) as e: |
75 | 75 |
raise APIError('Payload error: %s' % e) |
76 | 76 |
data['message'] = data['message'][:self.max_message_length] |
77 | 77 |
data['to'] = self.clean_numbers(data['to']) |
78 | 78 |
logging.info('sending SMS to %r from %r', data['to'], data['from']) |
79 | 79 |
stop = not bool('nostop' in request.GET) |
80 |
if bool('try_now' in request.GET): |
|
81 |
data = self.send_msg(text=data['message'], sender=data['from'], destinations=data['to'], |
|
82 |
stop=stop) |
|
83 |
return {'data': data} |
|
80 | 84 |
self.add_job('send_job', |
81 | 85 |
text=data['message'], sender=data['from'], destinations=data['to'], |
82 | 86 |
stop=stop) |
83 | 87 |
return {'err': 0} |
84 | 88 | |
85 | 89 |
def send_job(self, *args, **kwargs): |
86 | 90 |
self.send_msg(**kwargs) |
87 | 91 |
SMSLog.objects.create(appname=self.get_connector_slug(), slug=self.slug) |
tests/test_sms.py | ||
---|---|---|
49 | 49 |
# no access check |
50 | 50 |
AccessRight.objects.create(codename='can_send_messages', |
51 | 51 |
apiuser=api, |
52 | 52 |
resource_type=obj_type, |
53 | 53 |
resource_pk=c.pk) |
54 | 54 |
return c |
55 | 55 | |
56 | 56 | |
57 |
def test_connectors_try_now(app, connector, freezer): |
|
58 |
path = '/%s/%s/send/?try_now' % (connector.get_connector_slug(), connector.slug) |
|
59 |
result = app.post_json(path) |
|
60 |
assert result.json['err'] == 1 |
|
61 |
assert result.json['err_desc'].startswith('Payload error: ') |
|
62 | ||
63 |
payload = { |
|
64 |
'message': 'hello', |
|
65 |
'from': '+33699999999', |
|
66 |
'to': ['+33688888888', '+33677777777'], |
|
67 |
} |
|
68 |
for test_vector in getattr(connector, 'TEST_DEFAULTS', {}).get('test_vectors', []): |
|
69 |
with utils.mock_url( |
|
70 |
connector.URL, |
|
71 |
test_vector.get('response', ''), |
|
72 |
test_vector.get('status_code', 200)): |
|
73 |
result = app.post_json(path, params=payload) |
|
74 |
for key, value in test_vector['result'].items(): |
|
75 |
assert key in result.json |
|
76 |
assert result.json[key] == value |
|
77 | ||
78 | ||
57 | 79 |
def test_connectors(app, connector, freezer): |
58 | 80 |
path = '/%s/%s/send/' % (connector.get_connector_slug(), connector.slug) |
59 | 81 |
result = app.post_json(path, params={}) |
60 | 82 |
assert result.json['err'] == 1 |
61 | 83 |
assert result.json['err_desc'].startswith('Payload error: ') |
62 | 84 | |
63 | 85 |
payload = { |
64 | 86 |
'message': 'hello', |
65 |
- |