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.

custom_condition_tests.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from django.test import TestCase
  2. from django.contrib.auth.models import User
  3. from django_dynamic_fixture import G
  4. from oscar.apps.offer import custom, models
  5. from oscar.apps.basket.models import Basket
  6. class BasketOwnerCalledBarry(models.Condition):
  7. class Meta:
  8. proxy = True
  9. def is_satisfied(self, basket):
  10. if not basket.owner:
  11. return False
  12. return basket.owner.first_name.lower() == 'barry'
  13. def can_apply_condition(self, product):
  14. return False
  15. class TestCustomCondition(TestCase):
  16. def setUp(self):
  17. self.condition = custom.create_condition(BasketOwnerCalledBarry)
  18. self.offer = models.ConditionalOffer(
  19. condition=self.condition)
  20. self.basket = Basket()
  21. def test_is_not_satified_by_non_match(self):
  22. self.basket.owner = G(User, first_name="Alan")
  23. self.assertFalse(self.offer.is_condition_satisfied(self.basket))
  24. def test_is_satified_by_match(self):
  25. self.basket.owner = G(User, first_name="Barry")
  26. self.assertTrue(self.offer.is_condition_satisfied(self.basket))