Merge lp:~soren/surveilr/bulksms into lp:surveilr

Proposed by Soren Hansen
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
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 :
Download full text (5.8 KiB)

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
Installing distribute....................................................................................................................................................................................done.
Installing pip...............done.
Obtaining riak from git+git://github.com/basho/riak-python-client.git@master#egg=riak (from -r tools/pip-requirements.txt (line 1))
  Cloning git://github.com/basho/riak-python-client.git (to master) to ./.venv/src/riak
  Running setup.py egg_info for package riak

    warning: no files found matching 'erl_src/*'
Obtaining riakalchemy from git+git://github.com/Linux2Go/riakalchemy.git@master#egg=riakalchemy (from -r tools/pip-requirements.txt (line 2))
  Cloning git://github.com/Linux2Go/riakalchemy.git (to master) to ./.venv/src/riakalchemy
  Running setup.py egg_info for package riakalchemy

Downloading/unpacking nose (from -r tools/pip-requirements.txt (line 3))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fn%2Fnose%2Fnose-1.1.2.tar.gz
  Running setup.py egg_info for package nose

Downloading/unpacking routes (from -r tools/pip-requirements.txt (line 4))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FR%2FRoutes%2FRoutes-1.12.3.tar.gz
  Running setup.py egg_info for package routes

    warning: no previously-included files matching '.DS_Store' found anywhere in distribution
    warning: no previously-included files matching '*.hgignore' found anywhere in distribution
    warning: no previously-included files matching '*.hgtags' found anywhere in distribution
Downloading/unpacking webob (from -r tools/pip-requirements.txt (line 5))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FW%2FWebOb%2FWebOb-1.2b2.zip
  Running setup.py egg_info for package webob

    no previously-included directories found matching '*.pyc'
    no previously-included directories found matching '*.pyo'
Downloading/unpacking python-clickatell (from -r tools/pip-requirements.txt (line 6))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpython-clickatell%2Fpython-clickatell-0.1.3.tar.gz
  Running setup.py egg_info for package python-clickatell

Downloading/unpacking mock (from -r tools/pip-requirements.txt (line 7))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fm%2Fmock%2Fmock-0.7.2.zip
  Running setup.py egg_info for package mock

Downloading/unpacking eventlet (from -r tools/pip-requirements.txt (line 8))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fe%2Feventlet%2Feventlet-0.9.16.tar.gz
  Running setup.py egg_info for package eventlet

Downloading/unpacking httplib2 (from -r tools/pip-requirements.txt (line 9))
  Using download cache from /var/lib/jenkins/.pip/cache/http%3A%2F%2Fhttplib2...

Read more...

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 # This is where we stick defaults for various things
6
7 [sms]
8+driver = fake
9 username =
10 password =
11 api_id =
12
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 You should have received a copy of the GNU Affero General Public
19 License along with this program. If not, see
20 <http://www.gnu.org/licenses/>.
21-
22- SMS messaging driver
23 """
24
25 from surveilr import config
26 from surveilr import drivers
27
28-from clickatell.api import Clickatell
29-from clickatell import constants as cc
30+import surveilr.messaging.sms.fake
31+import surveilr.messaging.sms.clickatell_driver
32+import surveilr.messaging.sms.bulksms_driver
33
34
35 class SMSMessaging(object):
36 def __init__(self):
37- username = config.get_str('sms', 'username')
38- password = config.get_str('sms', 'password')
39- api_id = config.get_str('sms', 'api_id')
40- self.client = Clickatell(username, password, api_id,
41- sendmsg_defaults={
42- 'callback': cc.YES,
43- 'msg_type': cc.SMS_DEFAULT,
44- 'deliv_ack': cc.YES,
45- 'req_feat': (cc.FEAT_ALPHA +
46- cc.FEAT_NUMER +
47- cc.FEAT_DELIVACK)
48- })
49+ driver_name = config.get_str('sms', 'driver')
50+ self.driver = drivers.get_driver('sms', driver_name)
51
52 def send(self, recipient, info):
53- sender = config.get_str('sms', 'sender')
54- self.client.sendmsg(recipients=[recipient.messaging_address],
55- sender=sender,
56- text=str(info))
57-
58+ return self.driver.send(recipient, info)
59
60 drivers.register_driver('messaging', 'sms', SMSMessaging())
61
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+"""
67+ Surveilr - Log aggregation, analysis and visualisation
68+
69+ Copyright (C) 2011 Linux2Go
70+
71+ This program is free software: you can redistribute it and/or
72+ modify it under the terms of the GNU Affero General Public License
73+ as published by the Free Software Foundation, either version 3 of
74+ the License, or (at your option) any later version.
75+
76+ This program is distributed in the hope that it will be useful,
77+ but WITHOUT ANY WARRANTY; without even the implied warranty of
78+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79+ GNU Affero General Public License for more details.
80+
81+ You should have received a copy of the GNU Affero General Public
82+ License along with this program. If not, see
83+ <http://www.gnu.org/licenses/>.
84+
85+ BulkSMS driver
86+"""
87+from surveilr import config
88+from surveilr import drivers
89+
90+import BulkSMS
91+
92+
93+class BulkSMSMessaging(object):
94+ def __init__(self):
95+ username = config.get_str('sms', 'username')
96+ password = config.get_str('sms', 'password')
97+ kwargs = {}
98+ try:
99+ kwargs['server'] = config.get_str('sms', 'server')
100+ except config.NoOptionError:
101+ pass
102+
103+ self.client = BulkSMS.Server(username, password, **kwargs)
104+
105+ def send(self, recipient, info):
106+ sender = config.get_str('sms', 'sender')
107+ self.client.send_sms(recipients=[recipient.messaging_address],
108+ sender=sender,
109+ text=str(info))
110+
111+
112+drivers.register_driver('sms', 'bulksms', BulkSMSMessaging())
113
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+"""
119+ Surveilr - Log aggregation, analysis and visualisation
120+
121+ Copyright (C) 2011 Linux2Go
122+
123+ This program is free software: you can redistribute it and/or
124+ modify it under the terms of the GNU Affero General Public License
125+ as published by the Free Software Foundation, either version 3 of
126+ the License, or (at your option) any later version.
127+
128+ This program is distributed in the hope that it will be useful,
129+ but WITHOUT ANY WARRANTY; without even the implied warranty of
130+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131+ GNU Affero General Public License for more details.
132+
133+ You should have received a copy of the GNU Affero General Public
134+ License along with this program. If not, see
135+ <http://www.gnu.org/licenses/>.
136+
137+ Clickatell SMS driver
138+"""
139+from surveilr import config
140+from surveilr import drivers
141+
142+from clickatell.api import Clickatell
143+from clickatell import constants as cc
144+
145+
146+class ClickatellMessaging(object):
147+ def __init__(self):
148+ username = config.get_str('sms', 'username')
149+ password = config.get_str('sms', 'password')
150+ api_id = config.get_str('sms', 'api_id')
151+ self.client = Clickatell(username, password, api_id,
152+ sendmsg_defaults={
153+ 'callback': cc.YES,
154+ 'msg_type': cc.SMS_DEFAULT,
155+ 'deliv_ack': cc.YES,
156+ 'req_feat': (cc.FEAT_ALPHA +
157+ cc.FEAT_NUMER +
158+ cc.FEAT_DELIVACK)
159+ })
160+
161+ def send(self, recipient, info):
162+ sender = config.get_str('sms', 'sender')
163+ self.client.sendmsg(recipients=[recipient.messaging_address],
164+ sender=sender,
165+ text=str(info))
166+
167+
168+drivers.register_driver('sms', 'clickatell', ClickatellMessaging())
169
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+"""
175+ Surveilr - Log aggregation, analysis and visualisation
176+
177+ Copyright (C) 2011 Linux2Go
178+
179+ This program is free software: you can redistribute it and/or
180+ modify it under the terms of the GNU Affero General Public License
181+ as published by the Free Software Foundation, either version 3 of
182+ the License, or (at your option) any later version.
183+
184+ This program is distributed in the hope that it will be useful,
185+ but WITHOUT ANY WARRANTY; without even the implied warranty of
186+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187+ GNU Affero General Public License for more details.
188+
189+ You should have received a copy of the GNU Affero General Public
190+ License along with this program. If not, see
191+ <http://www.gnu.org/licenses/>.
192+
193+ Fake SMS driver
194+"""
195+
196+from surveilr import drivers
197+
198+
199+class FakeMessaging(object):
200+ msgs = []
201+
202+ def send(self, recipient, info):
203+ self.msgs.append((recipient, info))
204+
205+drivers.register_driver('sms', 'fake', FakeMessaging())
206
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
212 import mock
213 import os.path
214+import riakalchemy
215 import unittest
216
217 from surveilr import config
218@@ -39,8 +40,13 @@
219 return os.path.join(os.path.dirname(__file__),
220 os.path.pardir, 'defaults.cfg')
221
222+ def set_cfg_value(self, section, option, value):
223+ config.cfg.set(section, option, value)
224+
225 def setUp(self):
226 super(TestCase, self).setUp()
227+ riakalchemy.connect()
228+
229 with mock.patch('surveilr.config.defaults_file') as defaults_file:
230 with mock.patch('surveilr.config.config_files') as config_files:
231 config_files.return_value = self.config_files()
232
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
238 class APIServerTests(tests.TestCase):
239 def setUp(self):
240- import riakalchemy
241- riakalchemy.connect()
242+ super(APIServerTests, self).setUp()
243 self.application = SurveilrApplication({})
244
245 def test_create_retrieve_user(self):
246
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+"""
253+ Surveilr - Log aggregation, analysis and visualisation
254+
255+ Copyright (C) 2011 Linux2Go
256+
257+ This program is free software: you can redistribute it and/or
258+ modify it under the terms of the GNU Affero General Public License
259+ as published by the Free Software Foundation, either version 3 of
260+ the License, or (at your option) any later version.
261+
262+ This program is distributed in the hope that it will be useful,
263+ but WITHOUT ANY WARRANTY; without even the implied warranty of
264+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
265+ GNU Affero General Public License for more details.
266+
267+ You should have received a copy of the GNU Affero General Public
268+ License along with this program. If not, see
269+ <http://www.gnu.org/licenses/>.
270+"""
271
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+"""
278+ Surveilr - Log aggregation, analysis and visualisation
279+
280+ Copyright (C) 2011 Linux2Go
281+
282+ This program is free software: you can redistribute it and/or
283+ modify it under the terms of the GNU Affero General Public License
284+ as published by the Free Software Foundation, either version 3 of
285+ the License, or (at your option) any later version.
286+
287+ This program is distributed in the hope that it will be useful,
288+ but WITHOUT ANY WARRANTY; without even the implied warranty of
289+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
290+ GNU Affero General Public License for more details.
291+
292+ You should have received a copy of the GNU Affero General Public
293+ License along with this program. If not, see
294+ <http://www.gnu.org/licenses/>.
295+"""
296
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+[sms]
302+driver = not_your_average_sms_driver
303
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+"""
309+ Surveilr - Log aggregation, analysis and visualisation
310+
311+ Copyright (C) 2011 Linux2Go
312+
313+ This program is free software: you can redistribute it and/or
314+ modify it under the terms of the GNU Affero General Public License
315+ as published by the Free Software Foundation, either version 3 of
316+ the License, or (at your option) any later version.
317+
318+ This program is distributed in the hope that it will be useful,
319+ but WITHOUT ANY WARRANTY; without even the implied warranty of
320+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
321+ GNU Affero General Public License for more details.
322+
323+ You should have received a copy of the GNU Affero General Public
324+ License along with this program. If not, see
325+ <http://www.gnu.org/licenses/>.
326+"""
327+
328+import mock
329+
330+from surveilr import tests
331+from surveilr.messaging import sms
332+
333+
334+class SMSMessagingTest(tests.TestCase):
335+ @mock.patch('surveilr.messaging.sms.drivers')
336+ def test_init(self, drivers):
337+ sms.SMSMessaging()
338+ drivers.get_driver.assert_called_with('sms',
339+ 'not_your_average_sms_driver')
340+
341+ @mock.patch('surveilr.messaging.sms.drivers')
342+ def test_send(self, drivers):
343+ drv = sms.SMSMessaging()
344+ recipient = mock.sentinel.recipient
345+ info = mock.sentinel.info
346+
347+ drv.send(recipient, info)
348+
349+ drivers.get_driver.return_value.send.assert_called_with(recipient,
350+ info)
351
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+[sms]
357+driver = bulksms
358+username = testuser
359+password = testpassword
360+api_id = testapiid
361+sender = testsender
362
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+"""
368+ Surveilr - Log aggregation, analysis and visualisation
369+
370+ Copyright (C) 2011 Linux2Go
371+
372+ This program is free software: you can redistribute it and/or
373+ modify it under the terms of the GNU Affero General Public License
374+ as published by the Free Software Foundation, either version 3 of
375+ the License, or (at your option) any later version.
376+
377+ This program is distributed in the hope that it will be useful,
378+ but WITHOUT ANY WARRANTY; without even the implied warranty of
379+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
380+ GNU Affero General Public License for more details.
381+
382+ You should have received a copy of the GNU Affero General Public
383+ License along with this program. If not, see
384+ <http://www.gnu.org/licenses/>.
385+
386+ Tests for BulkSMS driver
387+"""
388+
389+import mock
390+
391+from surveilr import tests
392+from surveilr.messaging.sms import bulksms_driver
393+from surveilr.tests import utils
394+
395+
396+class BulkSMSDriverTests(tests.TestCase):
397+ @mock.patch('surveilr.messaging.sms.bulksms_driver.BulkSMS')
398+ def test_instantiate_client(self, BulkSMS):
399+ self.driver = bulksms_driver.BulkSMSMessaging()
400+ BulkSMS.Server.assert_called_with('testuser', 'testpassword')
401+
402+ @mock.patch('surveilr.messaging.sms.bulksms_driver.BulkSMS')
403+ def test_instantiate_client_override_server(self, BulkSMS):
404+ self.set_cfg_value('sms', 'server', 'testserver')
405+ self.driver = bulksms_driver.BulkSMSMessaging()
406+ BulkSMS.Server.assert_called_with('testuser', 'testpassword',
407+ server='testserver')
408+
409+ def test_send(self):
410+ driver = bulksms_driver.BulkSMSMessaging()
411+ driver.client = mock.Mock()
412+
413+ msisdn = '12345678'
414+ user = utils.get_test_user(messaging_driver='sms',
415+ messaging_address=msisdn)
416+ info = utils.get_test_notification_info()
417+
418+ driver.send(user, info)
419+
420+ driver.client.send_sms.assert_called_with(recipients=[msisdn],
421+ sender='testsender',
422+ text=str(info))
423
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 [sms]
429+driver = clickatell
430 username = testuser
431 password = testpassword
432 api_id = testapiid
433
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 License along with this program. If not, see
439 <http://www.gnu.org/licenses/>.
440
441- Tests for messaging layer
442+ Tests for Clickatell driver
443 """
444
445 import mock
446
447-from surveilr import drivers
448-from surveilr import messaging
449 from surveilr import tests
450-from surveilr.messaging import sms
451+from surveilr.messaging.sms import clickatell_driver
452 from surveilr.tests import utils
453
454
455-class FakeMessagingDriverTests(tests.TestCase):
456- def setUp(self):
457- import surveilr.messaging.fake
458- # This does nothing, but pyflakes gets upset if we import it
459- # and never "use" it.
460- surveilr.messaging.fake
461- self.driver = drivers.get_driver('messaging', 'fake')
462-
463- def test_send(self):
464- user = utils.get_test_user()
465- info = {'service': 'service_id',
466- 'state': 'normal',
467- 'previous_state': 'unexpected high'}
468- self.driver.send(user, info)
469-
470-
471-class SMSMessagingDriverTests(tests.TestCase):
472- @mock.patch('surveilr.messaging.sms.Clickatell')
473+class ClickatellDriverTests(tests.TestCase):
474+ @mock.patch('surveilr.messaging.sms.clickatell_driver.Clickatell')
475 def test_instantiate_client(self, clickatell):
476- self.driver = sms.SMSMessaging()
477+ self.driver = clickatell_driver.ClickatellMessaging()
478
479 sendmsg_defaults = {'callback': 1,
480 'req_feat': 8240,
481@@ -58,7 +40,7 @@
482 sendmsg_defaults=sendmsg_defaults)
483
484 def test_send(self):
485- driver = sms.SMSMessaging()
486+ driver = clickatell_driver.ClickatellMessaging()
487 driver.client = mock.Mock()
488
489 msisdn = '12345678'
490@@ -71,43 +53,3 @@
491 driver.client.sendmsg.assert_called_with(recipients=[msisdn],
492 sender='testsender',
493 text=str(info))
494-
495-
496-class MessagingAPITests(tests.TestCase):
497- def test_send(self):
498- user = utils.get_test_user()
499- info = {'service': 'service_id',
500- 'state': 'normal',
501- 'previous_state': 'unexpected high'}
502-
503- with mock.patch('surveilr.messaging._get_driver') as _get_driver:
504- messaging.send(user, info)
505-
506- # Check that _get_driver gets called with the user as its argument
507- _get_driver.assert_called_with(user)
508-
509- # Check that _get_driver's return value (i.e. the driver)
510- # gets its .send() method called with user and info as its
511- # arguments
512- _get_driver.return_value.send.assert_called_with(user, info)
513-
514- def test_get_driver_default(self):
515- user = utils.get_test_user()
516- expected_driver = drivers.get_driver('messaging', 'fake')
517-
518- actual_driver = messaging._get_driver(user)
519- self.assertEquals(actual_driver, expected_driver)
520-
521- def test_get_driver_sms(self):
522- user = utils.get_test_user(messaging_driver='sms')
523- expected_driver = drivers.get_driver('messaging', 'sms')
524-
525- actual_driver = messaging._get_driver(user)
526- self.assertEquals(actual_driver, expected_driver)
527-
528- def test_get_driver_fake(self):
529- user = utils.get_test_user(messaging_driver='fake')
530- expected_driver = drivers.get_driver('messaging', 'fake')
531-
532- actual_driver = messaging._get_driver(user)
533- self.assertEquals(actual_driver, expected_driver)
534
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+"""
540+ Surveilr - Log aggregation, analysis and visualisation
541+
542+ Copyright (C) 2011 Linux2Go
543+
544+ This program is free software: you can redistribute it and/or
545+ modify it under the terms of the GNU Affero General Public License
546+ as published by the Free Software Foundation, either version 3 of
547+ the License, or (at your option) any later version.
548+
549+ This program is distributed in the hope that it will be useful,
550+ but WITHOUT ANY WARRANTY; without even the implied warranty of
551+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
552+ GNU Affero General Public License for more details.
553+
554+ You should have received a copy of the GNU Affero General Public
555+ License along with this program. If not, see
556+ <http://www.gnu.org/licenses/>.
557+"""
558+
559+import mock
560+
561+from surveilr import tests
562+from surveilr.messaging.sms import fake
563+
564+
565+class FakeSMSMessagingTest(tests.TestCase):
566+ def test_send(self):
567+ recipient1 = mock.sentinel.recipient1
568+ info1 = mock.sentinel.info1
569+ recipient2 = mock.sentinel.recipient2
570+ info2 = mock.sentinel.info2
571+
572+ drv = fake.FakeMessaging()
573+ drv.send(recipient1, info1)
574+ drv.send(recipient2, info2)
575+
576+ self.assertEquals(drv.msgs, [(recipient1, info1),
577+ (recipient2, info2)])
578
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+"""
584+ Surveilr - Log aggregation, analysis and visualisation
585+
586+ Copyright (C) 2011 Linux2Go
587+
588+ This program is free software: you can redistribute it and/or
589+ modify it under the terms of the GNU Affero General Public License
590+ as published by the Free Software Foundation, either version 3 of
591+ the License, or (at your option) any later version.
592+
593+ This program is distributed in the hope that it will be useful,
594+ but WITHOUT ANY WARRANTY; without even the implied warranty of
595+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
596+ GNU Affero General Public License for more details.
597+
598+ You should have received a copy of the GNU Affero General Public
599+ License along with this program. If not, see
600+ <http://www.gnu.org/licenses/>.
601+
602+ Tests for messaging layer
603+"""
604+
605+import mock
606+
607+from surveilr import drivers
608+from surveilr import messaging
609+from surveilr import tests
610+from surveilr.tests import utils
611+
612+
613+class MessagingAPITests(tests.TestCase):
614+ def test_send(self):
615+ user = utils.get_test_user()
616+ info = {'service': 'service_id',
617+ 'state': 'normal',
618+ 'previous_state': 'unexpected high'}
619+
620+ with mock.patch('surveilr.messaging._get_driver') as _get_driver:
621+ messaging.send(user, info)
622+
623+ # Check that _get_driver gets called with the user as its argument
624+ _get_driver.assert_called_with(user)
625+
626+ # Check that _get_driver's return value (i.e. the driver)
627+ # gets its .send() method called with user and info as its
628+ # arguments
629+ _get_driver.return_value.send.assert_called_with(user, info)
630+
631+ def test_get_driver_default(self):
632+ user = utils.get_test_user()
633+ expected_driver = drivers.get_driver('messaging', 'fake')
634+
635+ actual_driver = messaging._get_driver(user)
636+ self.assertEquals(actual_driver, expected_driver)
637+
638+ def test_get_driver_sms(self):
639+ user = utils.get_test_user(messaging_driver='sms')
640+ expected_driver = drivers.get_driver('messaging', 'sms')
641+
642+ actual_driver = messaging._get_driver(user)
643+ self.assertEquals(actual_driver, expected_driver)
644+
645+ def test_get_driver_fake(self):
646+ user = utils.get_test_user(messaging_driver='fake')
647+ expected_driver = drivers.get_driver('messaging', 'fake')
648+
649+ actual_driver = messaging._get_driver(user)
650+ self.assertEquals(actual_driver, expected_driver)
651
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+"""
657+ Surveilr - Log aggregation, analysis and visualisation
658+
659+ Copyright (C) 2011 Linux2Go
660+
661+ This program is free software: you can redistribute it and/or
662+ modify it under the terms of the GNU Affero General Public License
663+ as published by the Free Software Foundation, either version 3 of
664+ the License, or (at your option) any later version.
665+
666+ This program is distributed in the hope that it will be useful,
667+ but WITHOUT ANY WARRANTY; without even the implied warranty of
668+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
669+ GNU Affero General Public License for more details.
670+
671+ You should have received a copy of the GNU Affero General Public
672+ License along with this program. If not, see
673+ <http://www.gnu.org/licenses/>.
674+
675+ Tests for fake messaging driver
676+"""
677+
678+from surveilr import drivers
679+from surveilr import tests
680+from surveilr.tests import utils
681+
682+
683+class FakeMessagingDriverTests(tests.TestCase):
684+ def setUp(self):
685+ import surveilr.messaging.fake
686+ # This does nothing, but pyflakes gets upset if we import it
687+ # and never "use" it.
688+ surveilr.messaging.fake
689+ self.driver = drivers.get_driver('messaging', 'fake')
690+
691+ def test_send(self):
692+ user = utils.get_test_user()
693+ info = {'service': 'service_id',
694+ 'state': 'normal',
695+ 'previous_state': 'unexpected high'}
696+ self.driver.send(user, info)
697
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
703 import os.path
704
705+
706 class ConfigTest(tests.TestCase):
707 def defaults_file(self):
708 return os.path.join(os.path.dirname(__file__),
709
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 pastedeploy
715 paste
716 PasteScript
717+-e hg+https://code.google.com/p/soren-bulksms/#egg=BulkSMS

Subscribers

People subscribed via source and target branches

to all changes: