コード例 #1
0
ファイル: tests.py プロジェクト: RobIncAMDSPhD/rapidsms
 def test_auth(self):
     """Vumi backend shold use basic authentication if given user/pass."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com", "sendsms_user": "******", "sendsms_pass": "******"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text, [message.connections[0].identity], {})
     self.assertTrue("auth" in kwargs)
コード例 #2
0
ファイル: tests.py プロジェクト: RobIncAMDSPhD/rapidsms
 def test_message_id_in_metadata(self):
     """Make sure our uuid is sent to Vumi."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text, [message.connections[0].identity], {})
     data = json.loads(kwargs["data"])
     self.assertIn(message.id, data.get("metadata", {}).values())
コード例 #3
0
ファイル: tests.py プロジェクト: RobIncAMDSPhD/rapidsms
 def test_bulk_response_external_id(self):
     """Only single messages should include in_response_to."""
     conn1 = self.create_connection()
     conn2 = self.create_connection()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request("1234", "foo", [conn1.identity, conn2.identity], {"external_id": "ASDF1234"})
     data = json.loads(kwargs["data"])
     self.assertTrue("in_reply_to" not in data)
コード例 #4
0
 def test_message_id_in_metadata(self):
     """Make sure our uuid is sent to Vumi."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], {})
     data = json.loads(kwargs['data'])
     self.assertIn(message.id, data.get('metadata', {}).values())
コード例 #5
0
ファイル: tests.py プロジェクト: RobIncAMDSPhD/rapidsms
 def test_response_external_id(self):
     """Make sure external_id context is sent to Vumi."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(
         message.id, message.text, [message.connections[0].identity], {"external_id": "ASDF1234"}
     )
     data = json.loads(kwargs["data"])
     self.assertEqual("ASDF1234", data["in_reply_to"])
コード例 #6
0
ファイル: tests.py プロジェクト: RobIncAMDSPhD/rapidsms
 def test_outgoing_keys(self):
     """Vumi requires JSON to include to_addr and content."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text, [message.connections[0].identity], {})
     self.assertEqual(kwargs["url"], config["sendsms_url"])
     data = json.loads(kwargs["data"])
     self.assertEqual(data["to_addr"], [message.connections[0].identity])
     self.assertEqual(data["content"], message.text)
コード例 #7
0
ファイル: tests.py プロジェクト: thedrow/rapidsms
 def test_auth(self):
     """Vumi backend shold use basic authentication if given user/pass."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com",
               "sendsms_user": "******",
               "sendsms_pass": "******"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], {})
     self.assertTrue('auth' in kwargs)
コード例 #8
0
 def test_response_external_id(self):
     """Make sure external_id context is sent to Vumi."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity],
                                      {'external_id': 'ASDF1234'})
     data = json.loads(kwargs['data'])
     self.assertEqual("ASDF1234", data['in_reply_to'])
コード例 #9
0
 def test_bulk_response_external_id(self):
     """Only single messages should include in_response_to."""
     conn1 = self.create_connection()
     conn2 = self.create_connection()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request("1234", "foo",
                                      [conn1.identity, conn2.identity],
                                      {'external_id': 'ASDF1234'})
     data = json.loads(kwargs['data'])
     self.assertTrue('in_reply_to' not in data)
コード例 #10
0
 def test_outgoing_keys(self):
     """Vumi requires JSON to include to_addr and content."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], {})
     self.assertEqual(kwargs['url'], config['sendsms_url'])
     data = json.loads(kwargs['data'])
     self.assertEqual(data['to_addr'], [message.connections[0].identity])
     self.assertEqual(data['content'], message.text)
コード例 #11
0
ファイル: tests.py プロジェクト: Achaz/rapidsms
 def test_send(self):
     """Test successful send."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], {})
     with patch('rapidsms.backends.vumi.outgoing.requests.post') as mock_post:
         backend.send(message.id, message.text,
                      [message.connections[0].identity], {})
     mock_post.assert_called_once_with(**kwargs)
コード例 #12
0
 def test_send(self):
     """Test successful send."""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], {})
     with patch('rapidsms.backends.vumi.outgoing.requests.post') as mock_post:
         backend.send(message.id, message.text,
                      [message.connections[0].identity], {})
     mock_post.assert_called_once_with(**kwargs)
コード例 #13
0
ファイル: tests.py プロジェクト: Achaz/rapidsms
 def test_from_addr_and_endpoint_in_payload(self):
     """Make sure that we include from_addr or endpoint if provided, but only those keys"""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     context = {'from_addr': '5551212',
                'endpoint': '12345',
                'other': 'not included'}
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], context)
     data = json.loads(kwargs['data'])
     self.assertEqual(context['from_addr'], data['from_addr'])
     self.assertEqual(context['endpoint'], data['endpoint'])
     self.assertNotIn('other', data)
コード例 #14
0
 def test_from_addr_and_endpoint_in_payload(self):
     """Make sure that we include from_addr or endpoint if provided, but only those keys"""
     message = self.create_outgoing_message()
     config = {"sendsms_url": "http://example.com"}
     backend = VumiBackend(None, "vumi", **config)
     context = {'from_addr': '5551212',
                'endpoint': '12345',
                'other': 'not included'}
     kwargs = backend.prepare_request(message.id, message.text,
                                      [message.connections[0].identity], context)
     data = json.loads(kwargs['data'])
     self.assertEqual(context['from_addr'], data['from_addr'])
     self.assertEqual(context['endpoint'], data['endpoint'])
     self.assertNotIn('other', data)