def test_get_non_general_credits_by_subscription_only_returns_active_credits(self):
        # Add credits to subscription
        product_credit = self.add_product_credit(100.00)
        sms_credit = self.add_sms_credit(200.00)
        user_credit = self.add_user_credit(300.00)

        non_general_credits = CreditLine.get_non_general_credits_by_subscription(subscription=self.subscription)
        self.assertEqual(3, non_general_credits.count())
        self.assertIn(product_credit, non_general_credits)
        self.assertIn(sms_credit, non_general_credits)
        self.assertIn(user_credit, non_general_credits)

        # Deactivate one credit
        sms_credit.is_active = False
        sms_credit.save()

        non_general_credits = CreditLine.get_non_general_credits_by_subscription(subscription=self.subscription)
        self.assertEqual(2, non_general_credits.count())
        self.assertIn(product_credit, non_general_credits)
        self.assertNotIn(sms_credit, non_general_credits)
        self.assertIn(user_credit, non_general_credits)
Example #2
0
    def test_get_non_general_credits_by_subscription_only_returns_active_credits(self):
        # Add credits to subscription
        product_credit = self.add_product_credit(100.00)
        sms_credit = self.add_sms_credit(200.00)
        user_credit = self.add_user_credit(300.00)

        non_general_credits = CreditLine.get_non_general_credits_by_subscription(subscription=self.subscription)
        self.assertEqual(3, non_general_credits.count())
        self.assertIn(product_credit, non_general_credits)
        self.assertIn(sms_credit, non_general_credits)
        self.assertIn(user_credit, non_general_credits)

        # Deactivate one credit
        sms_credit.is_active = False
        sms_credit.save()

        non_general_credits = CreditLine.get_non_general_credits_by_subscription(subscription=self.subscription)
        self.assertEqual(2, non_general_credits.count())
        self.assertIn(product_credit, non_general_credits)
        self.assertNotIn(sms_credit, non_general_credits)
        self.assertIn(user_credit, non_general_credits)
Example #3
0
 def _get_credit_info(self, subscription):
     return {
         'general_credit': self._fmt_credit(self._credit_grand_total(
             CreditLine.get_credits_by_subscription_and_features(
                 subscription
             )
         )),
         'feature_credit': self._fmt_credit(self._credit_grand_total(
             CreditLine.get_non_general_credits_by_subscription(subscription)
         )),
         'account_general_credit': self._fmt_credit(self._credit_grand_total(
             CreditLine.get_credits_for_account(
                 subscription.account
             ) if subscription.account else None
         )),
         'account_feature_credit': self._fmt_credit(self._credit_grand_total(
             CreditLine.get_non_general_credits_for_account(subscription.account)
         )),
     }