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)
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())
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)
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())
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"])
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)
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)
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'])
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)
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)
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)
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)