Changeset View
Changeset View
Standalone View
Standalone View
looper/tests/test_orders.py
| import datetime | import datetime | ||||
| from unittest import mock | from unittest import mock | ||||
| import django.utils.timezone | import django.utils.timezone | ||||
| from . import AbstractLooperTestCase | from .base import AbstractLooperTestCase | ||||
| class OrdersTest(AbstractLooperTestCase): | class OrdersTest(AbstractLooperTestCase): | ||||
| def test_create_from_subscription(self): | def test_create_from_subscription(self): | ||||
| subscription = self.create_subscription() | subscription = self.create_subscription() | ||||
| order = subscription.generate_order() | order = subscription.generate_order() | ||||
| self.assertEqual('created', order.status) | self.assertEqual('created', order.status) | ||||
| self.assertEqual('Blender Development Fund Membership / Gold', order.name) | self.assertEqual('Blender Development Fund Membership / Gold', order.name) | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def test_subscription_already_active_bump_next_payment(self): | ||||
| subscription.save() | subscription.save() | ||||
| # Don't do this in the same database change as setting the status to active, | # Don't do this in the same database change as setting the status to active, | ||||
| # as it will otherwise auto-bump the next payment date. | # as it will otherwise auto-bump the next payment date. | ||||
| subscription.next_payment = old_next_payment | subscription.next_payment = old_next_payment | ||||
| subscription.save() | subscription.save() | ||||
| subscription.refresh_from_db() | subscription.refresh_from_db() | ||||
| self.assertEqual(subscription.next_payment, old_next_payment, | self.assertEqual( | ||||
| 'Next payment date should be in the past') | subscription.next_payment, old_next_payment, 'Next payment date should be in the past' | ||||
| ) | |||||
| # The order is paid while the subscription is active, which should bump | # The order is paid while the subscription is active, which should bump | ||||
| # the next payment date. | # the next payment date. | ||||
| order = subscription.generate_order() | order = subscription.generate_order() | ||||
| order.status = 'paid' | order.status = 'paid' | ||||
| order.save() | order.save() | ||||
| subscription.refresh_from_db() | subscription.refresh_from_db() | ||||
| order.refresh_from_db() | order.refresh_from_db() | ||||
| self.assertEqual('paid', order.status) | self.assertEqual('paid', order.status) | ||||
| self.assertEqual('active', subscription.status) | self.assertEqual('active', subscription.status) | ||||
| self.assertGreaterEqual( | self.assertGreaterEqual( | ||||
| subscription.next_payment, start_time, | subscription.next_payment, | ||||
| start_time, | |||||
| 'Paying for an active subscription should bump the next payment date ' | 'Paying for an active subscription should bump the next payment date ' | ||||
| 'if that date is in the past.') | 'if that date is in the past.', | ||||
| ) | |||||
| self.assertEqual(0, subscription.intervals_elapsed) | self.assertEqual(0, subscription.intervals_elapsed) | ||||
| def test_subscription_active_order_cancelled(self): | def test_subscription_active_order_cancelled(self): | ||||
| subscription = self.create_subscription() | subscription = self.create_subscription() | ||||
| subscription.status = 'active' | subscription.status = 'active' | ||||
| subscription.save() | subscription.save() | ||||
| order = subscription.generate_order() | order = subscription.generate_order() | ||||
| order.status = 'cancelled' | order.status = 'cancelled' | ||||
| order.save() | order.save() | ||||
| subscription.refresh_from_db() | subscription.refresh_from_db() | ||||
| order.refresh_from_db() | order.refresh_from_db() | ||||
| self.assertEqual('cancelled', order.status) | self.assertEqual('cancelled', order.status) | ||||
| self.assertEqual('active', subscription.status, | self.assertEqual( | ||||
| 'Cancelling an order should not influence an already-active subscription') | 'active', | ||||
| subscription.status, | |||||
| 'Cancelling an order should not influence an already-active subscription', | |||||
| ) | |||||
| def test_subscription_direct_active_order_fulfilled(self): | def test_subscription_direct_active_order_fulfilled(self): | ||||
| # This way the subscription is marked as 'active' while | # This way the subscription is marked as 'active' while | ||||
| # the order is still in 'created' state. The order skipping | # the order is still in 'created' state. The order skipping | ||||
| # the 'paid' state shouldn't matter to the subscription. | # the 'paid' state shouldn't matter to the subscription. | ||||
| subscription = self.create_subscription() | subscription = self.create_subscription() | ||||
| subscription.status = 'active' | subscription.status = 'active' | ||||
| subscription.save() | subscription.save() | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||