Пример #1
0
 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
 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
 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
 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
 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
 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
 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
 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)