Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    def test_no_matching_fee(self):
        self.create_least_specific_gateway_fees()
        self.create_country_code_gateway_fees()
        self.create_instance_gateway_fees()
        self.create_most_specific_gateway_fees()

        phone_numbers = [generator.arbitrary_phone_number() for i in range(10)]
        for phone_number in phone_numbers:
            messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids,
                                                                             phone_number=phone_number,
                                                                             directions=['X', 'Y'])
            for msg_log in messages:
                billable = SmsBillable.create(msg_log)
                self.assertIsNotNone(billable)
                self.assertIsNone(billable.gateway_fee)
Esempio n. 5
0
    def test_no_matching_fee(self):
        self.create_least_specific_gateway_fees()
        self.create_country_code_gateway_fees()
        self.create_instance_gateway_fees()
        self.create_most_specific_gateway_fees()

        phone_numbers = [generator.arbitrary_phone_number() for i in range(10)]
        for phone_number in phone_numbers:
            messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids,
                                                                             phone_number=phone_number,
                                                                             directions=['X', 'Y'])
            for msg_log in messages:
                billable = SmsBillable.create(msg_log)
                self.assertIsNotNone(billable)
                self.assertIsNone(billable.gateway_fee)
Esempio n. 6
0
    def test_instance_fees(self):
        self.create_least_specific_gateway_fees()
        self.create_country_code_gateway_fees()
        self.create_instance_gateway_fees()

        phone_numbers = [generator.arbitrary_phone_number() for i in range(10)]
        for phone_number in phone_numbers:
            messages = generator.arbitrary_messages_by_backend_and_direction(
                self.backend_ids, phone_number=phone_number)
            for msg_log in messages:
                billable = SmsBillable.create(msg_log)
                self.assertIsNotNone(billable)
                self.assertEqual(
                    billable.gateway_charge,
                    self.instance_fees[billable.direction][
                        billable.gateway_fee.criteria.backend_api_id][1])
Esempio n. 7
0
    def test_country_code_fees(self):
        self.create_least_specific_gateway_fees()
        self.create_country_code_gateway_fees()

        phone_numbers = [generator.arbitrary_phone_number() for i in range(10)]
        for phone_number in phone_numbers:
            messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids,
                                                                             phone_number=phone_number)
            for msg_log in messages:
                billable = SmsBillable.create(msg_log)
                self.assertIsNotNone(billable)
                self.assertEqual(
                    billable.gateway_charge,
                    self.country_code_fees[billable.direction]
                    [billable.gateway_fee.criteria.backend_api_id]
                    [int(phone_number[:-10])]
                )