subscription: fix tests

Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
Skia 2017-09-07 11:21:32 +02:00
parent 96d0ae36be
commit 04fdb251e2

View File

@ -42,7 +42,7 @@ def date_mock_today(year, month, day):
FakeDate.today = classmethod(lambda cls: date(year, month, day))
class SubscriptionTest(TestCase):
class SubscriptionUnitTest(TestCase):
@mock.patch('subscription.models.date', FakeDate)
def test_start_dates_sliding_without_start(self):
@ -102,23 +102,7 @@ class SubscriptionTest(TestCase):
d = Subscription.compute_end(duration=4, start=date(2015, 9, 18))
self.assertTrue(d == date(2017, 9, 18))
@mock.patch('subscription.models.date', FakeDate)
def test_dates_sliding_with_subscribed_user(self):
user = User.objects.filter(pk=self.user.pk).first()
s = Subscription(member=user, subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = date(2015, 8, 29)
s.subscription_end = s.compute_end(duration=2,
start=s.subscription_start)
s.save()
self.assertTrue(s.subscription_end == date(2016, 8, 29))
date_mock_today(2016, 8, 25)
d = Subscription.compute_end(duration=2,
user=user)
self.assertTrue(d == date(2017, 8, 29))
class DecimalDurationTest(TestCase):
class SubscriptionIntegrationTest(TestCase):
def setUp(self):
call_command("populate")
self.user = User.objects.filter(username="public").first()
@ -153,3 +137,18 @@ class DecimalDurationTest(TestCase):
s.save()
self.assertTrue(s.subscription_end == date(2017, 12, 29))
@mock.patch('subscription.models.date', FakeDate)
def test_dates_sliding_with_subscribed_user(self):
user = User.objects.filter(pk=self.user.pk).first()
s = Subscription(member=user, subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = date(2015, 8, 29)
s.subscription_end = s.compute_end(duration=2,
start=s.subscription_start)
s.save()
self.assertTrue(s.subscription_end == date(2016, 8, 29))
date_mock_today(2016, 8, 25)
d = Subscription.compute_end(duration=2,
user=user)
self.assertTrue(d == date(2017, 8, 29))