コード例 #1
0
    def test_api_call_bad_customer(self):
        exception_message = (
            "BankAccounts must be manipulated through a Customer. "
            "Pass a Customer object into this call.")

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            BankAccount._api_create(customer="fish")

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            BankAccount.api_list(customer="fish")
コード例 #2
0
    def test_api_call_bad_account(self):
        exception_message = (
            "BankAccounts must be manipulated through a Stripe Connected Account. "
            "Pass an Account object into this call.")

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            BankAccount._api_create(account="fish")

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            BankAccount.api_list(account="fish")
コード例 #3
0
    def test_api_call_no_customer_and_no_account(self):
        exception_message = (
            "BankAccounts must be manipulated through either a Stripe Connected Account or a customer. "
            "Pass a Customer or an Account object into this call.")

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            BankAccount._api_create()

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            BankAccount.api_list()
コード例 #4
0
    def test_remove_already_deleted_bankaccount_by_account(
        self,
        account_retrieve_mock,
        bank_account_delete_mock,
    ):
        stripe_bank_account = BankAccount._api_create(
            account=self.custom_account, source=FAKE_BANK_ACCOUNT_IV["id"])
        bank_account = BankAccount.sync_from_stripe_data(stripe_bank_account)
        self.assertEqual(
            1,
            BankAccount.objects.filter(id=stripe_bank_account["id"]).count())

        api_key = bank_account.default_api_key
        stripe_account = bank_account._get_stripe_account_id(api_key)

        assert bank_account.customer is None
        assert bank_account.account is not None

        # remove BankAccount
        bank_account.remove()
        self.assertEqual(
            0,
            BankAccount.objects.filter(id=stripe_bank_account["id"]).count())
        bank_account_delete_mock.assert_called_once_with(
            self.custom_account.id,
            bank_account.id,
            api_key=api_key,
            stripe_account=stripe_account,
        )

        # remove BankAccount again
        count, _ = BankAccount.objects.filter(
            id=stripe_bank_account["id"]).delete()
        self.assertEqual(0, count)
コード例 #5
0
    def test_remove_bankaccount_by_customer(
        self,
        customer_retrieve_source_mock,
        customer_retrieve_mock,
        bank_account_retrieve_mock,
        bank_account_delete_mock,
    ):
        stripe_bank_account = BankAccount._api_create(
            customer=self.customer, source=FAKE_BANK_ACCOUNT_SOURCE["id"])
        BankAccount.sync_from_stripe_data(stripe_bank_account)

        self.assertEqual(
            1,
            BankAccount.objects.filter(id=stripe_bank_account["id"]).count())

        bank_account = self.customer.bank_account.all()[0]
        bank_account.remove()

        self.assertEqual(
            0,
            BankAccount.objects.filter(id=stripe_bank_account["id"]).count())

        api_key = bank_account.default_api_key
        stripe_account = bank_account._get_stripe_account_id(api_key)

        bank_account_delete_mock.assert_called_once_with(
            self.customer.id,
            bank_account.id,
            api_key=api_key,
            stripe_account=stripe_account,
        )
コード例 #6
0
    def test__api_create_with_customer_absent(
        self, account_retrieve_mock, customer_retrieve_mock
    ):
        stripe_bank_account = BankAccount._api_create(
            account=self.custom_account, source=FAKE_BANK_ACCOUNT_IV["id"]
        )

        self.assertEqual(FAKE_BANK_ACCOUNT_IV, stripe_bank_account)
コード例 #7
0
    def test_remove_already_deleted_card(self, customer_retrieve_mock):
        stripe_bank_account = BankAccount._api_create(
            customer=self.customer, source=FAKE_BANK_ACCOUNT_SOURCE["id"])
        BankAccount.sync_from_stripe_data(stripe_bank_account)

        self.assertEqual(self.customer.bank_account.count(), 1)
        bank_account_object = self.customer.bank_account.first()
        BankAccount.objects.filter(id=stripe_bank_account["id"]).delete()
        self.assertEqual(self.customer.bank_account.count(), 0)
        bank_account_object.remove()
        self.assertEqual(self.customer.bank_account.count(), 0)
コード例 #8
0
    def test_remove_bankaccount_by_account(
        self,
        account_retrieve_mock,
    ):
        stripe_bank_account = BankAccount._api_create(
            account=self.custom_account, source=FAKE_BANK_ACCOUNT_IV["id"]
        )
        BankAccount.sync_from_stripe_data(stripe_bank_account)

        # remove BankAccount
        count, _ = BankAccount.objects.filter(id=stripe_bank_account["id"]).delete()
        self.assertEqual(1, count)
コード例 #9
0
    def test__api_create_with_customer_and_account(self, account_retrieve_mock,
                                                   customer_retrieve_mock):

        FAKE_BANK_ACCOUNT_DICT = deepcopy(FAKE_BANK_ACCOUNT_SOURCE)
        FAKE_BANK_ACCOUNT_DICT["account"] = FAKE_CUSTOM_ACCOUNT["id"]

        stripe_bank_account = BankAccount._api_create(
            account=self.custom_account,
            customer=self.customer,
            source=FAKE_BANK_ACCOUNT_DICT["id"],
        )

        self.assertEqual(FAKE_BANK_ACCOUNT_SOURCE, stripe_bank_account)
コード例 #10
0
    def test_remove(
        self,
        customer_retrieve_mock,
        bank_account_retrieve_mock,
        bank_account_delete_mock,
    ):
        stripe_bank_account = BankAccount._api_create(
            customer=self.customer, source=FAKE_BANK_ACCOUNT_SOURCE["id"])
        BankAccount.sync_from_stripe_data(stripe_bank_account)

        self.assertEqual(1, self.customer.bank_account.count())

        bank_account = self.customer.bank_account.all()[0]
        bank_account.remove()

        self.assertEqual(0, self.customer.bank_account.count())
        self.assertTrue(bank_account_delete_mock.called)
コード例 #11
0
    def test_api_create(self, customer_retrieve_mock):
        stripe_bank_account = BankAccount._api_create(
            customer=self.customer, source=FAKE_BANK_ACCOUNT_SOURCE["id"])

        self.assertEqual(FAKE_BANK_ACCOUNT_SOURCE, stripe_bank_account)