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.1KB

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