Exemplo n.º 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")
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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()
Exemplo n.º 5
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)
Exemplo n.º 6
0
	def test_create_card_finds_customer(self):
		card = Card.sync_from_stripe_data(deepcopy(FAKE_CARD))

		self.assertEqual(self.customer, card.customer)
		self.assertEqual(
			card.get_stripe_dashboard_url(), self.customer.get_stripe_dashboard_url()
		)
Exemplo n.º 7
0
    def test_str(self):
        fake_card = deepcopy(FAKE_CARD)
        card = Card.sync_from_stripe_data(fake_card)

        self.assertEqual(
            "<brand={brand}, last4={last4}, exp_month={exp_month}, exp_year={exp_year}, stripe_id={stripe_id}>".format(
                brand=fake_card["brand"],
                last4=fake_card["last4"],
                exp_month=fake_card["exp_month"],
                exp_year=fake_card["exp_year"],
                stripe_id=fake_card["id"]
            ),
            str(card)
        )
Exemplo n.º 8
0
	def test_str(self):
		fake_card = deepcopy(FAKE_CARD)
		card = Card.sync_from_stripe_data(fake_card)

		self.assertEqual(
			"<brand={brand}, last4={last4}, exp_month={exp_month}, exp_year={exp_year}, id={id}>".format(
				brand=fake_card["brand"],
				last4=fake_card["last4"],
				exp_month=fake_card["exp_month"],
				exp_year=fake_card["exp_year"],
				id=fake_card["id"],
			),
			str(card),
		)

		self.assert_fks(card, expected_blank_fks={"djstripe.Customer.coupon"})
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def test_attach_objects_hook_without_customer(self):
        FAKE_CARD_DICT = deepcopy(FAKE_CARD)
        FAKE_CARD_DICT["customer"] = None

        card = Card.sync_from_stripe_data(FAKE_CARD_DICT)
        self.assertEqual(card.customer, None)
Exemplo n.º 11
0
	def test_card_create_token(self, token_create_mock):
		card = {"number": "4242", "exp_month": 5, "exp_year": 2012, "cvc": 445}
		Card.create_token(**card)

		token_create_mock.assert_called_with(api_key=ANY, card=card)
Exemplo n.º 12
0
    def test_api_list(self, customer_retrieve_mock):
        card_list = Card.api_list(customer=self.customer)

        self.assertEqual([FAKE_CARD, FAKE_CARD_V], card_list)
Exemplo n.º 13
0
    def test_card_create_token(self, token_create_mock):
        card = {"number": "4242", "exp_month": 5, "exp_year": 2012, "cvc": 445}
        Card.create_token(**card)

        token_create_mock.assert_called_with(card=card)
Exemplo n.º 14
0
 def test_attach_objects_hook_without_customer(self):
     with self.assertRaisesMessage(ValidationError, "A customer was not attached to this card."):
         Card.sync_from_stripe_data(deepcopy(FAKE_CARD_III))
Exemplo n.º 15
0
 def test_attach_objects_hook_without_account(self):
     card = Card.sync_from_stripe_data(FAKE_CARD)
     self.assertEqual(card.account, None)
Exemplo n.º 16
0
    def test_api_list(self, customer_retrieve_mock):
        card_list = Card.api_list(customer=self.customer)

        self.assertCountEqual([FAKE_CARD, FAKE_CARD_III],
                              [i for i in card_list])
Exemplo n.º 17
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)
Exemplo n.º 18
0
    def test_create_card_finds_customer(self):
        card = Card.sync_from_stripe_data(deepcopy(FAKE_CARD))

        self.assertEqual(self.customer, card.customer)
        self.assertEqual(card.get_stripe_dashboard_url(), self.customer.get_stripe_dashboard_url())
Exemplo n.º 19
0
	def test_api_list(self, customer_retrieve_mock):
		card_list = Card.api_list(customer=self.customer)

		self.assertEqual([FAKE_CARD, FAKE_CARD_V], card_list)
Exemplo n.º 20
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)
Exemplo n.º 21
0
	def test_attach_objects_hook_without_customer(self):
		card = Card.sync_from_stripe_data(deepcopy(FAKE_CARD_III))
		self.assertEqual(card.customer, None)
Exemplo n.º 22
0
 def test_attach_objects_hook_without_customer(self):
     card = Card.sync_from_stripe_data(deepcopy(FAKE_CARD_III))
     self.assertEqual(card.customer, None)
Exemplo n.º 23
0
 def test_attach_objects_hook_without_customer(self):
     with self.assertRaisesMessage(ValidationError, "A customer was not attached to this card."):
         Card.sync_from_stripe_data(deepcopy(FAKE_CARD_III))