Exemple #1
0
    def test_api_call_bad_customer(self):
        exception_message = "Cards must be manipulated through a Customer. Pass a Customer object into this call."

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

        with self.assertRaisesMessage(StripeObjectManipulationException, exception_message):
            Card.api_list(customer="fish")
Exemple #2
0
	def test_api_call_bad_customer(self):
		exception_message = "Cards must be manipulated through a Customer. Pass a Customer object into this call."

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

		with self.assertRaisesMessage(StripeObjectManipulationException, exception_message):
			Card.api_list(customer="fish")
Exemple #3
0
    def test_api_call_bad_account(self):
        exception_message = (
            "Cards must be manipulated through a Stripe Connected Account. "
            "Pass an Account object into this call.")

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

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            Card.api_list(account="fish")
Exemple #4
0
    def test_api_call_no_customer_and_no_account(self):
        exception_message = (
            "Cards 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):
            Card._api_create()

        with self.assertRaisesMessage(StripeObjectManipulationException,
                                      exception_message):
            Card.api_list()
Exemple #5
0
    def test_remove_already_deleted_card_by_account(self,
                                                    account_retrieve_mock,
                                                    card_delete_mock):

        stripe_card = Card._api_create(account=self.custom_account,
                                       source=FAKE_CARD_IV["id"])
        card = Card.sync_from_stripe_data(stripe_card)
        self.assertEqual(1, Card.objects.filter(id=stripe_card["id"]).count())

        # remove card
        card.remove()
        self.assertEqual(0, Card.objects.filter(id=stripe_card["id"]).count())

        # remove card again
        count, _ = Card.objects.filter(id=stripe_card["id"]).delete()
        self.assertEqual(0, count)

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

        card_delete_mock.assert_called_once_with(
            self.custom_account.id,
            card.id,
            api_key=api_key,
            stripe_account=stripe_account,
        )
Exemple #6
0
    def test_remove_card_by_customer(
        self,
        customer_retrieve_source_mock,
        customer_retrieve_mock,
        card_retrieve_mock,
        card_delete_mock,
    ):
        stripe_card = Card._api_create(customer=self.customer,
                                       source=FAKE_CARD["id"])
        Card.sync_from_stripe_data(stripe_card)

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

        # remove card
        card = self.customer.legacy_cards.all()[0]
        card.remove()

        self.assertEqual(0, self.customer.legacy_cards.count())
        api_key = card.default_api_key
        stripe_account = card._get_stripe_account_id(api_key)

        card_delete_mock.assert_called_once_with(self.customer.id,
                                                 card.id,
                                                 api_key=api_key,
                                                 stripe_account=stripe_account)
Exemple #7
0
    def test_remove_card_by_account(self, account_retrieve_mock):

        stripe_card = Card._api_create(account=self.custom_account,
                                       source=FAKE_CARD_IV["id"])
        Card.sync_from_stripe_data(stripe_card)
        # remove card
        count, _ = Card.objects.filter(id=stripe_card["id"]).delete()
        self.assertEqual(1, count)
Exemple #8
0
	def test_remove_already_deleted_card(self, customer_retrieve_mock):
		stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
		Card.sync_from_stripe_data(stripe_card)

		self.assertEqual(self.customer.legacy_cards.count(), 1)
		card_object = self.customer.legacy_cards.first()
		Card.objects.filter(id=stripe_card["id"]).delete()
		self.assertEqual(self.customer.legacy_cards.count(), 0)
		card_object.remove()
		self.assertEqual(self.customer.legacy_cards.count(), 0)
Exemple #9
0
    def test_remove_already_deleted_card(self, customer_retrieve_mock):
        stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
        Card.sync_from_stripe_data(stripe_card)

        self.assertEqual(self.customer.sources.count(), 1)
        card_object = self.customer.sources.first()
        Card.objects.filter(stripe_id=stripe_card["id"]).delete()
        self.assertEqual(self.customer.sources.count(), 0)
        card_object.remove()
        self.assertEqual(self.customer.sources.count(), 0)
Exemple #10
0
    def test_remove(self, customer_retrieve_mock, card_retrieve_mock, card_delete_mock):
        stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
        Card.sync_from_stripe_data(stripe_card)

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

        card = self.customer.sources.all()[0]
        card.remove()

        self.assertEqual(0, self.customer.sources.count())
        self.assertTrue(card_delete_mock.called)
Exemple #11
0
	def test_remove(self, customer_retrieve_mock, card_retrieve_mock, card_delete_mock):
		stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
		Card.sync_from_stripe_data(stripe_card)

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

		card = self.customer.legacy_cards.all()[0]
		card.remove()

		self.assertEqual(0, self.customer.legacy_cards.count())
		self.assertTrue(card_delete_mock.called)
Exemple #12
0
	def test_remove_unexpected_exception(self, customer_retrieve_mock, card_delete_mock):
		stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
		Card.sync_from_stripe_data(stripe_card)

		card_delete_mock.side_effect = InvalidRequestError("Unexpected Exception", "blah")

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

		card = self.customer.legacy_cards.all()[0]

		with self.assertRaisesMessage(InvalidRequestError, "Unexpected Exception"):
			card.remove()
Exemple #13
0
    def test_remove_unexpected_exception(self, customer_retrieve_mock, card_delete_mock):
        stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
        Card.sync_from_stripe_data(stripe_card)

        card_delete_mock.side_effect = InvalidRequestError("Unexpected Exception", "blah")

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

        card = self.customer.sources.all()[0]

        with self.assertRaisesMessage(InvalidRequestError, "Unexpected Exception"):
            card.remove()
Exemple #14
0
    def test__api_create_with_customer_and_account(self, account_retrieve_mock,
                                                   customer_retrieve_mock):
        FAKE_CARD_DICT = deepcopy(FAKE_CARD)
        FAKE_CARD_DICT["account"] = FAKE_CUSTOM_ACCOUNT["id"]

        stripe_card = Card._api_create(
            account=self.custom_account,
            customer=self.customer,
            source=FAKE_CARD_DICT["id"],
        )

        self.assertEqual(FAKE_CARD, stripe_card)
Exemple #15
0
    def test_remove_no_such_customer(self, customer_retrieve_mock, card_delete_mock):
        stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
        Card.sync_from_stripe_data(stripe_card)

        card_delete_mock.side_effect = InvalidRequestError("No such customer:", "blah")

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

        card = self.customer.sources.all()[0]
        card.remove()

        self.assertEqual(0, self.customer.sources.count())
        self.assertTrue(card_delete_mock.called)
Exemple #16
0
	def test_remove_no_such_customer(self, customer_retrieve_mock, card_delete_mock):
		stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])
		Card.sync_from_stripe_data(stripe_card)

		card_delete_mock.side_effect = InvalidRequestError("No such customer:", "blah")

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

		card = self.customer.legacy_cards.all()[0]
		card.remove()

		self.assertEqual(0, self.customer.legacy_cards.count())
		self.assertTrue(card_delete_mock.called)
Exemple #17
0
    def test_api_create(self, customer_retrieve_mock):
        stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])

        self.assertEqual(FAKE_CARD, stripe_card)
Exemple #18
0
    def test__api_create_with_customer_absent(self, account_retrieve_mock):
        stripe_card = Card._api_create(account=self.custom_account,
                                       source=FAKE_CARD_IV["id"])

        self.assertEqual(FAKE_CARD_IV, stripe_card)
Exemple #19
0
	def test_api_create(self, customer_retrieve_mock):
		stripe_card = Card._api_create(customer=self.customer, source=FAKE_CARD["id"])

		self.assertEqual(FAKE_CARD, stripe_card)