Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

custom_range_tests.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from django.core.exceptions import ValidationError
  2. from django.test import TestCase
  3. from oscar.test.factories import create_product
  4. from django.db import IntegrityError
  5. from django.utils.translation import ugettext_lazy as _
  6. from oscar.apps.offer import custom
  7. class CustomRange(object):
  8. name = "Custom range"
  9. def contains_product(self, product):
  10. return product.title.startswith("A")
  11. def num_products(self):
  12. return None
  13. class CustomRangeLazy(object):
  14. name = _("Custom range with ugettext_lazy")
  15. def contains_product(self, product):
  16. return product.title.startswith("B")
  17. def num_products(self):
  18. return None
  19. class TestACustomRange(TestCase):
  20. def test_creating_unique_custom_range(self):
  21. custom.create_range(CustomRange)
  22. try:
  23. custom.create_range(CustomRange)
  24. except IntegrityError:
  25. self.fail(
  26. 'IntegrityError when added the same CustomRange as existing')
  27. def test_must_have_a_text_name(self):
  28. try:
  29. custom.create_range(CustomRangeLazy)
  30. except ValidationError:
  31. pass
  32. else:
  33. self.fail("Range can't have ugettext titles")
  34. def test_correctly_includes_match(self):
  35. rng = custom.create_range(CustomRange)
  36. test_product = create_product(title=u"A tale")
  37. self.assertTrue(rng.contains_product(test_product))
  38. def test_correctly_excludes_nonmatch(self):
  39. rng = custom.create_range(CustomRange)
  40. test_product = create_product(title=u"B tale")
  41. self.assertFalse(rng.contains_product(test_product))