|
|
@@ -3,13 +3,17 @@ from unittest import mock
|
|
3
|
3
|
|
|
4
|
4
|
import pytest
|
|
5
|
5
|
from django.test import TestCase
|
|
|
6
|
+from django.utils.timezone import now
|
|
6
|
7
|
|
|
7
|
8
|
from oscar.apps.basket.models import Basket
|
|
8
|
|
-from oscar.apps.offer import custom, models
|
|
|
9
|
+from oscar.apps.offer import applicator, custom, models
|
|
|
10
|
+from oscar.core.loading import get_class
|
|
9
|
11
|
from oscar.test import factories
|
|
10
|
12
|
from oscar.test.basket import add_product
|
|
11
|
13
|
from tests._site.model_tests_app.models import BasketOwnerCalledBarry
|
|
12
|
14
|
|
|
|
15
|
+Selector = get_class('partner.strategy', 'Selector')
|
|
|
16
|
+
|
|
13
|
17
|
|
|
14
|
18
|
@pytest.fixture
|
|
15
|
19
|
def products_some():
|
|
|
@@ -329,3 +333,47 @@ class TestCustomCondition(TestCase):
|
|
329
|
333
|
def test_is_satisfied_by_match(self):
|
|
330
|
334
|
self.basket.owner = factories.UserFactory(first_name="Barry")
|
|
331
|
335
|
assert self.offer.is_condition_satisfied(self.basket)
|
|
|
336
|
+
|
|
|
337
|
+
|
|
|
338
|
+class TestOffersWithCountCondition(TestCase):
|
|
|
339
|
+
|
|
|
340
|
+ def setUp(self):
|
|
|
341
|
+ super().setUp()
|
|
|
342
|
+
|
|
|
343
|
+ self.basket = factories.create_basket(empty=True)
|
|
|
344
|
+
|
|
|
345
|
+ # Create range and add one product to it.
|
|
|
346
|
+ rng = factories.RangeFactory(name='All products', includes_all_products=True)
|
|
|
347
|
+ self.product = factories.ProductFactory()
|
|
|
348
|
+ rng.add_product(self.product)
|
|
|
349
|
+
|
|
|
350
|
+ # Create a non-exclusive offer #1.
|
|
|
351
|
+ condition1 = factories.ConditionFactory(range=rng, value=D('1'))
|
|
|
352
|
+ benefit1 = factories.BenefitFactory(range=rng, value=D('10'))
|
|
|
353
|
+ self.offer1 = factories.ConditionalOfferFactory(
|
|
|
354
|
+ condition=condition1, benefit=benefit1, start_datetime=now(),
|
|
|
355
|
+ name='Test offer #1', exclusive=False,
|
|
|
356
|
+ )
|
|
|
357
|
+
|
|
|
358
|
+ # Create a non-exclusive offer #2.
|
|
|
359
|
+ condition2 = factories.ConditionFactory(range=rng, value=D('1'))
|
|
|
360
|
+ benefit2 = factories.BenefitFactory(range=rng, value=D('5'))
|
|
|
361
|
+ self.offer2 = factories.ConditionalOfferFactory(
|
|
|
362
|
+ condition=condition2, benefit=benefit2, start_datetime=now(),
|
|
|
363
|
+ name='Test offer #2', exclusive=False,
|
|
|
364
|
+ )
|
|
|
365
|
+
|
|
|
366
|
+ def add_product(self):
|
|
|
367
|
+ self.basket.add_product(self.product)
|
|
|
368
|
+ self.basket.strategy = Selector().strategy()
|
|
|
369
|
+ applicator.Applicator().apply(self.basket)
|
|
|
370
|
+
|
|
|
371
|
+ def assertOffersApplied(self, offers):
|
|
|
372
|
+ applied_offers = self.basket.applied_offers()
|
|
|
373
|
+ self.assertEqual(len(offers), len(applied_offers))
|
|
|
374
|
+ for offer in offers:
|
|
|
375
|
+ self.assertIn(offer.id, applied_offers, msg=offer)
|
|
|
376
|
+
|
|
|
377
|
+ def test_both_non_exclusive_offers_are_applied(self):
|
|
|
378
|
+ self.add_product()
|
|
|
379
|
+ self.assertOffersApplied([self.offer1, self.offer2])
|