Skip to content

Commit

Permalink
Added CreateAccountMixin to various test classes
Browse files Browse the repository at this point in the history
This was done because the create_account auto-use fixture
was moved into the CreateAccountMixin class.
  • Loading branch information
arnav13081994 authored and jleclanche committed Mar 16, 2023
1 parent 92e2140 commit 800b012
Show file tree
Hide file tree
Showing 40 changed files with 156 additions and 76 deletions.
14 changes: 13 additions & 1 deletion tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
pytestmark = pytest.mark.django_db


class TestAccount(AssertStripeFksMixin, TestCase):
from .conftest import CreateAccountMixin


class TestAccount(CreateAccountMixin, AssertStripeFksMixin, TestCase):
@patch("stripe.Account.retrieve", autospec=True)
@patch(
"stripe.File.retrieve",
Expand Down Expand Up @@ -470,9 +473,18 @@ def test_api_reject(
api_key,
expected_api_key,
stripe_account,
monkeypatch,
):
"""Test that API reject properly uses the passed in parameters."""

def mock_account_retrieve(*args, **kwargs):
return FAKE_PLATFORM_ACCOUNT

monkeypatch.setattr(stripe.Account, "retrieve", mock_account_retrieve)

# create a Stripe Platform Account
FAKE_PLATFORM_ACCOUNT.create()

fake_account = deepcopy(FAKE_ACCOUNT)
fake_account_rejected = deepcopy(FAKE_ACCOUNT)
fake_account_rejected["charges_enabled"] = False
Expand Down
9 changes: 5 additions & 4 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
FAKE_SUBSCRIPTION_SCHEDULE,
)

from .conftest import CreateAccountMixin
from .fields.models import CustomActionModel

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -1120,8 +1121,8 @@ def test__sync_all_instances(self, admin_client, fake_selected_pks):
assert response.status_code == 200


class TestSubscriptionAdminCustomAction:
def test__cancel_subscription_instances( # noqa: C901
class TestSubscriptionAdminCustomAction(CreateAccountMixin):
def test__cancel_subscription_instances(
self,
admin_client,
monkeypatch,
Expand Down Expand Up @@ -1197,8 +1198,8 @@ def mock_plan_get(*args, **kwargs):
assert response.status_code == 200


class TestSubscriptionScheduleAdminCustomAction:
def test__release_subscription_schedule( # noqa: C901
class TestSubscriptionScheduleAdminCustomAction(CreateAccountMixin):
def test__release_subscription_schedule(
self,
admin_client,
monkeypatch,
Expand Down
14 changes: 12 additions & 2 deletions tests/test_apikey.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import patch

import pytest
import stripe
from django.test import TestCase

from djstripe.admin.admin import APIKeyAdminCreateForm
Expand All @@ -24,6 +25,7 @@
PK_LIVE = "pk_live_" + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXBBBB"

pytestmark = pytest.mark.django_db
from .conftest import CreateAccountMixin


def test_get_api_key_details_by_prefix():
Expand Down Expand Up @@ -54,8 +56,16 @@ def test_clean_public_apikey():
@patch("stripe.Account.retrieve", return_value=deepcopy(FAKE_PLATFORM_ACCOUNT))
@patch("stripe.File.retrieve", return_value=deepcopy(FAKE_FILEUPLOAD_ICON))
def test_apikey_detect_livemode_and_type(
fileupload_retrieve_mock, account_retrieve_mock
fileupload_retrieve_mock, account_retrieve_mock, monkeypatch
):
def mock_account_retrieve(*args, **kwargs):
return FAKE_PLATFORM_ACCOUNT

monkeypatch.setattr(stripe.Account, "retrieve", mock_account_retrieve)

# create a Stripe Platform Account
FAKE_PLATFORM_ACCOUNT.create()

keys_and_values = (
(PK_TEST, False, APIKeyType.publishable),
(RK_TEST, False, APIKeyType.restricted),
Expand All @@ -77,7 +87,7 @@ def test_apikey_detect_livemode_and_type(
assert key.type is type


class APIKeyTest(TestCase):
class APIKeyTest(CreateAccountMixin, TestCase):
def setUp(self):
# create a Stripe Platform Account
self.account = FAKE_PLATFORM_ACCOUNT.create()
Expand Down
8 changes: 5 additions & 3 deletions tests/test_balance_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import patch

import pytest
import stripe
from django.test.testcases import TestCase

from djstripe import models
Expand All @@ -25,9 +26,10 @@
)

pytestmark = pytest.mark.django_db
from .conftest import CreateAccountMixin


class TestBalanceTransactionStr:
class TestBalanceTransactionStr(CreateAccountMixin):
@pytest.mark.parametrize("transaction_status", BalanceTransactionStatus.__members__)
def test___str__(self, transaction_status):
modified_balance_transaction = deepcopy(FAKE_BALANCE_TRANSACTION)
Expand All @@ -42,7 +44,7 @@ def test___str__(self, transaction_status):
)


class TestBalanceTransactionSourceClass:
class TestBalanceTransactionSourceClass(CreateAccountMixin):
@pytest.mark.parametrize("transaction_type", ["card", "payout", "refund"])
def test_get_source_class_success(self, transaction_type):
modified_balance_transaction = deepcopy(FAKE_BALANCE_TRANSACTION)
Expand All @@ -67,7 +69,7 @@ def test_get_source_class_failure(self, transaction_type):
balance_transaction.get_source_class()


class TestBalanceTransaction(TestCase):
class TestBalanceTransaction(CreateAccountMixin, TestCase):
@patch(
"stripe.Invoice.retrieve",
return_value=deepcopy(FAKE_INVOICE),
Expand Down
3 changes: 2 additions & 1 deletion tests/test_bank_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
FAKE_STANDARD_ACCOUNT,
AssertStripeFksMixin,
)
from .conftest import CreateAccountMixin

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -121,7 +122,7 @@ def mock_account_get(*args, **kwargs):
)


class BankAccountTest(AssertStripeFksMixin, TestCase):
class BankAccountTest(CreateAccountMixin, AssertStripeFksMixin, TestCase):
def setUp(self):
# create a Standard Stripe Account
self.standard_account = FAKE_STANDARD_ACCOUNT.create()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
FAKE_STANDARD_ACCOUNT,
AssertStripeFksMixin,
)
from .conftest import CreateAccountMixin

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -80,7 +81,7 @@ def mock_account_get(*args, **kwargs):
)


class CardTest(AssertStripeFksMixin, TestCase):
class CardTest(CreateAccountMixin, AssertStripeFksMixin, TestCase):
def setUp(self):
# create a Standard Stripe Account
self.standard_account = FAKE_STANDARD_ACCOUNT.create()
Expand Down
7 changes: 6 additions & 1 deletion tests/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from decimal import Decimal
from unittest.mock import call, create_autospec, patch

import pytest
import stripe
from django.contrib.auth import get_user_model
from django.test.testcases import TestCase

Expand Down Expand Up @@ -34,9 +36,12 @@
FAKE_TRANSFER,
AssertStripeFksMixin,
)
from .conftest import CreateAccountMixin

pytestmark = pytest.mark.django_db

class ChargeTest(AssertStripeFksMixin, TestCase):

class ChargeTest(CreateAccountMixin, AssertStripeFksMixin, TestCase):
@classmethod
def setUp(self):
# create a Stripe Platform Account
Expand Down
6 changes: 4 additions & 2 deletions tests/test_coupon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
from decimal import Decimal

import pytest
import stripe
from django.test.testcases import TestCase

from djstripe.models import Coupon

from . import FAKE_COUPON
from .conftest import CreateAccountMixin

pytestmark = pytest.mark.django_db


class TransferTest(TestCase):
class TransferTest(CreateAccountMixin, TestCase):
def test_retrieve_coupon(self):
coupon_data = deepcopy(FAKE_COUPON)
coupon = Coupon.sync_from_stripe_data(coupon_data)
Expand Down Expand Up @@ -106,7 +108,7 @@ def test_human_readable_integer_percent_off_forever(self):
self.assertEqual(str(coupon), coupon.human_readable)


class TestCouponDecimal:
class TestCouponDecimal(CreateAccountMixin):
@pytest.mark.parametrize(
"inputted,expected",
[
Expand Down
7 changes: 5 additions & 2 deletions tests/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from copy import deepcopy
from unittest.mock import ANY, call, patch

import pytest
import stripe
from django.contrib.auth import get_user_model
from django.test import TestCase, override_settings
from django.utils import timezone
Expand Down Expand Up @@ -61,9 +63,10 @@
StripeList,
datetime_to_unix,
)
from .conftest import CreateAccountMixin


class TestCustomer(AssertStripeFksMixin, TestCase):
class TestCustomer(CreateAccountMixin, AssertStripeFksMixin, TestCase):
def setUp(self):
# create a Stripe Platform Account
self.account = FAKE_PLATFORM_ACCOUNT.create()
Expand Down Expand Up @@ -2223,7 +2226,7 @@ def test_is_subscribed_to_with_product_string_by_price(


# These tests use Plan which is deprecated in favor of Price
class TestCustomerLegacy(AssertStripeFksMixin, TestCase):
class TestCustomerLegacy(CreateAccountMixin, AssertStripeFksMixin, TestCase):
def setUp(self):
# create a Stripe Platform Account
self.account = FAKE_PLATFORM_ACCOUNT.create()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dispute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
)

pytestmark = pytest.mark.django_db
from .conftest import CreateAccountMixin


class TestDispute(TestCase):
class TestDispute(CreateAccountMixin, TestCase):
def setUp(self):
self.user = get_user_model().objects.create_user(
username="fake_customer_1", email=FAKE_CUSTOMER["email"]
Expand Down
5 changes: 4 additions & 1 deletion tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from copy import deepcopy
from unittest.mock import patch

import pytest
import stripe
from django.contrib.auth import get_user_model
from django.test import TestCase
from stripe.error import StripeError
Expand All @@ -18,9 +20,10 @@
FAKE_PLATFORM_ACCOUNT,
FAKE_TRANSFER,
)
from .conftest import CreateAccountMixin


class EventTest(TestCase):
class EventTest(CreateAccountMixin, TestCase):
def setUp(self):
self.user = get_user_model().objects.create_user(
username="pydanny", email="[email protected]"
Expand Down
Loading

0 comments on commit 800b012

Please sign in to comment.