Example #1
0
    def test_under_limit(self):
        """
        Make sure that the Line Item for the SMS Rate has the following:
        - base_description is None
        - base_cost is 0.0
        - unit_description is not None
        - unit_cost is 0.0
        - quantity is equal to 1
        - total and subtotals are 0.0
        """
        num_sms = random.randint(0, self.sms_rate.monthly_limit/2)
        arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain, self.sms_date, num_sms, direction=INCOMING
        )
        arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain, self.sms_date, num_sms, direction=OUTGOING
        )
        sms_line_item = self._create_sms_line_item()

        # there is no base cost
        self.assertIsNone(sms_line_item.base_description)
        self.assertEqual(sms_line_item.base_cost, Decimal('0.0000'))

        self.assertEqual(sms_line_item.quantity, 1)
        self.assertEqual(sms_line_item.unit_cost, Decimal('0.0000'))
        self.assertIsNotNone(sms_line_item.unit_description)
        self.assertEqual(sms_line_item.subtotal, Decimal('0.0000'))
        self.assertEqual(sms_line_item.total, Decimal('0.0000'))
    def test_sms_over_limit_in_yearly_invoice(self):
        num_sms = random.randint(self.sms_rate.monthly_limit + 1, self.sms_rate.monthly_limit + 2)
        billables = arbitrary_sms_billables_for_domain(
            self.domain, self.sms_date, num_sms
        )
        num_sms_advanced = random.randint(self.advanced_sms_rate.monthly_limit + 1,
                                          self.advanced_sms_rate.monthly_limit + 2)
        advanced_billables = arbitrary_sms_billables_for_domain(
            self.domain2, self.sms_date, num_sms_advanced
        )

        tasks.generate_invoices(self.invoice_date)
        self.assertEqual(CustomerInvoice.objects.count(), 1)
        invoice = CustomerInvoice.objects.first()

        sms_line_items = invoice.lineitem_set.get_feature_by_type(FeatureType.SMS)
        self.assertEqual(sms_line_items.count(), 2)
        for sms_line_item in sms_line_items:
            self.assertIsNone(sms_line_item.base_description)
            self.assertEqual(sms_line_item.base_cost, Decimal('0.0000'))
            self.assertEqual(sms_line_item.quantity, 1)

            if self.advanced_sms_rate.feature == sms_line_item.feature_rate.feature:
                sms_cost = sum(
                    billable.gateway_charge + billable.usage_charge
                    for billable in advanced_billables[self.advanced_sms_rate.monthly_limit:]
                )
            else:
                sms_cost = sum(
                    billable.gateway_charge + billable.usage_charge
                    for billable in billables[self.sms_rate.monthly_limit:]
                )
            self.assertEqual(sms_line_item.unit_cost, sms_cost)
            self.assertEqual(sms_line_item.total, sms_cost)
    def test_subscription_level_sms_credits(self):
        # Add SMS usage
        arbitrary_sms_billables_for_domain(
            self.domain, self.sms_date, self.sms_rate.monthly_limit + 1
        )
        arbitrary_sms_billables_for_domain(
            self.domain2, self.sms_date, num_sms=self.advanced_rate.monthly_limit + 10
        )

        # Cover the cost of 1 SMS on the Standard subscription
        CreditLine.add_credit(
            amount=Decimal(0.7500),
            feature_type=FeatureType.SMS,
            subscription=self.subscription
        )
        # Cover the cost of 10 SMS on the Advanced subscription
        CreditLine.add_credit(
            amount=Decimal(7.5000),
            feature_type=FeatureType.SMS,
            subscription=self.sub2,
        )

        tasks.generate_invoices(self.invoice_date)
        self.assertEqual(CustomerInvoice.objects.count(), 1)
        invoice = CustomerInvoice.objects.first()
        self.assertEqual(invoice.balance, Decimal('1500.0000'))
    def test_over_limit(self):
        num_sms = random.randint(self.sms_rate.monthly_limit + 1, self.sms_rate.monthly_limit + 2)
        billables = arbitrary_sms_billables_for_domain(
            self.domain, self.sms_date, num_sms
        )
        num_sms_advanced = random.randint(self.advanced_rate.monthly_limit + 1,
                                          self.advanced_rate.monthly_limit + 2)
        advanced_billables = arbitrary_sms_billables_for_domain(
            self.domain2, self.sms_date, num_sms_advanced
        )

        sms_line_items = self._create_sms_line_items()
        self.assertEqual(sms_line_items.count(), 2)
        for sms_line_item in sms_line_items:
            self.assertIsNone(sms_line_item.base_description)
            self.assertEqual(sms_line_item.base_cost, Decimal('0.0000'))
            self.assertEqual(sms_line_item.quantity, 1)

            if self.advanced_rate.feature == sms_line_item.feature_rate.feature:
                sms_cost = sum(
                    billable.gateway_charge + billable.usage_charge
                    for billable in advanced_billables[self.advanced_rate.monthly_limit:]
                )
            else:
                sms_cost = sum(
                    billable.gateway_charge + billable.usage_charge
                    for billable in billables[self.sms_rate.monthly_limit:]
                )
            self.assertEqual(sms_line_item.unit_cost, sms_cost)
            self.assertEqual(sms_line_item.total, sms_cost)
Example #5
0
 def _create_multipart_billables(self, total_parts):
     count_parts = 0
     while True:
         multipart_count = random.randint(1, 5)
         if count_parts + multipart_count <= total_parts:
             arbitrary_sms_billables_for_domain(
                 self.subscription.subscriber.domain, self.sms_date, 1, multipart_count=multipart_count
             )
             count_parts += multipart_count
         else:
             break
     remaining_parts = total_parts - count_parts
     if remaining_parts > 0:
         arbitrary_sms_billables_for_domain(
             self.subscription.subscriber.domain, self.sms_date, 1, multipart_count=remaining_parts
         )
Example #6
0
    def test_over_limit(self):
        """
        Make sure that the Line Item for the SMS Rate has the following:
        - base_description is None
        - base_cost is 0.0
        - unit_description is not None
        - unit_cost is greater than 0.0
        - quantity is equal to 1
        - total and subtotals are greater than zero
        """
        num_sms = random.randint(self.sms_rate.monthly_limit + 1, self.sms_rate.monthly_limit + 2)
        billables = arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain, self.sms_date, num_sms
        )
        sms_line_item = self._create_sms_line_item()

        # there is no base cost
        self.assertIsNone(sms_line_item.base_description)
        self.assertEqual(sms_line_item.base_cost, Decimal('0.0000'))

        sms_cost = sum(
            billable.gateway_charge + billable.usage_charge
            for billable in billables[self.sms_rate.monthly_limit:]
        )

        self.assertEqual(sms_line_item.quantity, 1)
        self.assertEqual(sms_line_item.unit_cost, sms_cost)
        self.assertIsNotNone(sms_line_item.unit_description)

        self.assertEqual(sms_line_item.subtotal, sms_cost)
        self.assertEqual(sms_line_item.total, sms_cost)
    def test_under_limit(self):
        num_sms = self.sms_rate.monthly_limit // 2
        arbitrary_sms_billables_for_domain(
            self.domain, self.sms_date, num_sms, direction=INCOMING
        )
        num_sms_advanced = self.advanced_rate.monthly_limit // 2
        arbitrary_sms_billables_for_domain(
            self.domain2, self.sms_date, num_sms_advanced, direction=INCOMING
        )

        sms_line_items = self._create_sms_line_items()
        self.assertEqual(sms_line_items.count(), 2)
        for sms_line_item in sms_line_items:
            self.assertIsNone(sms_line_item.base_description)
            self.assertEqual(sms_line_item.base_cost, Decimal('0.0000'))
            self.assertEqual(sms_line_item.quantity, 1)
            self.assertEqual(sms_line_item.unit_cost, Decimal('0.0000'))
            self.assertIsNotNone(sms_line_item.unit_description)
            self.assertEqual(sms_line_item.subtotal, Decimal('0.0000'))
            self.assertEqual(sms_line_item.total, Decimal('0.0000'))
Example #8
0
    def test_multipart_over_limit(self):
        def _set_billable_date_sent_day(sms_billable, day):
            sms_billable.date_sent = datetime.date(
                sms_billable.date_sent.year, sms_billable.date_sent.month, day)
            sms_billable.save()

        self._create_multipart_billables(self.sms_rate.monthly_limit - 1)
        for billable in SmsBillable.objects.all():
            _set_billable_date_sent_day(billable, 1)

        half_charged_billable = arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain,
            self.sms_date,
            1,
            multipart_count=2)[0]
        _set_billable_date_sent_day(half_charged_billable, 2)

        fully_charged_billable = arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain,
            self.sms_date,
            1,
            multipart_count=random.randint(2, 5))[0]
        _set_billable_date_sent_day(fully_charged_billable, 3)

        sms_cost = ((half_charged_billable.gateway_charge +
                     half_charged_billable.usage_charge) / 2 +
                    fully_charged_billable.gateway_charge +
                    fully_charged_billable.usage_charge)

        sms_line_item = self._create_sms_line_item()

        self.assertEqual(sms_line_item.quantity, 1)
        self.assertEqual(sms_line_item.unit_cost, sms_cost)
        self.assertIsNotNone(sms_line_item.unit_description)

        self.assertEqual(sms_line_item.subtotal, sms_cost)
        self.assertEqual(sms_line_item.total, sms_cost)
Example #9
0
    def test_multipart_over_limit(self):
        def _set_billable_date_sent_day(sms_billable, day):
            sms_billable.date_sent = datetime.date(
                sms_billable.date_sent.year,
                sms_billable.date_sent.month,
                day
            )
            sms_billable.save()

        self._create_multipart_billables(self.sms_rate.monthly_limit - 1)
        for billable in SmsBillable.objects.all():
            _set_billable_date_sent_day(billable, 1)

        half_charged_billable = arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain, self.sms_date, 1, multipart_count=2
        )[0]
        _set_billable_date_sent_day(half_charged_billable, 2)

        fully_charged_billable = arbitrary_sms_billables_for_domain(
            self.subscription.subscriber.domain, self.sms_date, 1, multipart_count=random.randint(2, 5)
        )[0]
        _set_billable_date_sent_day(fully_charged_billable, 3)

        sms_cost = (
            (half_charged_billable.gateway_charge + half_charged_billable.usage_charge) / 2
            + fully_charged_billable.gateway_charge + fully_charged_billable.usage_charge
        )

        sms_line_item = self._create_sms_line_item()

        self.assertEqual(sms_line_item.quantity, 1)
        self.assertEqual(sms_line_item.unit_cost, sms_cost)
        self.assertIsNotNone(sms_line_item.unit_description)

        self.assertEqual(sms_line_item.subtotal, sms_cost)
        self.assertEqual(sms_line_item.total, sms_cost)