Browse Source

Merge pull request #2510 from sasha0/feature/2163/offer-proxy

Fix condition/offer proxy class name property validation.
master
Alexander Gaevsky 8 years ago
parent
commit
2f27da2e1e
No account linked to committer's email address

+ 1
- 1
src/oscar/apps/offer/abstract_models.py View File

@@ -67,7 +67,7 @@ class BaseOfferMixin(models.Model):
67 67
         This is used in the dropdowns within the offer dashboard.
68 68
         """
69 69
         proxy_instance = self.proxy()
70
-        if self.proxy_class and self == proxy_instance:
70
+        if self.proxy_class and self.__class__ == proxy_instance.__class__:
71 71
             raise AssertionError('Name property is not defined on proxy class.')
72 72
         return proxy_instance.name
73 73
 

+ 15
- 0
tests/_site/model_tests_app/models.py View File

@@ -57,6 +57,21 @@ class CustomBenefitModel(BaseOfferModel, Benefit):
57 57
         return self.name
58 58
 
59 59
 
60
+class CustomConditionModel(Condition):
61
+
62
+    name = 'Test condition'
63
+
64
+    class Meta:
65
+        proxy = True
66
+        app_label = 'tests'
67
+
68
+    def is_satisfied(self, offer, basket):
69
+        return True
70
+
71
+    def can_apply_condition(self, product):
72
+        return True
73
+
74
+
60 75
 class CustomBenefitWithoutName(Benefit):
61 76
     class Meta:
62 77
         proxy = True

+ 16
- 8
tests/integration/offer/test_custom.py View File

@@ -1,23 +1,31 @@
1 1
 from django.test import TestCase
2 2
 
3 3
 from oscar.apps.offer import custom
4
-
5
-from tests._site.model_tests_app.models import CustomBenefitWithoutName, CustomConditionWithoutName
4
+from tests._site.model_tests_app.models import (
5
+    CustomBenefitModel, CustomBenefitWithoutName, CustomConditionModel, CustomConditionWithoutName)
6 6
 
7 7
 
8 8
 class TestCustomBenefit(TestCase):
9 9
     def setUp(self):
10
-        self.custom_benefit = custom.create_benefit(CustomBenefitWithoutName)
10
+        self.custom_benefits = [
11
+            custom.create_benefit(CustomBenefitModel), custom.create_benefit(CustomBenefitWithoutName)]
12
+
13
+    def test_name(self):
14
+        self.assertEquals(self.custom_benefits[0].name, 'Test benefit')
11 15
 
12
-    def test_benefit_raises_assert_on_missing_title(self):
16
+    def test_raises_assert_on_missing_name(self):
13 17
         with self.assertRaisesMessage(AssertionError, 'Name property is not defined on proxy class.'):
14
-            str(self.custom_benefit)
18
+            str(self.custom_benefits[1])
15 19
 
16 20
 
17 21
 class TestCustomCondition(TestCase):
18 22
     def setUp(self):
19
-        self.custom_condition = custom.create_condition(CustomConditionWithoutName)
23
+        self.custom_conditions = [
24
+            custom.create_condition(CustomConditionModel), custom.create_condition(CustomConditionWithoutName)]
25
+
26
+    def test_name(self):
27
+        self.assertEquals(self.custom_conditions[0].name, 'Test condition')
20 28
 
21
-    def test_benefit_raises_assert_on_missing_title(self):
29
+    def test_raises_assert_on_missing_name(self):
22 30
         with self.assertRaisesMessage(AssertionError, 'Name property is not defined on proxy class.'):
23
-            str(self.custom_condition)
31
+            str(self.custom_conditions[1])

Loading…
Cancel
Save