コード例 #1
0
    def test_clean(self):
        account = BillingAccount.objects.create(
            currency=generator.init_default_currency(),
        )
        subscription = Subscription.objects.create(
            account=account,
            date_start=date.today(),
            plan_version=generator.subscribable_plan(),
            subscriber=Subscriber.objects.create(domain='test')
        )
        invoice = Invoice.objects.create(
            date_start=date.today(),
            date_end=date.today(),
            subscription=subscription,
        )
        line_item = LineItem.objects.create(
            invoice=invoice,
        )

        with self.assertRaises(ValidationError):
            try:
                CreditAdjustment(
                    invoice=invoice,
                    line_item=line_item,
                ).save()
            except ValidationError as e:
                self.assertIn('__all__', e.error_dict)
                raise e
コード例 #2
0
 def test_patchy_coverage(self):
     some_plan = generator.subscribable_plan()
     middle_date = self.invoice_end - datetime.timedelta(days=15)
     Subscription.new_domain_subscription(
         self.account, self.domain, some_plan,
         date_start=self.invoice_start + datetime.timedelta(days=1),
         date_end=middle_date
     )
     next_start = middle_date + datetime.timedelta(days=2)
     next_end = next_start + datetime.timedelta(days=2)
     Subscription.new_domain_subscription(
         self.account, self.domain, some_plan,
         date_start=next_start,
         date_end=next_end,
     )
     final_start = next_end + datetime.timedelta(days=2)
     Subscription.new_domain_subscription(
         self.account, self.domain, some_plan,
         date_start=final_start,
         date_end=self.invoice_end - datetime.timedelta(days=1),
     )
     subscriptions = self.invoice_factory._get_subscriptions()
     self.assertEqual(len(subscriptions), 3)
     community_ranges = self.invoice_factory._get_community_ranges(subscriptions)
     self.assertEqual(len(community_ranges), 4)
     self._clean_subs()
コード例 #3
0
 def test_full_coverage(self):
     some_plan = generator.subscribable_plan()
     Subscription.new_domain_subscription(
         self.account, self.domain, some_plan,
         date_start=self.invoice_start,
         date_end=self.invoice_end + datetime.timedelta(days=1),
     )
     subscriptions = self.invoice_factory._get_subscriptions()
     community_ranges = self.invoice_factory._get_community_ranges(subscriptions)
     self.assertEqual(len(community_ranges), 0)
     self._clean_subs()
コード例 #4
0
 def test_incomplete_starting_coverage(self):
     some_plan = generator.subscribable_plan()
     subscription = Subscription.new_domain_subscription(
         self.account, self.domain, some_plan,
         date_start=self.invoice_start + datetime.timedelta(days=3)
     )
     subscriptions = self.invoice_factory._get_subscriptions()
     community_ranges = self.invoice_factory._get_community_ranges(subscriptions)
     self.assertEqual(len(community_ranges), 1)
     self.assertEqual(community_ranges[0][0], self.invoice_start)
     self.assertEqual(community_ranges[0][1], subscription.date_start)
     self._clean_subs()