| 12345678910111213141516171819202122232425262728293031323334353637 |
- from django.test import TestCase
- from django.contrib.auth.models import User
- from django_dynamic_fixture import G
-
- from oscar.apps.offer import custom, models
- from oscar.apps.basket.models import Basket
-
-
- class BasketOwnerCalledBarry(models.Condition):
-
- class Meta:
- proxy = True
-
- def is_satisfied(self, basket):
- if not basket.owner:
- return False
- return basket.owner.first_name.lower() == 'barry'
-
- def can_apply_condition(self, product):
- return False
-
-
- class TestCustomCondition(TestCase):
-
- def setUp(self):
- self.condition = custom.create_condition(BasketOwnerCalledBarry)
- self.offer = models.ConditionalOffer(
- condition=self.condition)
- self.basket = Basket()
-
- def test_is_not_satified_by_non_match(self):
- self.basket.owner = G(User, first_name="Alan")
- self.assertFalse(self.offer.is_condition_satisfied(self.basket))
-
- def test_is_satified_by_match(self):
- self.basket.owner = G(User, first_name="Barry")
- self.assertTrue(self.offer.is_condition_satisfied(self.basket))
|