Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

availability_tests.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from decimal import Decimal as D
  2. import datetime
  3. from django.test import TestCase
  4. from oscar.apps.offer import models
  5. from oscar.core.compat import get_user_model
  6. User = get_user_model()
  7. class TestADateBasedConditionalOffer(TestCase):
  8. def setUp(self):
  9. self.start = datetime.date(2011, 1, 1)
  10. self.end = datetime.date(2011, 2, 1)
  11. self.offer = models.ConditionalOffer(start_datetime=self.start,
  12. end_datetime=self.end)
  13. def test_is_available_during_date_range(self):
  14. test = datetime.date(2011, 1, 10)
  15. self.assertTrue(self.offer.is_available(test_date=test))
  16. def test_is_inactive_before_date_range(self):
  17. test = datetime.date(2010, 3, 10)
  18. self.assertFalse(self.offer.is_available(test_date=test))
  19. def test_is_inactive_after_date_range(self):
  20. test = datetime.date(2011, 3, 10)
  21. self.assertFalse(self.offer.is_available(test_date=test))
  22. def test_is_active_on_end_datetime(self):
  23. self.assertTrue(self.offer.is_available(test_date=self.end))
  24. class TestAConsumptionFrequencyBasedConditionalOffer(TestCase):
  25. def setUp(self):
  26. self.offer = models.ConditionalOffer(max_global_applications=4)
  27. def test_is_available_with_no_applications(self):
  28. self.assertTrue(self.offer.is_available())
  29. def test_is_available_with_fewer_applications_than_max(self):
  30. self.offer.num_applications = 3
  31. self.assertTrue(self.offer.is_available())
  32. def test_is_inactive_with_equal_applications_to_max(self):
  33. self.offer.num_applications = 4
  34. self.assertFalse(self.offer.is_available())
  35. def test_is_inactive_with_more_applications_than_max(self):
  36. self.offer.num_applications = 4
  37. self.assertFalse(self.offer.is_available())
  38. def test_restricts_number_of_applications_correctly_with_no_applications(self):
  39. self.assertEqual(4, self.offer.get_max_applications())
  40. def test_restricts_number_of_applications_correctly_with_fewer_applications_than_max(self):
  41. self.offer.num_applications = 3
  42. self.assertEqual(1, self.offer.get_max_applications())
  43. def test_restricts_number_of_applications_correctly_with_more_applications_than_max(self):
  44. self.offer.num_applications = 5
  45. self.assertEqual(0, self.offer.get_max_applications())
  46. class TestCappedDiscountConditionalOffer(TestCase):
  47. def setUp(self):
  48. self.offer = models.ConditionalOffer(
  49. max_discount=D('100.00'),
  50. total_discount=D('0.00'))
  51. def test_is_available_when_below_threshold(self):
  52. self.assertTrue(self.offer.is_available())
  53. def test_is_inactive_when_on_threshold(self):
  54. self.offer.total_discount = self.offer.max_discount
  55. self.assertFalse(self.offer.is_available())
  56. def test_is_inactive_when_above_threshold(self):
  57. self.offer.total_discount = self.offer.max_discount + D('10.00')
  58. self.assertFalse(self.offer.is_available())
  59. class TestASuspendedOffer(TestCase):
  60. def setUp(self):
  61. self.offer = models.ConditionalOffer(
  62. status=models.ConditionalOffer.SUSPENDED)
  63. def test_is_unavailable(self):
  64. self.assertFalse(self.offer.is_available())
  65. def test_lists_suspension_as_an_availability_restriction(self):
  66. restrictions = self.offer.availability_restrictions()
  67. self.assertEqual(1, len(restrictions))