Status: | Merged |
---|---|
Approved by: | Soren Hansen |
Approved revision: | 21 |
Merged at revision: | 20 |
Proposed branch: | lp:~soren/surveilr/bulksms |
Merge into: | lp:surveilr |
Diff against target: |
717 lines (+446/-87) 20 files modified
surveilr/defaults.cfg (+1/-0) surveilr/messaging/sms/__init__.py (+6/-21) surveilr/messaging/sms/bulksms_driver.py (+47/-0) surveilr/messaging/sms/clickatell_driver.py (+51/-0) surveilr/messaging/sms/fake.py (+32/-0) surveilr/tests/__init__.py (+6/-0) surveilr/tests/api/test_server.py (+1/-2) surveilr/tests/messaging/__init__.py (+19/-0) surveilr/tests/messaging/sms/__init__.py (+19/-0) surveilr/tests/messaging/sms/test_base.cfg (+2/-0) surveilr/tests/messaging/sms/test_base.py (+43/-0) surveilr/tests/messaging/sms/test_bulksms.cfg (+6/-0) surveilr/tests/messaging/sms/test_bulksms.py (+56/-0) surveilr/tests/messaging/sms/test_clickatell.cfg (+1/-0) surveilr/tests/messaging/sms/test_clickatell.py (+6/-64) surveilr/tests/messaging/sms/test_fake.py (+39/-0) surveilr/tests/messaging/test_base.py (+68/-0) surveilr/tests/messaging/test_fake.py (+41/-0) surveilr/tests/test_config.py (+1/-0) tools/pip-requirements.txt (+1/-0) |
To merge this branch: | bzr merge lp:~soren/surveilr/bulksms |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Soren Hansen | Pending | ||
Review via email: mp+86377@code.launchpad.net |
Commit message
Add BulkSMS driver.
In the process, split the drivers into separate modules and turn
messaging.sms into a package.
Description of the change
Add BulkSMS driver.
In the process, split the drivers into separate modules and turn
messaging.sms into a package.
To post a comment you must log in.
Revision history for this message
Linux2Go Jenkins (linux2go-jenkins) wrote : | # |
Revision history for this message
Soren Hansen (soren) wrote : | # |
Installed mercurial on Jenkins box.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'surveilr/defaults.cfg' | |||
2 | --- surveilr/defaults.cfg 2011-12-18 14:25:14 +0000 | |||
3 | +++ surveilr/defaults.cfg 2011-12-20 11:09:28 +0000 | |||
4 | @@ -1,6 +1,7 @@ | |||
5 | 1 | # This is where we stick defaults for various things | 1 | # This is where we stick defaults for various things |
6 | 2 | 2 | ||
7 | 3 | [sms] | 3 | [sms] |
8 | 4 | driver = fake | ||
9 | 4 | username = | 5 | username = |
10 | 5 | password = | 6 | password = |
11 | 6 | api_id = | 7 | api_id = |
12 | 7 | 8 | ||
13 | === added directory 'surveilr/messaging/sms' | |||
14 | === renamed file 'surveilr/messaging/sms.py' => 'surveilr/messaging/sms/__init__.py' | |||
15 | --- surveilr/messaging/sms.py 2011-11-29 23:41:46 +0000 | |||
16 | +++ surveilr/messaging/sms/__init__.py 2011-12-20 11:09:28 +0000 | |||
17 | @@ -16,37 +16,22 @@ | |||
18 | 16 | You should have received a copy of the GNU Affero General Public | 16 | You should have received a copy of the GNU Affero General Public |
19 | 17 | License along with this program. If not, see | 17 | License along with this program. If not, see |
20 | 18 | <http://www.gnu.org/licenses/>. | 18 | <http://www.gnu.org/licenses/>. |
21 | 19 | |||
22 | 20 | SMS messaging driver | ||
23 | 21 | """ | 19 | """ |
24 | 22 | 20 | ||
25 | 23 | from surveilr import config | 21 | from surveilr import config |
26 | 24 | from surveilr import drivers | 22 | from surveilr import drivers |
27 | 25 | 23 | ||
30 | 26 | from clickatell.api import Clickatell | 24 | import surveilr.messaging.sms.fake |
31 | 27 | from clickatell import constants as cc | 25 | import surveilr.messaging.sms.clickatell_driver |
32 | 26 | import surveilr.messaging.sms.bulksms_driver | ||
33 | 28 | 27 | ||
34 | 29 | 28 | ||
35 | 30 | class SMSMessaging(object): | 29 | class SMSMessaging(object): |
36 | 31 | def __init__(self): | 30 | def __init__(self): |
49 | 32 | username = config.get_str('sms', 'username') | 31 | driver_name = config.get_str('sms', 'driver') |
50 | 33 | password = config.get_str('sms', 'password') | 32 | self.driver = drivers.get_driver('sms', driver_name) |
39 | 34 | api_id = config.get_str('sms', 'api_id') | ||
40 | 35 | self.client = Clickatell(username, password, api_id, | ||
41 | 36 | sendmsg_defaults={ | ||
42 | 37 | 'callback': cc.YES, | ||
43 | 38 | 'msg_type': cc.SMS_DEFAULT, | ||
44 | 39 | 'deliv_ack': cc.YES, | ||
45 | 40 | 'req_feat': (cc.FEAT_ALPHA + | ||
46 | 41 | cc.FEAT_NUMER + | ||
47 | 42 | cc.FEAT_DELIVACK) | ||
48 | 43 | }) | ||
51 | 44 | 33 | ||
52 | 45 | def send(self, recipient, info): | 34 | def send(self, recipient, info): |
58 | 46 | sender = config.get_str('sms', 'sender') | 35 | return self.driver.send(recipient, info) |
54 | 47 | self.client.sendmsg(recipients=[recipient.messaging_address], | ||
55 | 48 | sender=sender, | ||
56 | 49 | text=str(info)) | ||
57 | 50 | |||
59 | 51 | 36 | ||
60 | 52 | drivers.register_driver('messaging', 'sms', SMSMessaging()) | 37 | drivers.register_driver('messaging', 'sms', SMSMessaging()) |
61 | 53 | 38 | ||
62 | === added file 'surveilr/messaging/sms/bulksms_driver.py' | |||
63 | --- surveilr/messaging/sms/bulksms_driver.py 1970-01-01 00:00:00 +0000 | |||
64 | +++ surveilr/messaging/sms/bulksms_driver.py 2011-12-20 11:09:28 +0000 | |||
65 | @@ -0,0 +1,47 @@ | |||
66 | 1 | """ | ||
67 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
68 | 3 | |||
69 | 4 | Copyright (C) 2011 Linux2Go | ||
70 | 5 | |||
71 | 6 | This program is free software: you can redistribute it and/or | ||
72 | 7 | modify it under the terms of the GNU Affero General Public License | ||
73 | 8 | as published by the Free Software Foundation, either version 3 of | ||
74 | 9 | the License, or (at your option) any later version. | ||
75 | 10 | |||
76 | 11 | This program is distributed in the hope that it will be useful, | ||
77 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
78 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
79 | 14 | GNU Affero General Public License for more details. | ||
80 | 15 | |||
81 | 16 | You should have received a copy of the GNU Affero General Public | ||
82 | 17 | License along with this program. If not, see | ||
83 | 18 | <http://www.gnu.org/licenses/>. | ||
84 | 19 | |||
85 | 20 | BulkSMS driver | ||
86 | 21 | """ | ||
87 | 22 | from surveilr import config | ||
88 | 23 | from surveilr import drivers | ||
89 | 24 | |||
90 | 25 | import BulkSMS | ||
91 | 26 | |||
92 | 27 | |||
93 | 28 | class BulkSMSMessaging(object): | ||
94 | 29 | def __init__(self): | ||
95 | 30 | username = config.get_str('sms', 'username') | ||
96 | 31 | password = config.get_str('sms', 'password') | ||
97 | 32 | kwargs = {} | ||
98 | 33 | try: | ||
99 | 34 | kwargs['server'] = config.get_str('sms', 'server') | ||
100 | 35 | except config.NoOptionError: | ||
101 | 36 | pass | ||
102 | 37 | |||
103 | 38 | self.client = BulkSMS.Server(username, password, **kwargs) | ||
104 | 39 | |||
105 | 40 | def send(self, recipient, info): | ||
106 | 41 | sender = config.get_str('sms', 'sender') | ||
107 | 42 | self.client.send_sms(recipients=[recipient.messaging_address], | ||
108 | 43 | sender=sender, | ||
109 | 44 | text=str(info)) | ||
110 | 45 | |||
111 | 46 | |||
112 | 47 | drivers.register_driver('sms', 'bulksms', BulkSMSMessaging()) | ||
113 | 0 | 48 | ||
114 | === added file 'surveilr/messaging/sms/clickatell_driver.py' | |||
115 | --- surveilr/messaging/sms/clickatell_driver.py 1970-01-01 00:00:00 +0000 | |||
116 | +++ surveilr/messaging/sms/clickatell_driver.py 2011-12-20 11:09:28 +0000 | |||
117 | @@ -0,0 +1,51 @@ | |||
118 | 1 | """ | ||
119 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
120 | 3 | |||
121 | 4 | Copyright (C) 2011 Linux2Go | ||
122 | 5 | |||
123 | 6 | This program is free software: you can redistribute it and/or | ||
124 | 7 | modify it under the terms of the GNU Affero General Public License | ||
125 | 8 | as published by the Free Software Foundation, either version 3 of | ||
126 | 9 | the License, or (at your option) any later version. | ||
127 | 10 | |||
128 | 11 | This program is distributed in the hope that it will be useful, | ||
129 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
130 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
131 | 14 | GNU Affero General Public License for more details. | ||
132 | 15 | |||
133 | 16 | You should have received a copy of the GNU Affero General Public | ||
134 | 17 | License along with this program. If not, see | ||
135 | 18 | <http://www.gnu.org/licenses/>. | ||
136 | 19 | |||
137 | 20 | Clickatell SMS driver | ||
138 | 21 | """ | ||
139 | 22 | from surveilr import config | ||
140 | 23 | from surveilr import drivers | ||
141 | 24 | |||
142 | 25 | from clickatell.api import Clickatell | ||
143 | 26 | from clickatell import constants as cc | ||
144 | 27 | |||
145 | 28 | |||
146 | 29 | class ClickatellMessaging(object): | ||
147 | 30 | def __init__(self): | ||
148 | 31 | username = config.get_str('sms', 'username') | ||
149 | 32 | password = config.get_str('sms', 'password') | ||
150 | 33 | api_id = config.get_str('sms', 'api_id') | ||
151 | 34 | self.client = Clickatell(username, password, api_id, | ||
152 | 35 | sendmsg_defaults={ | ||
153 | 36 | 'callback': cc.YES, | ||
154 | 37 | 'msg_type': cc.SMS_DEFAULT, | ||
155 | 38 | 'deliv_ack': cc.YES, | ||
156 | 39 | 'req_feat': (cc.FEAT_ALPHA + | ||
157 | 40 | cc.FEAT_NUMER + | ||
158 | 41 | cc.FEAT_DELIVACK) | ||
159 | 42 | }) | ||
160 | 43 | |||
161 | 44 | def send(self, recipient, info): | ||
162 | 45 | sender = config.get_str('sms', 'sender') | ||
163 | 46 | self.client.sendmsg(recipients=[recipient.messaging_address], | ||
164 | 47 | sender=sender, | ||
165 | 48 | text=str(info)) | ||
166 | 49 | |||
167 | 50 | |||
168 | 51 | drivers.register_driver('sms', 'clickatell', ClickatellMessaging()) | ||
169 | 0 | 52 | ||
170 | === added file 'surveilr/messaging/sms/fake.py' | |||
171 | --- surveilr/messaging/sms/fake.py 1970-01-01 00:00:00 +0000 | |||
172 | +++ surveilr/messaging/sms/fake.py 2011-12-20 11:09:28 +0000 | |||
173 | @@ -0,0 +1,32 @@ | |||
174 | 1 | """ | ||
175 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
176 | 3 | |||
177 | 4 | Copyright (C) 2011 Linux2Go | ||
178 | 5 | |||
179 | 6 | This program is free software: you can redistribute it and/or | ||
180 | 7 | modify it under the terms of the GNU Affero General Public License | ||
181 | 8 | as published by the Free Software Foundation, either version 3 of | ||
182 | 9 | the License, or (at your option) any later version. | ||
183 | 10 | |||
184 | 11 | This program is distributed in the hope that it will be useful, | ||
185 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
186 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
187 | 14 | GNU Affero General Public License for more details. | ||
188 | 15 | |||
189 | 16 | You should have received a copy of the GNU Affero General Public | ||
190 | 17 | License along with this program. If not, see | ||
191 | 18 | <http://www.gnu.org/licenses/>. | ||
192 | 19 | |||
193 | 20 | Fake SMS driver | ||
194 | 21 | """ | ||
195 | 22 | |||
196 | 23 | from surveilr import drivers | ||
197 | 24 | |||
198 | 25 | |||
199 | 26 | class FakeMessaging(object): | ||
200 | 27 | msgs = [] | ||
201 | 28 | |||
202 | 29 | def send(self, recipient, info): | ||
203 | 30 | self.msgs.append((recipient, info)) | ||
204 | 31 | |||
205 | 32 | drivers.register_driver('sms', 'fake', FakeMessaging()) | ||
206 | 0 | 33 | ||
207 | === modified file 'surveilr/tests/__init__.py' | |||
208 | --- surveilr/tests/__init__.py 2011-11-30 09:32:31 +0000 | |||
209 | +++ surveilr/tests/__init__.py 2011-12-20 11:09:28 +0000 | |||
210 | @@ -20,6 +20,7 @@ | |||
211 | 20 | 20 | ||
212 | 21 | import mock | 21 | import mock |
213 | 22 | import os.path | 22 | import os.path |
214 | 23 | import riakalchemy | ||
215 | 23 | import unittest | 24 | import unittest |
216 | 24 | 25 | ||
217 | 25 | from surveilr import config | 26 | from surveilr import config |
218 | @@ -39,8 +40,13 @@ | |||
219 | 39 | return os.path.join(os.path.dirname(__file__), | 40 | return os.path.join(os.path.dirname(__file__), |
220 | 40 | os.path.pardir, 'defaults.cfg') | 41 | os.path.pardir, 'defaults.cfg') |
221 | 41 | 42 | ||
222 | 43 | def set_cfg_value(self, section, option, value): | ||
223 | 44 | config.cfg.set(section, option, value) | ||
224 | 45 | |||
225 | 42 | def setUp(self): | 46 | def setUp(self): |
226 | 43 | super(TestCase, self).setUp() | 47 | super(TestCase, self).setUp() |
227 | 48 | riakalchemy.connect() | ||
228 | 49 | |||
229 | 44 | with mock.patch('surveilr.config.defaults_file') as defaults_file: | 50 | with mock.patch('surveilr.config.defaults_file') as defaults_file: |
230 | 45 | with mock.patch('surveilr.config.config_files') as config_files: | 51 | with mock.patch('surveilr.config.config_files') as config_files: |
231 | 46 | config_files.return_value = self.config_files() | 52 | config_files.return_value = self.config_files() |
232 | 47 | 53 | ||
233 | === modified file 'surveilr/tests/api/test_server.py' | |||
234 | --- surveilr/tests/api/test_server.py 2011-12-20 09:49:02 +0000 | |||
235 | +++ surveilr/tests/api/test_server.py 2011-12-20 11:09:28 +0000 | |||
236 | @@ -33,8 +33,7 @@ | |||
237 | 33 | 33 | ||
238 | 34 | class APIServerTests(tests.TestCase): | 34 | class APIServerTests(tests.TestCase): |
239 | 35 | def setUp(self): | 35 | def setUp(self): |
242 | 36 | import riakalchemy | 36 | super(APIServerTests, self).setUp() |
241 | 37 | riakalchemy.connect() | ||
243 | 38 | self.application = SurveilrApplication({}) | 37 | self.application = SurveilrApplication({}) |
244 | 39 | 38 | ||
245 | 40 | def test_create_retrieve_user(self): | 39 | def test_create_retrieve_user(self): |
246 | 41 | 40 | ||
247 | === added directory 'surveilr/tests/messaging' | |||
248 | === added file 'surveilr/tests/messaging/__init__.py' | |||
249 | --- surveilr/tests/messaging/__init__.py 1970-01-01 00:00:00 +0000 | |||
250 | +++ surveilr/tests/messaging/__init__.py 2011-12-20 11:09:28 +0000 | |||
251 | @@ -0,0 +1,19 @@ | |||
252 | 1 | """ | ||
253 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
254 | 3 | |||
255 | 4 | Copyright (C) 2011 Linux2Go | ||
256 | 5 | |||
257 | 6 | This program is free software: you can redistribute it and/or | ||
258 | 7 | modify it under the terms of the GNU Affero General Public License | ||
259 | 8 | as published by the Free Software Foundation, either version 3 of | ||
260 | 9 | the License, or (at your option) any later version. | ||
261 | 10 | |||
262 | 11 | This program is distributed in the hope that it will be useful, | ||
263 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
264 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
265 | 14 | GNU Affero General Public License for more details. | ||
266 | 15 | |||
267 | 16 | You should have received a copy of the GNU Affero General Public | ||
268 | 17 | License along with this program. If not, see | ||
269 | 18 | <http://www.gnu.org/licenses/>. | ||
270 | 19 | """ | ||
271 | 0 | 20 | ||
272 | === added directory 'surveilr/tests/messaging/sms' | |||
273 | === added file 'surveilr/tests/messaging/sms/__init__.py' | |||
274 | --- surveilr/tests/messaging/sms/__init__.py 1970-01-01 00:00:00 +0000 | |||
275 | +++ surveilr/tests/messaging/sms/__init__.py 2011-12-20 11:09:28 +0000 | |||
276 | @@ -0,0 +1,19 @@ | |||
277 | 1 | """ | ||
278 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
279 | 3 | |||
280 | 4 | Copyright (C) 2011 Linux2Go | ||
281 | 5 | |||
282 | 6 | This program is free software: you can redistribute it and/or | ||
283 | 7 | modify it under the terms of the GNU Affero General Public License | ||
284 | 8 | as published by the Free Software Foundation, either version 3 of | ||
285 | 9 | the License, or (at your option) any later version. | ||
286 | 10 | |||
287 | 11 | This program is distributed in the hope that it will be useful, | ||
288 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
289 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
290 | 14 | GNU Affero General Public License for more details. | ||
291 | 15 | |||
292 | 16 | You should have received a copy of the GNU Affero General Public | ||
293 | 17 | License along with this program. If not, see | ||
294 | 18 | <http://www.gnu.org/licenses/>. | ||
295 | 19 | """ | ||
296 | 0 | 20 | ||
297 | === added file 'surveilr/tests/messaging/sms/test_base.cfg' | |||
298 | --- surveilr/tests/messaging/sms/test_base.cfg 1970-01-01 00:00:00 +0000 | |||
299 | +++ surveilr/tests/messaging/sms/test_base.cfg 2011-12-20 11:09:28 +0000 | |||
300 | @@ -0,0 +1,2 @@ | |||
301 | 1 | [sms] | ||
302 | 2 | driver = not_your_average_sms_driver | ||
303 | 0 | 3 | ||
304 | === added file 'surveilr/tests/messaging/sms/test_base.py' | |||
305 | --- surveilr/tests/messaging/sms/test_base.py 1970-01-01 00:00:00 +0000 | |||
306 | +++ surveilr/tests/messaging/sms/test_base.py 2011-12-20 11:09:28 +0000 | |||
307 | @@ -0,0 +1,43 @@ | |||
308 | 1 | """ | ||
309 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
310 | 3 | |||
311 | 4 | Copyright (C) 2011 Linux2Go | ||
312 | 5 | |||
313 | 6 | This program is free software: you can redistribute it and/or | ||
314 | 7 | modify it under the terms of the GNU Affero General Public License | ||
315 | 8 | as published by the Free Software Foundation, either version 3 of | ||
316 | 9 | the License, or (at your option) any later version. | ||
317 | 10 | |||
318 | 11 | This program is distributed in the hope that it will be useful, | ||
319 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
320 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
321 | 14 | GNU Affero General Public License for more details. | ||
322 | 15 | |||
323 | 16 | You should have received a copy of the GNU Affero General Public | ||
324 | 17 | License along with this program. If not, see | ||
325 | 18 | <http://www.gnu.org/licenses/>. | ||
326 | 19 | """ | ||
327 | 20 | |||
328 | 21 | import mock | ||
329 | 22 | |||
330 | 23 | from surveilr import tests | ||
331 | 24 | from surveilr.messaging import sms | ||
332 | 25 | |||
333 | 26 | |||
334 | 27 | class SMSMessagingTest(tests.TestCase): | ||
335 | 28 | @mock.patch('surveilr.messaging.sms.drivers') | ||
336 | 29 | def test_init(self, drivers): | ||
337 | 30 | sms.SMSMessaging() | ||
338 | 31 | drivers.get_driver.assert_called_with('sms', | ||
339 | 32 | 'not_your_average_sms_driver') | ||
340 | 33 | |||
341 | 34 | @mock.patch('surveilr.messaging.sms.drivers') | ||
342 | 35 | def test_send(self, drivers): | ||
343 | 36 | drv = sms.SMSMessaging() | ||
344 | 37 | recipient = mock.sentinel.recipient | ||
345 | 38 | info = mock.sentinel.info | ||
346 | 39 | |||
347 | 40 | drv.send(recipient, info) | ||
348 | 41 | |||
349 | 42 | drivers.get_driver.return_value.send.assert_called_with(recipient, | ||
350 | 43 | info) | ||
351 | 0 | 44 | ||
352 | === added file 'surveilr/tests/messaging/sms/test_bulksms.cfg' | |||
353 | --- surveilr/tests/messaging/sms/test_bulksms.cfg 1970-01-01 00:00:00 +0000 | |||
354 | +++ surveilr/tests/messaging/sms/test_bulksms.cfg 2011-12-20 11:09:28 +0000 | |||
355 | @@ -0,0 +1,6 @@ | |||
356 | 1 | [sms] | ||
357 | 2 | driver = bulksms | ||
358 | 3 | username = testuser | ||
359 | 4 | password = testpassword | ||
360 | 5 | api_id = testapiid | ||
361 | 6 | sender = testsender | ||
362 | 0 | 7 | ||
363 | === added file 'surveilr/tests/messaging/sms/test_bulksms.py' | |||
364 | --- surveilr/tests/messaging/sms/test_bulksms.py 1970-01-01 00:00:00 +0000 | |||
365 | +++ surveilr/tests/messaging/sms/test_bulksms.py 2011-12-20 11:09:28 +0000 | |||
366 | @@ -0,0 +1,56 @@ | |||
367 | 1 | """ | ||
368 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
369 | 3 | |||
370 | 4 | Copyright (C) 2011 Linux2Go | ||
371 | 5 | |||
372 | 6 | This program is free software: you can redistribute it and/or | ||
373 | 7 | modify it under the terms of the GNU Affero General Public License | ||
374 | 8 | as published by the Free Software Foundation, either version 3 of | ||
375 | 9 | the License, or (at your option) any later version. | ||
376 | 10 | |||
377 | 11 | This program is distributed in the hope that it will be useful, | ||
378 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
379 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
380 | 14 | GNU Affero General Public License for more details. | ||
381 | 15 | |||
382 | 16 | You should have received a copy of the GNU Affero General Public | ||
383 | 17 | License along with this program. If not, see | ||
384 | 18 | <http://www.gnu.org/licenses/>. | ||
385 | 19 | |||
386 | 20 | Tests for BulkSMS driver | ||
387 | 21 | """ | ||
388 | 22 | |||
389 | 23 | import mock | ||
390 | 24 | |||
391 | 25 | from surveilr import tests | ||
392 | 26 | from surveilr.messaging.sms import bulksms_driver | ||
393 | 27 | from surveilr.tests import utils | ||
394 | 28 | |||
395 | 29 | |||
396 | 30 | class BulkSMSDriverTests(tests.TestCase): | ||
397 | 31 | @mock.patch('surveilr.messaging.sms.bulksms_driver.BulkSMS') | ||
398 | 32 | def test_instantiate_client(self, BulkSMS): | ||
399 | 33 | self.driver = bulksms_driver.BulkSMSMessaging() | ||
400 | 34 | BulkSMS.Server.assert_called_with('testuser', 'testpassword') | ||
401 | 35 | |||
402 | 36 | @mock.patch('surveilr.messaging.sms.bulksms_driver.BulkSMS') | ||
403 | 37 | def test_instantiate_client_override_server(self, BulkSMS): | ||
404 | 38 | self.set_cfg_value('sms', 'server', 'testserver') | ||
405 | 39 | self.driver = bulksms_driver.BulkSMSMessaging() | ||
406 | 40 | BulkSMS.Server.assert_called_with('testuser', 'testpassword', | ||
407 | 41 | server='testserver') | ||
408 | 42 | |||
409 | 43 | def test_send(self): | ||
410 | 44 | driver = bulksms_driver.BulkSMSMessaging() | ||
411 | 45 | driver.client = mock.Mock() | ||
412 | 46 | |||
413 | 47 | msisdn = '12345678' | ||
414 | 48 | user = utils.get_test_user(messaging_driver='sms', | ||
415 | 49 | messaging_address=msisdn) | ||
416 | 50 | info = utils.get_test_notification_info() | ||
417 | 51 | |||
418 | 52 | driver.send(user, info) | ||
419 | 53 | |||
420 | 54 | driver.client.send_sms.assert_called_with(recipients=[msisdn], | ||
421 | 55 | sender='testsender', | ||
422 | 56 | text=str(info)) | ||
423 | 0 | 57 | ||
424 | === renamed file 'surveilr/tests/test_messaging.cfg' => 'surveilr/tests/messaging/sms/test_clickatell.cfg' | |||
425 | --- surveilr/tests/test_messaging.cfg 2011-11-29 23:41:46 +0000 | |||
426 | +++ surveilr/tests/messaging/sms/test_clickatell.cfg 2011-12-20 11:09:28 +0000 | |||
427 | @@ -1,4 +1,5 @@ | |||
428 | 1 | [sms] | 1 | [sms] |
429 | 2 | driver = clickatell | ||
430 | 2 | username = testuser | 3 | username = testuser |
431 | 3 | password = testpassword | 4 | password = testpassword |
432 | 4 | api_id = testapiid | 5 | api_id = testapiid |
433 | 5 | 6 | ||
434 | === renamed file 'surveilr/tests/test_messaging.py' => 'surveilr/tests/messaging/sms/test_clickatell.py' | |||
435 | --- surveilr/tests/test_messaging.py 2011-12-20 09:49:02 +0000 | |||
436 | +++ surveilr/tests/messaging/sms/test_clickatell.py 2011-12-20 11:09:28 +0000 | |||
437 | @@ -17,38 +17,20 @@ | |||
438 | 17 | License along with this program. If not, see | 17 | License along with this program. If not, see |
439 | 18 | <http://www.gnu.org/licenses/>. | 18 | <http://www.gnu.org/licenses/>. |
440 | 19 | 19 | ||
442 | 20 | Tests for messaging layer | 20 | Tests for Clickatell driver |
443 | 21 | """ | 21 | """ |
444 | 22 | 22 | ||
445 | 23 | import mock | 23 | import mock |
446 | 24 | 24 | ||
447 | 25 | from surveilr import drivers | ||
448 | 26 | from surveilr import messaging | ||
449 | 27 | from surveilr import tests | 25 | from surveilr import tests |
451 | 28 | from surveilr.messaging import sms | 26 | from surveilr.messaging.sms import clickatell_driver |
452 | 29 | from surveilr.tests import utils | 27 | from surveilr.tests import utils |
453 | 30 | 28 | ||
454 | 31 | 29 | ||
473 | 32 | class FakeMessagingDriverTests(tests.TestCase): | 30 | class ClickatellDriverTests(tests.TestCase): |
474 | 33 | def setUp(self): | 31 | @mock.patch('surveilr.messaging.sms.clickatell_driver.Clickatell') |
457 | 34 | import surveilr.messaging.fake | ||
458 | 35 | # This does nothing, but pyflakes gets upset if we import it | ||
459 | 36 | # and never "use" it. | ||
460 | 37 | surveilr.messaging.fake | ||
461 | 38 | self.driver = drivers.get_driver('messaging', 'fake') | ||
462 | 39 | |||
463 | 40 | def test_send(self): | ||
464 | 41 | user = utils.get_test_user() | ||
465 | 42 | info = {'service': 'service_id', | ||
466 | 43 | 'state': 'normal', | ||
467 | 44 | 'previous_state': 'unexpected high'} | ||
468 | 45 | self.driver.send(user, info) | ||
469 | 46 | |||
470 | 47 | |||
471 | 48 | class SMSMessagingDriverTests(tests.TestCase): | ||
472 | 49 | @mock.patch('surveilr.messaging.sms.Clickatell') | ||
475 | 50 | def test_instantiate_client(self, clickatell): | 32 | def test_instantiate_client(self, clickatell): |
477 | 51 | self.driver = sms.SMSMessaging() | 33 | self.driver = clickatell_driver.ClickatellMessaging() |
478 | 52 | 34 | ||
479 | 53 | sendmsg_defaults = {'callback': 1, | 35 | sendmsg_defaults = {'callback': 1, |
480 | 54 | 'req_feat': 8240, | 36 | 'req_feat': 8240, |
481 | @@ -58,7 +40,7 @@ | |||
482 | 58 | sendmsg_defaults=sendmsg_defaults) | 40 | sendmsg_defaults=sendmsg_defaults) |
483 | 59 | 41 | ||
484 | 60 | def test_send(self): | 42 | def test_send(self): |
486 | 61 | driver = sms.SMSMessaging() | 43 | driver = clickatell_driver.ClickatellMessaging() |
487 | 62 | driver.client = mock.Mock() | 44 | driver.client = mock.Mock() |
488 | 63 | 45 | ||
489 | 64 | msisdn = '12345678' | 46 | msisdn = '12345678' |
490 | @@ -71,43 +53,3 @@ | |||
491 | 71 | driver.client.sendmsg.assert_called_with(recipients=[msisdn], | 53 | driver.client.sendmsg.assert_called_with(recipients=[msisdn], |
492 | 72 | sender='testsender', | 54 | sender='testsender', |
493 | 73 | text=str(info)) | 55 | text=str(info)) |
494 | 74 | |||
495 | 75 | |||
496 | 76 | class MessagingAPITests(tests.TestCase): | ||
497 | 77 | def test_send(self): | ||
498 | 78 | user = utils.get_test_user() | ||
499 | 79 | info = {'service': 'service_id', | ||
500 | 80 | 'state': 'normal', | ||
501 | 81 | 'previous_state': 'unexpected high'} | ||
502 | 82 | |||
503 | 83 | with mock.patch('surveilr.messaging._get_driver') as _get_driver: | ||
504 | 84 | messaging.send(user, info) | ||
505 | 85 | |||
506 | 86 | # Check that _get_driver gets called with the user as its argument | ||
507 | 87 | _get_driver.assert_called_with(user) | ||
508 | 88 | |||
509 | 89 | # Check that _get_driver's return value (i.e. the driver) | ||
510 | 90 | # gets its .send() method called with user and info as its | ||
511 | 91 | # arguments | ||
512 | 92 | _get_driver.return_value.send.assert_called_with(user, info) | ||
513 | 93 | |||
514 | 94 | def test_get_driver_default(self): | ||
515 | 95 | user = utils.get_test_user() | ||
516 | 96 | expected_driver = drivers.get_driver('messaging', 'fake') | ||
517 | 97 | |||
518 | 98 | actual_driver = messaging._get_driver(user) | ||
519 | 99 | self.assertEquals(actual_driver, expected_driver) | ||
520 | 100 | |||
521 | 101 | def test_get_driver_sms(self): | ||
522 | 102 | user = utils.get_test_user(messaging_driver='sms') | ||
523 | 103 | expected_driver = drivers.get_driver('messaging', 'sms') | ||
524 | 104 | |||
525 | 105 | actual_driver = messaging._get_driver(user) | ||
526 | 106 | self.assertEquals(actual_driver, expected_driver) | ||
527 | 107 | |||
528 | 108 | def test_get_driver_fake(self): | ||
529 | 109 | user = utils.get_test_user(messaging_driver='fake') | ||
530 | 110 | expected_driver = drivers.get_driver('messaging', 'fake') | ||
531 | 111 | |||
532 | 112 | actual_driver = messaging._get_driver(user) | ||
533 | 113 | self.assertEquals(actual_driver, expected_driver) | ||
534 | 114 | 56 | ||
535 | === added file 'surveilr/tests/messaging/sms/test_fake.py' | |||
536 | --- surveilr/tests/messaging/sms/test_fake.py 1970-01-01 00:00:00 +0000 | |||
537 | +++ surveilr/tests/messaging/sms/test_fake.py 2011-12-20 11:09:28 +0000 | |||
538 | @@ -0,0 +1,39 @@ | |||
539 | 1 | """ | ||
540 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
541 | 3 | |||
542 | 4 | Copyright (C) 2011 Linux2Go | ||
543 | 5 | |||
544 | 6 | This program is free software: you can redistribute it and/or | ||
545 | 7 | modify it under the terms of the GNU Affero General Public License | ||
546 | 8 | as published by the Free Software Foundation, either version 3 of | ||
547 | 9 | the License, or (at your option) any later version. | ||
548 | 10 | |||
549 | 11 | This program is distributed in the hope that it will be useful, | ||
550 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
551 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
552 | 14 | GNU Affero General Public License for more details. | ||
553 | 15 | |||
554 | 16 | You should have received a copy of the GNU Affero General Public | ||
555 | 17 | License along with this program. If not, see | ||
556 | 18 | <http://www.gnu.org/licenses/>. | ||
557 | 19 | """ | ||
558 | 20 | |||
559 | 21 | import mock | ||
560 | 22 | |||
561 | 23 | from surveilr import tests | ||
562 | 24 | from surveilr.messaging.sms import fake | ||
563 | 25 | |||
564 | 26 | |||
565 | 27 | class FakeSMSMessagingTest(tests.TestCase): | ||
566 | 28 | def test_send(self): | ||
567 | 29 | recipient1 = mock.sentinel.recipient1 | ||
568 | 30 | info1 = mock.sentinel.info1 | ||
569 | 31 | recipient2 = mock.sentinel.recipient2 | ||
570 | 32 | info2 = mock.sentinel.info2 | ||
571 | 33 | |||
572 | 34 | drv = fake.FakeMessaging() | ||
573 | 35 | drv.send(recipient1, info1) | ||
574 | 36 | drv.send(recipient2, info2) | ||
575 | 37 | |||
576 | 38 | self.assertEquals(drv.msgs, [(recipient1, info1), | ||
577 | 39 | (recipient2, info2)]) | ||
578 | 0 | 40 | ||
579 | === added file 'surveilr/tests/messaging/test_base.py' | |||
580 | --- surveilr/tests/messaging/test_base.py 1970-01-01 00:00:00 +0000 | |||
581 | +++ surveilr/tests/messaging/test_base.py 2011-12-20 11:09:28 +0000 | |||
582 | @@ -0,0 +1,68 @@ | |||
583 | 1 | """ | ||
584 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
585 | 3 | |||
586 | 4 | Copyright (C) 2011 Linux2Go | ||
587 | 5 | |||
588 | 6 | This program is free software: you can redistribute it and/or | ||
589 | 7 | modify it under the terms of the GNU Affero General Public License | ||
590 | 8 | as published by the Free Software Foundation, either version 3 of | ||
591 | 9 | the License, or (at your option) any later version. | ||
592 | 10 | |||
593 | 11 | This program is distributed in the hope that it will be useful, | ||
594 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
595 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
596 | 14 | GNU Affero General Public License for more details. | ||
597 | 15 | |||
598 | 16 | You should have received a copy of the GNU Affero General Public | ||
599 | 17 | License along with this program. If not, see | ||
600 | 18 | <http://www.gnu.org/licenses/>. | ||
601 | 19 | |||
602 | 20 | Tests for messaging layer | ||
603 | 21 | """ | ||
604 | 22 | |||
605 | 23 | import mock | ||
606 | 24 | |||
607 | 25 | from surveilr import drivers | ||
608 | 26 | from surveilr import messaging | ||
609 | 27 | from surveilr import tests | ||
610 | 28 | from surveilr.tests import utils | ||
611 | 29 | |||
612 | 30 | |||
613 | 31 | class MessagingAPITests(tests.TestCase): | ||
614 | 32 | def test_send(self): | ||
615 | 33 | user = utils.get_test_user() | ||
616 | 34 | info = {'service': 'service_id', | ||
617 | 35 | 'state': 'normal', | ||
618 | 36 | 'previous_state': 'unexpected high'} | ||
619 | 37 | |||
620 | 38 | with mock.patch('surveilr.messaging._get_driver') as _get_driver: | ||
621 | 39 | messaging.send(user, info) | ||
622 | 40 | |||
623 | 41 | # Check that _get_driver gets called with the user as its argument | ||
624 | 42 | _get_driver.assert_called_with(user) | ||
625 | 43 | |||
626 | 44 | # Check that _get_driver's return value (i.e. the driver) | ||
627 | 45 | # gets its .send() method called with user and info as its | ||
628 | 46 | # arguments | ||
629 | 47 | _get_driver.return_value.send.assert_called_with(user, info) | ||
630 | 48 | |||
631 | 49 | def test_get_driver_default(self): | ||
632 | 50 | user = utils.get_test_user() | ||
633 | 51 | expected_driver = drivers.get_driver('messaging', 'fake') | ||
634 | 52 | |||
635 | 53 | actual_driver = messaging._get_driver(user) | ||
636 | 54 | self.assertEquals(actual_driver, expected_driver) | ||
637 | 55 | |||
638 | 56 | def test_get_driver_sms(self): | ||
639 | 57 | user = utils.get_test_user(messaging_driver='sms') | ||
640 | 58 | expected_driver = drivers.get_driver('messaging', 'sms') | ||
641 | 59 | |||
642 | 60 | actual_driver = messaging._get_driver(user) | ||
643 | 61 | self.assertEquals(actual_driver, expected_driver) | ||
644 | 62 | |||
645 | 63 | def test_get_driver_fake(self): | ||
646 | 64 | user = utils.get_test_user(messaging_driver='fake') | ||
647 | 65 | expected_driver = drivers.get_driver('messaging', 'fake') | ||
648 | 66 | |||
649 | 67 | actual_driver = messaging._get_driver(user) | ||
650 | 68 | self.assertEquals(actual_driver, expected_driver) | ||
651 | 0 | 69 | ||
652 | === added file 'surveilr/tests/messaging/test_fake.py' | |||
653 | --- surveilr/tests/messaging/test_fake.py 1970-01-01 00:00:00 +0000 | |||
654 | +++ surveilr/tests/messaging/test_fake.py 2011-12-20 11:09:28 +0000 | |||
655 | @@ -0,0 +1,41 @@ | |||
656 | 1 | """ | ||
657 | 2 | Surveilr - Log aggregation, analysis and visualisation | ||
658 | 3 | |||
659 | 4 | Copyright (C) 2011 Linux2Go | ||
660 | 5 | |||
661 | 6 | This program is free software: you can redistribute it and/or | ||
662 | 7 | modify it under the terms of the GNU Affero General Public License | ||
663 | 8 | as published by the Free Software Foundation, either version 3 of | ||
664 | 9 | the License, or (at your option) any later version. | ||
665 | 10 | |||
666 | 11 | This program is distributed in the hope that it will be useful, | ||
667 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
668 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
669 | 14 | GNU Affero General Public License for more details. | ||
670 | 15 | |||
671 | 16 | You should have received a copy of the GNU Affero General Public | ||
672 | 17 | License along with this program. If not, see | ||
673 | 18 | <http://www.gnu.org/licenses/>. | ||
674 | 19 | |||
675 | 20 | Tests for fake messaging driver | ||
676 | 21 | """ | ||
677 | 22 | |||
678 | 23 | from surveilr import drivers | ||
679 | 24 | from surveilr import tests | ||
680 | 25 | from surveilr.tests import utils | ||
681 | 26 | |||
682 | 27 | |||
683 | 28 | class FakeMessagingDriverTests(tests.TestCase): | ||
684 | 29 | def setUp(self): | ||
685 | 30 | import surveilr.messaging.fake | ||
686 | 31 | # This does nothing, but pyflakes gets upset if we import it | ||
687 | 32 | # and never "use" it. | ||
688 | 33 | surveilr.messaging.fake | ||
689 | 34 | self.driver = drivers.get_driver('messaging', 'fake') | ||
690 | 35 | |||
691 | 36 | def test_send(self): | ||
692 | 37 | user = utils.get_test_user() | ||
693 | 38 | info = {'service': 'service_id', | ||
694 | 39 | 'state': 'normal', | ||
695 | 40 | 'previous_state': 'unexpected high'} | ||
696 | 41 | self.driver.send(user, info) | ||
697 | 0 | 42 | ||
698 | === modified file 'surveilr/tests/test_config.py' | |||
699 | --- surveilr/tests/test_config.py 2011-12-19 23:16:11 +0000 | |||
700 | +++ surveilr/tests/test_config.py 2011-12-20 11:09:28 +0000 | |||
701 | @@ -25,6 +25,7 @@ | |||
702 | 25 | 25 | ||
703 | 26 | import os.path | 26 | import os.path |
704 | 27 | 27 | ||
705 | 28 | |||
706 | 28 | class ConfigTest(tests.TestCase): | 29 | class ConfigTest(tests.TestCase): |
707 | 29 | def defaults_file(self): | 30 | def defaults_file(self): |
708 | 30 | return os.path.join(os.path.dirname(__file__), | 31 | return os.path.join(os.path.dirname(__file__), |
709 | 31 | 32 | ||
710 | === modified file 'tools/pip-requirements.txt' | |||
711 | --- tools/pip-requirements.txt 2011-12-18 14:25:14 +0000 | |||
712 | +++ tools/pip-requirements.txt 2011-12-20 11:09:28 +0000 | |||
713 | @@ -12,3 +12,4 @@ | |||
714 | 12 | pastedeploy | 12 | pastedeploy |
715 | 13 | paste | 13 | paste |
716 | 14 | PasteScript | 14 | PasteScript |
717 | 15 | -e hg+https://code.google.com/p/soren-bulksms/#egg=BulkSMS |
The attempt to merge lp:~soren/surveilr/bulksms into lp:surveilr failed. Below is the output from the failed tests.
New python executable in .venv/bin/python ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....done. ....... ....done. //github. com/basho/ riak-python- client. git@master# egg=riak (from -r tools/pip- requirements. txt (line 1)) com/basho/ riak-python- client. git (to master) to ./.venv/src/riak
Installing distribute.
Installing pip....
Obtaining riak from git+git:
Cloning git://github.
Running setup.py egg_info for package riak
warning: no files found matching 'erl_src/*' //github. com/Linux2Go/ riakalchemy. git@master# egg=riakalchemy (from -r tools/pip- requirements. txt (line 2)) com/Linux2Go/ riakalchemy. git (to master) to ./.venv/ src/riakalchemy
Obtaining riakalchemy from git+git:
Cloning git://github.
Running setup.py egg_info for package riakalchemy
Downloading/ unpacking nose (from -r tools/pip- requirements. txt (line 3)) jenkins/ .pip/cache/ http%3A% 2F%2Fpypi. python. org%2Fpackages% 2Fsource% 2Fn%2Fnose% 2Fnose- 1.1.2.tar. gz
Using download cache from /var/lib/
Running setup.py egg_info for package nose
Downloading/ unpacking routes (from -r tools/pip- requirements. txt (line 4)) jenkins/ .pip/cache/ http%3A% 2F%2Fpypi. python. org%2Fpackages% 2Fsource% 2FR%2FRoutes% 2FRoutes- 1.12.3. tar.gz
Using download cache from /var/lib/
Running setup.py egg_info for package routes
warning: no previously-included files matching '.DS_Store' found anywhere in distribution unpacking webob (from -r tools/pip- requirements. txt (line 5)) jenkins/ .pip/cache/ http%3A% 2F%2Fpypi. python. org%2Fpackages% 2Fsource% 2FW%2FWebOb% 2FWebOb- 1.2b2.zip
warning: no previously-included files matching '*.hgignore' found anywhere in distribution
warning: no previously-included files matching '*.hgtags' found anywhere in distribution
Downloading/
Using download cache from /var/lib/
Running setup.py egg_info for package webob
no previously-included directories found matching '*.pyc' unpacking python-clickatell (from -r tools/pip- requirements. txt (line 6)) jenkins/ .pip/cache/ http%3A% 2F%2Fpypi. python. org%2Fpackages% 2Fsource% 2Fp%2Fpython- clickatell% 2Fpython- clickatell- 0.1.3.tar. gz
no previously-included directories found matching '*.pyo'
Downloading/
Using download cache from /var/lib/
Running setup.py egg_info for package python-clickatell
Downloading/ unpacking mock (from -r tools/pip- requirements. txt (line 7)) jenkins/ .pip/cache/ http%3A% 2F%2Fpypi. python. org%2Fpackages% 2Fsource% 2Fm%2Fmock% 2Fmock- 0.7.2.zip
Using download cache from /var/lib/
Running setup.py egg_info for package mock
Downloading/ unpacking eventlet (from -r tools/pip- requirements. txt (line 8)) jenkins/ .pip/cache/ http%3A% 2F%2Fpypi. python. org%2Fpackages% 2Fsource% 2Fe%2Feventlet% 2Feventlet- 0.9.16. tar.gz
Using download cache from /var/lib/
Running setup.py egg_info for package eventlet
Downloading/ unpacking httplib2 (from -r tools/pip- requirements. txt (line 9)) jenkins/ .pip/cache/ http%3A% 2F%2Fhttplib2. ..
Using download cache from /var/lib/