|
|
@@ -6,6 +6,7 @@ from django.test import TestCase
|
|
6
|
6
|
|
|
7
|
7
|
from oscar.core.loading import get_model
|
|
8
|
8
|
from oscar.test.factories import (
|
|
|
9
|
+ PartnerFactory,
|
|
9
|
10
|
ProductAttributeFactory,
|
|
10
|
11
|
ProductClassFactory,
|
|
11
|
12
|
ProductFactory,
|
|
|
@@ -289,6 +290,48 @@ class ProductAttributeTest(TestCase):
|
|
289
|
290
|
self.assertEqual(html, "<h1>Hi</h1>")
|
|
290
|
291
|
self.assertTrue(hasattr(html, "__html__"))
|
|
291
|
292
|
|
|
|
293
|
+ def test_entity_attributes(self):
|
|
|
294
|
+ unrelated_object = PartnerFactory()
|
|
|
295
|
+ _ = ProductAttributeFactory(
|
|
|
296
|
+ type="entity",
|
|
|
297
|
+ product_class=self.product_class,
|
|
|
298
|
+ name="entity",
|
|
|
299
|
+ code="entity",
|
|
|
300
|
+ )
|
|
|
301
|
+ self.product.attr.entity = unrelated_object
|
|
|
302
|
+ self.product.attr.weight = 3
|
|
|
303
|
+ self.product.save()
|
|
|
304
|
+
|
|
|
305
|
+ self.product.refresh_from_db()
|
|
|
306
|
+ self.assertEqual(self.product.attr.entity, unrelated_object)
|
|
|
307
|
+
|
|
|
308
|
+ another_product = ProductFactory(
|
|
|
309
|
+ title="Aother",
|
|
|
310
|
+ stockrecords=None,
|
|
|
311
|
+ product_class=self.product_class,
|
|
|
312
|
+ structure="standalone",
|
|
|
313
|
+ upc="henk1239",
|
|
|
314
|
+ )
|
|
|
315
|
+
|
|
|
316
|
+ self.product.attr.entity = another_product
|
|
|
317
|
+ self.product.attr.weight = 5
|
|
|
318
|
+ self.product.save()
|
|
|
319
|
+
|
|
|
320
|
+ self.product.refresh_from_db()
|
|
|
321
|
+ self.assertEqual(self.product.attr.entity, another_product)
|
|
|
322
|
+
|
|
|
323
|
+ self.product.attr.entity = None
|
|
|
324
|
+ self.product.save()
|
|
|
325
|
+
|
|
|
326
|
+ self.product.refresh_from_db()
|
|
|
327
|
+
|
|
|
328
|
+ self.assertEqual(self.product.attr.entity, None)
|
|
|
329
|
+
|
|
|
330
|
+ product = Product.objects.get(pk=self.product.pk)
|
|
|
331
|
+ with self.assertRaises(AttributeError):
|
|
|
332
|
+ # pylint: disable=pointless-statement
|
|
|
333
|
+ product.attr.entity
|
|
|
334
|
+
|
|
292
|
335
|
|
|
293
|
336
|
class MultiOptionTest(TestCase):
|
|
294
|
337
|
fixtures = ["productattributes"]
|