|
|
@@ -4,9 +4,33 @@ from django.core.exceptions import ValidationError
|
|
4
|
4
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
5
|
5
|
from django.test import TestCase
|
|
6
|
6
|
|
|
|
7
|
+from oscar.apps.catalogue.models import Product
|
|
7
|
8
|
from oscar.test import factories
|
|
8
|
9
|
|
|
9
|
10
|
|
|
|
11
|
+class TestContainer(TestCase):
|
|
|
12
|
+
|
|
|
13
|
+ def test_attributes_initialised_before_write(self):
|
|
|
14
|
+ # Regression test for https://github.com/django-oscar/django-oscar/issues/3258
|
|
|
15
|
+ product_class = factories.ProductClassFactory()
|
|
|
16
|
+ product_class.attributes.create(name='a1', code='a1', required=True)
|
|
|
17
|
+ product_class.attributes.create(name='a2', code='a2', required=False)
|
|
|
18
|
+ product_class.attributes.create(name='a3', code='a3', required=True)
|
|
|
19
|
+ product = factories.ProductFactory(product_class=product_class)
|
|
|
20
|
+ product.attr.a1 = "v1"
|
|
|
21
|
+ product.attr.a3 = "v3"
|
|
|
22
|
+ product.attr.save()
|
|
|
23
|
+
|
|
|
24
|
+ product = Product.objects.get(pk=product.pk)
|
|
|
25
|
+ product.attr.a1 = "v2"
|
|
|
26
|
+ product.attr.a3 = "v6"
|
|
|
27
|
+ product.attr.save()
|
|
|
28
|
+
|
|
|
29
|
+ product = Product.objects.get(pk=product.pk)
|
|
|
30
|
+ assert product.attr.a1 == "v2"
|
|
|
31
|
+ assert product.attr.a3 == "v6"
|
|
|
32
|
+
|
|
|
33
|
+
|
|
10
|
34
|
class TestBooleanAttributes(TestCase):
|
|
11
|
35
|
|
|
12
|
36
|
def setUp(self):
|
|
|
@@ -52,7 +76,7 @@ class TestMultiOptionAttributes(TestCase):
|
|
52
|
76
|
product = factories.ProductFactory()
|
|
53
|
77
|
# We'll save two out of the three available options
|
|
54
|
78
|
self.attr.save_value(product, [self.options[0], self.options[2]])
|
|
55
|
|
- product.refresh_from_db()
|
|
|
79
|
+ product = Product.objects.get(pk=product.pk)
|
|
56
|
80
|
self.assertEqual(list(product.attr.sizes), [self.options[0], self.options[2]])
|
|
57
|
81
|
|
|
58
|
82
|
def test_delete_multi_option_value(self):
|
|
|
@@ -60,7 +84,7 @@ class TestMultiOptionAttributes(TestCase):
|
|
60
|
84
|
self.attr.save_value(product, [self.options[0], self.options[1]])
|
|
61
|
85
|
# Now delete these values
|
|
62
|
86
|
self.attr.save_value(product, None)
|
|
63
|
|
- product.refresh_from_db()
|
|
|
87
|
+ product = Product.objects.get(pk=product.pk)
|
|
64
|
88
|
self.assertFalse(hasattr(product.attr, 'sizes'))
|
|
65
|
89
|
|
|
66
|
90
|
def test_multi_option_value_as_text(self):
|