Skip to content

Commit

Permalink
Add FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT
Browse files Browse the repository at this point in the history
for tests that assumed Subscription.is_period_current() = False
  • Loading branch information
therefromhere committed Jun 14, 2019
1 parent 27f643b commit 3d995f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,11 @@ def save(self, idempotency_key=None):
}
)

FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT = deepcopy(FAKE_SUBSCRIPTION)
FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT.update(
{"current_period_end": 1441907581, "current_period_start": 1439229181}
)

FAKE_SUBSCRIPTION_CANCELED = deepcopy(FAKE_SUBSCRIPTION)
FAKE_SUBSCRIPTION_CANCELED["status"] = "canceled"
FAKE_SUBSCRIPTION_CANCELED["canceled_at"] = 1440907580
Expand Down
4 changes: 3 additions & 1 deletion tests/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ def test_sync_from_stripe_data_refunded(
self.assertEqual(True, charge.refunded)
self.assertEqual(True, charge.captured)
self.assertEqual(False, charge.disputed)
self.assertEqual("VideoDoc consultation for ivanp0001 berkp0001", charge.description)
self.assertEqual(
"VideoDoc consultation for ivanp0001 berkp0001", charge.description
)
self.assertEqual(charge.amount, charge.amount_refunded)

charge_retrieve_mock.assert_not_called()
Expand Down
12 changes: 11 additions & 1 deletion tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
from djstripe.middleware import SubscriptionPaymentMiddleware
from djstripe.models import Customer, Subscription

from . import FAKE_CUSTOMER, FAKE_PRODUCT, FAKE_SUBSCRIPTION, FUTURE_DATE
from . import (
FAKE_CUSTOMER, FAKE_PRODUCT, FAKE_SUBSCRIPTION,
FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT, FUTURE_DATE
)


class MiddlewareURLTest(TestCase):
Expand Down Expand Up @@ -140,6 +143,13 @@ def test_is_superuser(self):
self.assertEqual(response, None)

def test_customer_has_inactive_subscription(self):
with patch(
"stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True
):
self.subscription = Subscription.sync_from_stripe_data(
FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT
)

request = self.factory.get("/testapp_content/")
request.user = self.user
request.urlconf = self.urlconf
Expand Down
7 changes: 4 additions & 3 deletions tests/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

from . import (
FAKE_CUSTOMER, FAKE_CUSTOMER_II, FAKE_PLAN, FAKE_PLAN_II, FAKE_PLAN_METERED,
FAKE_PRODUCT, FAKE_SUBSCRIPTION, FAKE_SUBSCRIPTION_CANCELED, FAKE_SUBSCRIPTION_METERED,
FAKE_SUBSCRIPTION_MULTI_PLAN, AssertStripeFksMixin, datetime_to_unix
FAKE_PRODUCT, FAKE_SUBSCRIPTION, FAKE_SUBSCRIPTION_CANCELED,
FAKE_SUBSCRIPTION_METERED, FAKE_SUBSCRIPTION_MULTI_PLAN,
FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT, AssertStripeFksMixin, datetime_to_unix
)


Expand Down Expand Up @@ -150,7 +151,7 @@ def test_extend_negative_delta(
product_retrieve_mock,
plan_retrieve_mock,
):
subscription_fake = deepcopy(FAKE_SUBSCRIPTION)
subscription_fake = deepcopy(FAKE_SUBSCRIPTION_NOT_PERIOD_CURRENT)
subscription = Subscription.sync_from_stripe_data(subscription_fake)

with self.assertRaises(ValueError):
Expand Down

0 comments on commit 3d995f5

Please sign in to comment.