Beispiel #1
0
	def test_str(self):
		charge = Charge(
			amount=50,
			currency="usd",
			id="ch_test",
			status=ChargeStatus.failed,
			captured=False,
			paid=False,
		)
		self.assertEqual(str(charge), "$50.00 USD (Uncaptured)")

		charge.captured = True
		self.assertEqual(str(charge), "$50.00 USD (Failed)")
		charge.status = ChargeStatus.succeeded

		charge.dispute = Dispute()
		self.assertEqual(str(charge), "$50.00 USD (Disputed)")

		charge.dispute = None
		charge.refunded = True
		charge.amount_refunded = 50
		self.assertEqual(str(charge), "$50.00 USD (Refunded)")

		charge.refunded = False
		self.assertEqual(str(charge), "$50.00 USD (Partially refunded)")

		charge.amount_refunded = 0
		self.assertEqual(str(charge), "$50.00 USD")
    def test__attach_objects_post_save_hook(
        self,
        dispute_retrieve_mock,
        file_retrieve_mock,
        balance_transaction_retrieve_mock,
        charge_retrieve_mock,
        payment_intent_retrieve_mock,
        payment_method_retrieve_mock,
    ):

        dispute = Dispute.sync_from_stripe_data(FAKE_DISPUTE_III)
        assert dispute.id == FAKE_DISPUTE_III["id"]

        # assert File was retrieved correctly
        file_retrieve_mock.assert_called_once_with(
            id=FAKE_DISPUTE_III["evidence"]["receipt"],
            api_key=djstripe_settings.STRIPE_SECRET_KEY,
            expand=[],
            stripe_account=None,
        )

        # assert Balance Transactions were retrieved correctly
        balance_transaction_retrieve_mock.assert_called_once_with(
            id=FAKE_DISPUTE_BALANCE_TRANSACTION["id"],
            api_key=djstripe_settings.STRIPE_SECRET_KEY,
            expand=[],
            stripe_account=None,
        )
    def test___str__(
        self,
        dispute_retrieve_mock,
        file_retrieve_mock,
        balance_transaction_retrieve_mock,
        charge_retrieve_mock,
        payment_intent_retrieve_mock,
        payment_method_retrieve_mock,
    ):

        dispute = Dispute.sync_from_stripe_data(FAKE_DISPUTE_I)
        self.assertEqual(str(dispute), "$10.00 USD (Needs response) ")
    def test_sync_from_stripe_data(
        self,
        dispute_retrieve_mock,
        file_retrieve_mock,
        balance_transaction_retrieve_mock,
        charge_retrieve_mock,
        payment_intent_retrieve_mock,
        payment_method_retrieve_mock,
    ):

        dispute = Dispute.sync_from_stripe_data(FAKE_DISPUTE_I)
        assert dispute.id == FAKE_DISPUTE_I["id"]
    def test_get_stripe_dashboard_url(
        self,
        dispute_retrieve_mock,
        file_retrieve_mock,
        balance_transaction_retrieve_mock,
        charge_retrieve_mock,
        payment_intent_retrieve_mock,
        payment_method_retrieve_mock,
    ):

        dispute = Dispute.sync_from_stripe_data(FAKE_DISPUTE_I)
        self.assertEqual(
            dispute.get_stripe_dashboard_url(),
            f"{dispute._get_base_stripe_dashboard_url()}"
            f"{dispute.stripe_dashboard_item_name}/{dispute.payment_intent.id}",
        )