Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

custom_range_tests.py 1.5KB

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