Example #1
0
    def test_set_autopay(self, fake_customer):
        fake_customer.__get__ = mock.Mock(
            return_value=self.fake_stripe_customer)
        self.assertEqual(self.billing_account.auto_pay_user, None)
        self.assertFalse(self.billing_account.auto_pay_enabled)

        self.payment_method.set_autopay(self.fake_card, self.billing_account,
                                        None)
        self.assertEqual(
            self.fake_card.metadata,
            {"auto_pay_{}".format(self.billing_account.id): 'True'})
        self.assertEqual(self.billing_account.auto_pay_user, self.web_user)
        self.assertTrue(self.billing_account.auto_pay_enabled)

        self.payment_method.set_autopay(self.fake_card, self.billing_account_2,
                                        None)
        self.assertEqual(
            self.fake_card.metadata, {
                "auto_pay_{}".format(self.billing_account.id): 'True',
                "auto_pay_{}".format(self.billing_account_2.id): 'True'
            })

        other_web_user = generator.create_arbitrary_web_user_name()
        other_payment_method = StripePaymentMethod(web_user=other_web_user)
        different_fake_card = FakeStripeCard()

        other_payment_method.set_autopay(different_fake_card,
                                         self.billing_account, None)
        self.assertEqual(self.billing_account.auto_pay_user, other_web_user)
        self.assertTrue(different_fake_card.metadata["auto_pay_{}".format(
            self.billing_account.id)])
        self.assertFalse(self.fake_card.metadata["auto_pay_{}".format(
            self.billing_account.id)] == 'True')
Example #2
0
 def _create_autopay_method(self, fake_customer):
     fake_customer.__get__ = mock.Mock(
         return_value=self.fake_stripe_customer)
     self.payment_method = StripePaymentMethod(
         web_user=self.autopay_user_email,
         customer_id=self.fake_stripe_customer.id)
     self.payment_method.set_autopay(self.fake_card, self.autopay_account,
                                     self.domain)
     self.payment_method.save()
Example #3
0
    def setUp(self):
        super(TestStripePaymentMethod, self).setUp()

        self.web_user = generator.create_arbitrary_web_user_name()
        self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)

        self.fake_card = FakeStripeCard()
        self.fake_stripe_customer = FakeStripeCustomer(cards=[self.fake_card])

        self.currency = generator.init_default_currency()
        self.billing_account = generator.billing_account(self.dimagi_user, self.web_user)
        self.billing_account_2 = generator.billing_account(self.dimagi_user, self.web_user)

        self.payment_method = StripePaymentMethod(web_user=self.web_user,
                                                  customer_id=self.fake_stripe_customer.id)
        self.payment_method.save()