You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

availability_tests.py 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. from django.test import TestCase
  2. from django_dynamic_fixture import G
  3. from oscar.apps.offer import models
  4. from oscar.apps.order.models import OrderDiscount
  5. from oscar.core.compat import get_user_model
  6. from oscar.test.factories import create_order
  7. User = get_user_model()
  8. class TestAPerUserConditionalOffer(TestCase):
  9. def setUp(self):
  10. self.offer = models.ConditionalOffer(max_user_applications=1)
  11. self.user = G(User)
  12. def test_is_available_with_no_applications(self):
  13. self.assertTrue(self.offer.is_available())
  14. def test_max_applications_is_correct_when_no_applications(self):
  15. self.assertEqual(1, self.offer.get_max_applications(self.user))
  16. def test_max_applications_is_correct_when_equal_applications(self):
  17. order = create_order(user=self.user)
  18. G(OrderDiscount, order=order, offer_id=self.offer.id, frequency=1)
  19. self.assertEqual(0, self.offer.get_max_applications(self.user))
  20. def test_max_applications_is_correct_when_more_applications(self):
  21. order = create_order(user=self.user)
  22. G(OrderDiscount, order=order, offer_id=self.offer.id, frequency=5)
  23. self.assertEqual(0, self.offer.get_max_applications(self.user))