def test_twilio_domain_level_backend(self, mock_log_smsbillables_error): add_twilio_gateway_fee(apps) bootstrap_usage_fees(apps) twilio_backend = SQLTwilioBackend.objects.create( name='TWILIO', is_global=False, hq_api_id=SQLTwilioBackend.get_api_id(), couch_id='domain_backend', ) twilio_backend.set_extra_fields( account_sid='sid', auth_token='token', ) twilio_backend.save() messages = [ message for phone_number in [generator.arbitrary_phone_number() for _ in range(10)] for message in generator.arbitrary_messages_by_backend_and_direction( {twilio_backend.hq_api_id: twilio_backend.couch_id}, phone_number=phone_number) ] for msg_log in messages: FakeTwilioMessageFactory.add_price_for_message( msg_log.backend_message_id, generator.arbitrary_fee()) for msg_log in messages: multipart_count = randint(1, 10) # Should be ignored billable = SmsBillable.create(msg_log, multipart_count=multipart_count) self.assertIsNotNone(billable) self.assertIsNone(billable.gateway_fee) self.assertEqual(billable.gateway_charge, 0) self.assertEqual(mock_log_smsbillables_error.call_count, 0)
def test_twilio_multipart_usage_charge(self): self.apply_direction_fee() twilio_backend = SQLTwilioBackend.objects.create( name='TWILIO', is_global=True, hq_api_id=SQLTwilioBackend.get_api_id(), couch_id='global_backend', ) twilio_backend.set_extra_fields( account_sid='sid', auth_token='token', ) twilio_backend.save() messages = generator.arbitrary_messages_by_backend_and_direction( {twilio_backend.hq_api_id: twilio_backend.couch_id}) for message in messages: FakeTwilioMessageFactory.add_num_segments_for_message( message.backend_message_id, randint(1, 10)) FakeTwilioMessageFactory.add_price_for_message( message.backend_message_id, generator.arbitrary_fee()) for message in messages: multipart_count = randint(1, 10) # Should be ignored billable = SmsBillable.create(message, multipart_count=multipart_count) self.assertIsNotNone(billable) self.assertEqual( billable.usage_charge, (self.least_specific_fees[message.direction] * FakeTwilioMessageFactory.get_num_segments_for_message( message.backend_message_id)))
def test_non_global_backends_with_direct_provider_fees( self, mock_log_smsbillables_error): bootstrap_twilio_gateway(apps) bootstrap_infobip_gateway(apps) bootstrap_usage_fees(apps) backends = generator.arbitrary_non_global_with_direct_fees_backends() for backend in backends: messages = [ message for phone_number in [generator.arbitrary_phone_number() for _ in range(10)] for message in generator.arbitrary_messages_by_backend_and_direction( {backend.hq_api_id: backend.couch_id}, phone_number=phone_number) ] for msg_log in messages: FakeMessageFactory.add_price_for_message( msg_log.backend_message_id, generator.arbitrary_fee()) for msg_log in messages: multipart_count = randint(1, 10) # Should be ignored billable = SmsBillable.create(msg_log, multipart_count=multipart_count) self.assertIsNotNone(billable) self.assertIsNone(billable.gateway_fee) self.assertEqual(billable.gateway_charge, 0) self.assertEqual(mock_log_smsbillables_error.call_count, 0)
def test_multipart_usage_charge_for_backends_with_direct_fees(self): self.apply_direction_fee() backends = generator.arbitrary_with_direct_fees_backends() for backend in backends: messages = generator.arbitrary_messages_by_backend_and_direction( {backend.hq_api_id: backend.couch_id}) for message in messages: FakeMessageFactory.add_num_segments_for_message( message.backend_message_id, randint(1, 10)) FakeMessageFactory.add_price_for_message( message.backend_message_id, generator.arbitrary_fee()) for message in messages: multipart_count = randint(1, 10) # Should be ignored billable = SmsBillable.create(message, multipart_count=multipart_count) self.assertIsNotNone(billable) self.assertEqual( billable.usage_charge, (self.least_specific_fees[message.direction] * FakeMessageFactory.get_num_segments_for_message( message.backend_message_id)))
def test_twilio_domain_level_backend(self, mock_log_smsbillables_error): add_twilio_gateway_fee(apps) bootstrap_usage_fees(apps) twilio_backend = SQLTwilioBackend.objects.create( name='TWILIO', is_global=False, hq_api_id=SQLTwilioBackend.get_api_id(), couch_id='domain_backend', ) twilio_backend.set_extra_fields( account_sid='sid', auth_token='token', ) twilio_backend.save() messages = [ message for phone_number in [generator.arbitrary_phone_number() for _ in range(10)] for message in generator.arbitrary_messages_by_backend_and_direction( {twilio_backend.hq_api_id: twilio_backend.couch_id}, phone_number=phone_number ) ] for msg_log in messages: FakeTwilioMessageFactory.add_price_for_message(msg_log.backend_message_id, generator.arbitrary_fee()) for msg_log in messages: multipart_count = randint(1, 10) # Should be ignored billable = SmsBillable.create(msg_log, multipart_count=multipart_count) self.assertIsNotNone(billable) self.assertIsNone(billable.gateway_fee) self.assertEqual(billable.gateway_charge, 0) self.assertEqual(mock_log_smsbillables_error.call_count, 0)
def test_twilio_multipart_usage_charge(self): self.apply_direction_fee() twilio_backend = SQLTwilioBackend.objects.create( name='TWILIO', is_global=True, hq_api_id=SQLTwilioBackend.get_api_id(), couch_id='global_backend', ) twilio_backend.set_extra_fields( account_sid='sid', auth_token='token', ) twilio_backend.save() messages = generator.arbitrary_messages_by_backend_and_direction( {twilio_backend.hq_api_id: twilio_backend.couch_id} ) for message in messages: FakeTwilioMessageFactory.add_num_segments_for_message(message.backend_message_id, randint(1, 10)) FakeTwilioMessageFactory.add_price_for_message(message.backend_message_id, generator.arbitrary_fee()) for message in messages: multipart_count = randint(1, 10) # Should be ignored billable = SmsBillable.create(message, multipart_count=multipart_count) self.assertIsNotNone(billable) self.assertEqual( billable.usage_charge, ( self.least_specific_fees[message.direction] * FakeTwilioMessageFactory.get_num_segments_for_message( message.backend_message_id ) ) )