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
=== modified file 'surveilr/defaults.cfg'
--- surveilr/defaults.cfg 2011-12-18 14:25:14 +0000
+++ surveilr/defaults.cfg 2011-12-20 11:09:28 +0000
@@ -1,6 +1,7 @@
1# This is where we stick defaults for various things1# This is where we stick defaults for various things
22
3[sms]3[sms]
4driver = fake
4username =5username =
5password =6password =
6api_id =7api_id =
78
=== added directory 'surveilr/messaging/sms'
=== renamed file 'surveilr/messaging/sms.py' => 'surveilr/messaging/sms/__init__.py'
--- surveilr/messaging/sms.py 2011-11-29 23:41:46 +0000
+++ surveilr/messaging/sms/__init__.py 2011-12-20 11:09:28 +0000
@@ -16,37 +16,22 @@
16 You should have received a copy of the GNU Affero General Public16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.18 <http://www.gnu.org/licenses/>.
19
20 SMS messaging driver
21"""19"""
2220
23from surveilr import config21from surveilr import config
24from surveilr import drivers22from surveilr import drivers
2523
26from clickatell.api import Clickatell24import surveilr.messaging.sms.fake
27from clickatell import constants as cc25import surveilr.messaging.sms.clickatell_driver
26import surveilr.messaging.sms.bulksms_driver
2827
2928
30class SMSMessaging(object):29class SMSMessaging(object):
31 def __init__(self):30 def __init__(self):
32 username = config.get_str('sms', 'username')31 driver_name = config.get_str('sms', 'driver')
33 password = config.get_str('sms', 'password')32 self.driver = drivers.get_driver('sms', driver_name)
34 api_id = config.get_str('sms', 'api_id')
35 self.client = Clickatell(username, password, api_id,
36 sendmsg_defaults={
37 'callback': cc.YES,
38 'msg_type': cc.SMS_DEFAULT,
39 'deliv_ack': cc.YES,
40 'req_feat': (cc.FEAT_ALPHA +
41 cc.FEAT_NUMER +
42 cc.FEAT_DELIVACK)
43 })
4433
45 def send(self, recipient, info):34 def send(self, recipient, info):
46 sender = config.get_str('sms', 'sender')35 return self.driver.send(recipient, info)
47 self.client.sendmsg(recipients=[recipient.messaging_address],
48 sender=sender,
49 text=str(info))
50
5136
52drivers.register_driver('messaging', 'sms', SMSMessaging())37drivers.register_driver('messaging', 'sms', SMSMessaging())
5338
=== added file 'surveilr/messaging/sms/bulksms_driver.py'
--- surveilr/messaging/sms/bulksms_driver.py 1970-01-01 00:00:00 +0000
+++ surveilr/messaging/sms/bulksms_driver.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,47 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 BulkSMS driver
21"""
22from surveilr import config
23from surveilr import drivers
24
25import BulkSMS
26
27
28class BulkSMSMessaging(object):
29 def __init__(self):
30 username = config.get_str('sms', 'username')
31 password = config.get_str('sms', 'password')
32 kwargs = {}
33 try:
34 kwargs['server'] = config.get_str('sms', 'server')
35 except config.NoOptionError:
36 pass
37
38 self.client = BulkSMS.Server(username, password, **kwargs)
39
40 def send(self, recipient, info):
41 sender = config.get_str('sms', 'sender')
42 self.client.send_sms(recipients=[recipient.messaging_address],
43 sender=sender,
44 text=str(info))
45
46
47drivers.register_driver('sms', 'bulksms', BulkSMSMessaging())
048
=== added file 'surveilr/messaging/sms/clickatell_driver.py'
--- surveilr/messaging/sms/clickatell_driver.py 1970-01-01 00:00:00 +0000
+++ surveilr/messaging/sms/clickatell_driver.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,51 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 Clickatell SMS driver
21"""
22from surveilr import config
23from surveilr import drivers
24
25from clickatell.api import Clickatell
26from clickatell import constants as cc
27
28
29class ClickatellMessaging(object):
30 def __init__(self):
31 username = config.get_str('sms', 'username')
32 password = config.get_str('sms', 'password')
33 api_id = config.get_str('sms', 'api_id')
34 self.client = Clickatell(username, password, api_id,
35 sendmsg_defaults={
36 'callback': cc.YES,
37 'msg_type': cc.SMS_DEFAULT,
38 'deliv_ack': cc.YES,
39 'req_feat': (cc.FEAT_ALPHA +
40 cc.FEAT_NUMER +
41 cc.FEAT_DELIVACK)
42 })
43
44 def send(self, recipient, info):
45 sender = config.get_str('sms', 'sender')
46 self.client.sendmsg(recipients=[recipient.messaging_address],
47 sender=sender,
48 text=str(info))
49
50
51drivers.register_driver('sms', 'clickatell', ClickatellMessaging())
052
=== added file 'surveilr/messaging/sms/fake.py'
--- surveilr/messaging/sms/fake.py 1970-01-01 00:00:00 +0000
+++ surveilr/messaging/sms/fake.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,32 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 Fake SMS driver
21"""
22
23from surveilr import drivers
24
25
26class FakeMessaging(object):
27 msgs = []
28
29 def send(self, recipient, info):
30 self.msgs.append((recipient, info))
31
32drivers.register_driver('sms', 'fake', FakeMessaging())
033
=== modified file 'surveilr/tests/__init__.py'
--- surveilr/tests/__init__.py 2011-11-30 09:32:31 +0000
+++ surveilr/tests/__init__.py 2011-12-20 11:09:28 +0000
@@ -20,6 +20,7 @@
2020
21import mock21import mock
22import os.path22import os.path
23import riakalchemy
23import unittest24import unittest
2425
25from surveilr import config26from surveilr import config
@@ -39,8 +40,13 @@
39 return os.path.join(os.path.dirname(__file__),40 return os.path.join(os.path.dirname(__file__),
40 os.path.pardir, 'defaults.cfg')41 os.path.pardir, 'defaults.cfg')
4142
43 def set_cfg_value(self, section, option, value):
44 config.cfg.set(section, option, value)
45
42 def setUp(self):46 def setUp(self):
43 super(TestCase, self).setUp()47 super(TestCase, self).setUp()
48 riakalchemy.connect()
49
44 with mock.patch('surveilr.config.defaults_file') as defaults_file:50 with mock.patch('surveilr.config.defaults_file') as defaults_file:
45 with mock.patch('surveilr.config.config_files') as config_files:51 with mock.patch('surveilr.config.config_files') as config_files:
46 config_files.return_value = self.config_files()52 config_files.return_value = self.config_files()
4753
=== modified file 'surveilr/tests/api/test_server.py'
--- surveilr/tests/api/test_server.py 2011-12-20 09:49:02 +0000
+++ surveilr/tests/api/test_server.py 2011-12-20 11:09:28 +0000
@@ -33,8 +33,7 @@
3333
34class APIServerTests(tests.TestCase):34class APIServerTests(tests.TestCase):
35 def setUp(self):35 def setUp(self):
36 import riakalchemy36 super(APIServerTests, self).setUp()
37 riakalchemy.connect()
38 self.application = SurveilrApplication({})37 self.application = SurveilrApplication({})
3938
40 def test_create_retrieve_user(self):39 def test_create_retrieve_user(self):
4140
=== added directory 'surveilr/tests/messaging'
=== added file 'surveilr/tests/messaging/__init__.py'
--- surveilr/tests/messaging/__init__.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/__init__.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,19 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19"""
020
=== added directory 'surveilr/tests/messaging/sms'
=== added file 'surveilr/tests/messaging/sms/__init__.py'
--- surveilr/tests/messaging/sms/__init__.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/sms/__init__.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,19 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19"""
020
=== added file 'surveilr/tests/messaging/sms/test_base.cfg'
--- surveilr/tests/messaging/sms/test_base.cfg 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/sms/test_base.cfg 2011-12-20 11:09:28 +0000
@@ -0,0 +1,2 @@
1[sms]
2driver = not_your_average_sms_driver
03
=== added file 'surveilr/tests/messaging/sms/test_base.py'
--- surveilr/tests/messaging/sms/test_base.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/sms/test_base.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,43 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19"""
20
21import mock
22
23from surveilr import tests
24from surveilr.messaging import sms
25
26
27class SMSMessagingTest(tests.TestCase):
28 @mock.patch('surveilr.messaging.sms.drivers')
29 def test_init(self, drivers):
30 sms.SMSMessaging()
31 drivers.get_driver.assert_called_with('sms',
32 'not_your_average_sms_driver')
33
34 @mock.patch('surveilr.messaging.sms.drivers')
35 def test_send(self, drivers):
36 drv = sms.SMSMessaging()
37 recipient = mock.sentinel.recipient
38 info = mock.sentinel.info
39
40 drv.send(recipient, info)
41
42 drivers.get_driver.return_value.send.assert_called_with(recipient,
43 info)
044
=== added file 'surveilr/tests/messaging/sms/test_bulksms.cfg'
--- surveilr/tests/messaging/sms/test_bulksms.cfg 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/sms/test_bulksms.cfg 2011-12-20 11:09:28 +0000
@@ -0,0 +1,6 @@
1[sms]
2driver = bulksms
3username = testuser
4password = testpassword
5api_id = testapiid
6sender = testsender
07
=== added file 'surveilr/tests/messaging/sms/test_bulksms.py'
--- surveilr/tests/messaging/sms/test_bulksms.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/sms/test_bulksms.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,56 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 Tests for BulkSMS driver
21"""
22
23import mock
24
25from surveilr import tests
26from surveilr.messaging.sms import bulksms_driver
27from surveilr.tests import utils
28
29
30class BulkSMSDriverTests(tests.TestCase):
31 @mock.patch('surveilr.messaging.sms.bulksms_driver.BulkSMS')
32 def test_instantiate_client(self, BulkSMS):
33 self.driver = bulksms_driver.BulkSMSMessaging()
34 BulkSMS.Server.assert_called_with('testuser', 'testpassword')
35
36 @mock.patch('surveilr.messaging.sms.bulksms_driver.BulkSMS')
37 def test_instantiate_client_override_server(self, BulkSMS):
38 self.set_cfg_value('sms', 'server', 'testserver')
39 self.driver = bulksms_driver.BulkSMSMessaging()
40 BulkSMS.Server.assert_called_with('testuser', 'testpassword',
41 server='testserver')
42
43 def test_send(self):
44 driver = bulksms_driver.BulkSMSMessaging()
45 driver.client = mock.Mock()
46
47 msisdn = '12345678'
48 user = utils.get_test_user(messaging_driver='sms',
49 messaging_address=msisdn)
50 info = utils.get_test_notification_info()
51
52 driver.send(user, info)
53
54 driver.client.send_sms.assert_called_with(recipients=[msisdn],
55 sender='testsender',
56 text=str(info))
057
=== renamed file 'surveilr/tests/test_messaging.cfg' => 'surveilr/tests/messaging/sms/test_clickatell.cfg'
--- surveilr/tests/test_messaging.cfg 2011-11-29 23:41:46 +0000
+++ surveilr/tests/messaging/sms/test_clickatell.cfg 2011-12-20 11:09:28 +0000
@@ -1,4 +1,5 @@
1[sms]1[sms]
2driver = clickatell
2username = testuser3username = testuser
3password = testpassword4password = testpassword
4api_id = testapiid5api_id = testapiid
56
=== renamed file 'surveilr/tests/test_messaging.py' => 'surveilr/tests/messaging/sms/test_clickatell.py'
--- surveilr/tests/test_messaging.py 2011-12-20 09:49:02 +0000
+++ surveilr/tests/messaging/sms/test_clickatell.py 2011-12-20 11:09:28 +0000
@@ -17,38 +17,20 @@
17 License along with this program. If not, see17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.18 <http://www.gnu.org/licenses/>.
1919
20 Tests for messaging layer20 Tests for Clickatell driver
21"""21"""
2222
23import mock23import mock
2424
25from surveilr import drivers
26from surveilr import messaging
27from surveilr import tests25from surveilr import tests
28from surveilr.messaging import sms26from surveilr.messaging.sms import clickatell_driver
29from surveilr.tests import utils27from surveilr.tests import utils
3028
3129
32class FakeMessagingDriverTests(tests.TestCase):30class ClickatellDriverTests(tests.TestCase):
33 def setUp(self):31 @mock.patch('surveilr.messaging.sms.clickatell_driver.Clickatell')
34 import surveilr.messaging.fake
35 # This does nothing, but pyflakes gets upset if we import it
36 # and never "use" it.
37 surveilr.messaging.fake
38 self.driver = drivers.get_driver('messaging', 'fake')
39
40 def test_send(self):
41 user = utils.get_test_user()
42 info = {'service': 'service_id',
43 'state': 'normal',
44 'previous_state': 'unexpected high'}
45 self.driver.send(user, info)
46
47
48class SMSMessagingDriverTests(tests.TestCase):
49 @mock.patch('surveilr.messaging.sms.Clickatell')
50 def test_instantiate_client(self, clickatell):32 def test_instantiate_client(self, clickatell):
51 self.driver = sms.SMSMessaging()33 self.driver = clickatell_driver.ClickatellMessaging()
5234
53 sendmsg_defaults = {'callback': 1,35 sendmsg_defaults = {'callback': 1,
54 'req_feat': 8240,36 'req_feat': 8240,
@@ -58,7 +40,7 @@
58 sendmsg_defaults=sendmsg_defaults)40 sendmsg_defaults=sendmsg_defaults)
5941
60 def test_send(self):42 def test_send(self):
61 driver = sms.SMSMessaging()43 driver = clickatell_driver.ClickatellMessaging()
62 driver.client = mock.Mock()44 driver.client = mock.Mock()
6345
64 msisdn = '12345678'46 msisdn = '12345678'
@@ -71,43 +53,3 @@
71 driver.client.sendmsg.assert_called_with(recipients=[msisdn],53 driver.client.sendmsg.assert_called_with(recipients=[msisdn],
72 sender='testsender',54 sender='testsender',
73 text=str(info))55 text=str(info))
74
75
76class MessagingAPITests(tests.TestCase):
77 def test_send(self):
78 user = utils.get_test_user()
79 info = {'service': 'service_id',
80 'state': 'normal',
81 'previous_state': 'unexpected high'}
82
83 with mock.patch('surveilr.messaging._get_driver') as _get_driver:
84 messaging.send(user, info)
85
86 # Check that _get_driver gets called with the user as its argument
87 _get_driver.assert_called_with(user)
88
89 # Check that _get_driver's return value (i.e. the driver)
90 # gets its .send() method called with user and info as its
91 # arguments
92 _get_driver.return_value.send.assert_called_with(user, info)
93
94 def test_get_driver_default(self):
95 user = utils.get_test_user()
96 expected_driver = drivers.get_driver('messaging', 'fake')
97
98 actual_driver = messaging._get_driver(user)
99 self.assertEquals(actual_driver, expected_driver)
100
101 def test_get_driver_sms(self):
102 user = utils.get_test_user(messaging_driver='sms')
103 expected_driver = drivers.get_driver('messaging', 'sms')
104
105 actual_driver = messaging._get_driver(user)
106 self.assertEquals(actual_driver, expected_driver)
107
108 def test_get_driver_fake(self):
109 user = utils.get_test_user(messaging_driver='fake')
110 expected_driver = drivers.get_driver('messaging', 'fake')
111
112 actual_driver = messaging._get_driver(user)
113 self.assertEquals(actual_driver, expected_driver)
11456
=== added file 'surveilr/tests/messaging/sms/test_fake.py'
--- surveilr/tests/messaging/sms/test_fake.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/sms/test_fake.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,39 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19"""
20
21import mock
22
23from surveilr import tests
24from surveilr.messaging.sms import fake
25
26
27class FakeSMSMessagingTest(tests.TestCase):
28 def test_send(self):
29 recipient1 = mock.sentinel.recipient1
30 info1 = mock.sentinel.info1
31 recipient2 = mock.sentinel.recipient2
32 info2 = mock.sentinel.info2
33
34 drv = fake.FakeMessaging()
35 drv.send(recipient1, info1)
36 drv.send(recipient2, info2)
37
38 self.assertEquals(drv.msgs, [(recipient1, info1),
39 (recipient2, info2)])
040
=== added file 'surveilr/tests/messaging/test_base.py'
--- surveilr/tests/messaging/test_base.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/test_base.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,68 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 Tests for messaging layer
21"""
22
23import mock
24
25from surveilr import drivers
26from surveilr import messaging
27from surveilr import tests
28from surveilr.tests import utils
29
30
31class MessagingAPITests(tests.TestCase):
32 def test_send(self):
33 user = utils.get_test_user()
34 info = {'service': 'service_id',
35 'state': 'normal',
36 'previous_state': 'unexpected high'}
37
38 with mock.patch('surveilr.messaging._get_driver') as _get_driver:
39 messaging.send(user, info)
40
41 # Check that _get_driver gets called with the user as its argument
42 _get_driver.assert_called_with(user)
43
44 # Check that _get_driver's return value (i.e. the driver)
45 # gets its .send() method called with user and info as its
46 # arguments
47 _get_driver.return_value.send.assert_called_with(user, info)
48
49 def test_get_driver_default(self):
50 user = utils.get_test_user()
51 expected_driver = drivers.get_driver('messaging', 'fake')
52
53 actual_driver = messaging._get_driver(user)
54 self.assertEquals(actual_driver, expected_driver)
55
56 def test_get_driver_sms(self):
57 user = utils.get_test_user(messaging_driver='sms')
58 expected_driver = drivers.get_driver('messaging', 'sms')
59
60 actual_driver = messaging._get_driver(user)
61 self.assertEquals(actual_driver, expected_driver)
62
63 def test_get_driver_fake(self):
64 user = utils.get_test_user(messaging_driver='fake')
65 expected_driver = drivers.get_driver('messaging', 'fake')
66
67 actual_driver = messaging._get_driver(user)
68 self.assertEquals(actual_driver, expected_driver)
069
=== added file 'surveilr/tests/messaging/test_fake.py'
--- surveilr/tests/messaging/test_fake.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/messaging/test_fake.py 2011-12-20 11:09:28 +0000
@@ -0,0 +1,41 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 Tests for fake messaging driver
21"""
22
23from surveilr import drivers
24from surveilr import tests
25from surveilr.tests import utils
26
27
28class FakeMessagingDriverTests(tests.TestCase):
29 def setUp(self):
30 import surveilr.messaging.fake
31 # This does nothing, but pyflakes gets upset if we import it
32 # and never "use" it.
33 surveilr.messaging.fake
34 self.driver = drivers.get_driver('messaging', 'fake')
35
36 def test_send(self):
37 user = utils.get_test_user()
38 info = {'service': 'service_id',
39 'state': 'normal',
40 'previous_state': 'unexpected high'}
41 self.driver.send(user, info)
042
=== modified file 'surveilr/tests/test_config.py'
--- surveilr/tests/test_config.py 2011-12-19 23:16:11 +0000
+++ surveilr/tests/test_config.py 2011-12-20 11:09:28 +0000
@@ -25,6 +25,7 @@
2525
26import os.path26import os.path
2727
28
28class ConfigTest(tests.TestCase):29class ConfigTest(tests.TestCase):
29 def defaults_file(self):30 def defaults_file(self):
30 return os.path.join(os.path.dirname(__file__),31 return os.path.join(os.path.dirname(__file__),
3132
=== modified file 'tools/pip-requirements.txt'
--- tools/pip-requirements.txt 2011-12-18 14:25:14 +0000
+++ tools/pip-requirements.txt 2011-12-20 11:09:28 +0000
@@ -12,3 +12,4 @@
12pastedeploy12pastedeploy
13paste13paste
14PasteScript14PasteScript
15-e hg+https://code.google.com/p/soren-bulksms/#egg=BulkSMS

Subscribers

People subscribed via source and target branches

to all changes: