-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_outgoing.py
59 lines (49 loc) · 2.62 KB
/
test_outgoing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# coding: utf-8
from __future__ import unicode_literals
from mock import patch
from django.test import TestCase
from rapidsms.tests.harness import CreateDataMixin
from rapidsms_multimodem.outgoing import MultiModemBackend, ISMS_ASCII, ISMS_UNICODE
class SendTest(CreateDataMixin, TestCase):
def setUp(self):
config = {
'sendsms_url': 'http://192.168.170.200:81/sendmsg',
'sendsms_user': 'admin',
'sendsms_pass': 'admin',
'modem_port': 1,
'server_slug': 'isms-lebanon',
}
self.backend = MultiModemBackend(None, "multimodem", **config)
def test_required_fields(self):
"""Multimodem backend requires Gateway URL and credentials."""
self.assertRaises(TypeError, MultiModemBackend, None, "multimodem")
def test_prepare_querystring(self):
message = self.create_outgoing_message(data={'text': 'a message'})
query_string = self.backend.prepare_querystring(id_=message.id,
text=message.text,
identities=message.connections[0].identity,
context={})
self.assertIn('user=admin', query_string)
self.assertIn('passwd=admin', query_string)
self.assertIn('enc={}'.format(ISMS_ASCII), query_string)
self.assertIn('modem=1', query_string)
# just ensure the text param is there. content is tested in test_utils.py
self.assertIn('text=', query_string)
def test_prepare_unicode_querystring(self):
unicode_string = 'Щнпзнмгмжнм'
message = self.create_outgoing_message(data={'text': unicode_string})
query_string = self.backend.prepare_querystring(id_=message.id,
text=message.text,
identities=message.connections[0].identity,
context={})
self.assertIn('enc={}'.format(ISMS_UNICODE), query_string)
# just ensure the text param is there. content is tested in test_utils.py
self.assertIn('text=', query_string)
@patch('rapidsms_multimodem.outgoing.requests')
def test_send(self, mock_requests):
message = self.create_outgoing_message(data={'text': 'a message'})
self.backend.send(id_=message.id,
text=message.text,
identities=message.connections[0].identity,
context={})
self.assertTrue(mock_requests.get.called)