|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+from django.test import TestCase
|
|
|
2
|
+
|
|
|
3
|
+from oscar.apps.dashboard.catalogue.views import ProductListView
|
|
|
4
|
+from oscar.core.loading import get_model
|
|
|
5
|
+from oscar.test.factories import create_product
|
|
|
6
|
+from oscar.test.utils import RequestFactory
|
|
|
7
|
+
|
|
|
8
|
+Product = get_model('catalogue', 'Product')
|
|
|
9
|
+
|
|
|
10
|
+
|
|
|
11
|
+class ProductListViewTestCase(TestCase):
|
|
|
12
|
+ def test_searching_child_product_by_title_returns_parent_product(self):
|
|
|
13
|
+ self.parent_product = create_product(structure=Product.PARENT, title='Parent', upc='PARENT_UPC')
|
|
|
14
|
+ create_product(structure=Product.CHILD, title='Child', parent=self.parent_product, upc='CHILD_UPC')
|
|
|
15
|
+ view = ProductListView(request=RequestFactory().get('/?title=Child'))
|
|
|
16
|
+ assert list(view.get_queryset()) == [self.parent_product]
|
|
|
17
|
+
|
|
|
18
|
+ def test_searching_child_product_by_title_returns_1_parent_product_if_title_is_partially_shared(self):
|
|
|
19
|
+ self.parent_product = create_product(structure=Product.PARENT, title='Shared', upc='PARENT_UPC')
|
|
|
20
|
+ create_product(structure=Product.CHILD, title='Shared', parent=self.parent_product, upc='CHILD_UPC')
|
|
|
21
|
+ create_product(structure=Product.CHILD, title='Shared1', parent=self.parent_product, upc='CHILD_UPC1')
|
|
|
22
|
+ view = ProductListView(request=RequestFactory().get('/?title=Shared'))
|
|
|
23
|
+ assert list(view.get_queryset()) == [self.parent_product]
|
|
|
24
|
+
|
|
|
25
|
+ def test_searching_child_product_by_upc_returns_parent_product(self):
|
|
|
26
|
+ self.parent_product = create_product(structure=Product.PARENT, title='Parent', upc='PARENT_UPC')
|
|
|
27
|
+ create_product(structure=Product.CHILD, title='Child', parent=self.parent_product, upc='CHILD_UPC')
|
|
|
28
|
+ view = ProductListView(request=RequestFactory().get('/?upc=CHILD_UPC'))
|
|
|
29
|
+ assert list(view.get_queryset()) == [self.parent_product]
|
|
|
30
|
+
|
|
|
31
|
+ def test_searching_child_product_by_upc_returns_1_parent_product_if_upc_is_partially_shared(self):
|
|
|
32
|
+ self.parent_product = create_product(structure=Product.PARENT, title='Parent', upc='PARENT_UPC')
|
|
|
33
|
+ create_product(structure=Product.CHILD, title='Child', parent=self.parent_product, upc='CHILD_UPC')
|
|
|
34
|
+ create_product(structure=Product.CHILD, title='Child1', parent=self.parent_product, upc='CHILD_UPC1')
|
|
|
35
|
+ view = ProductListView(request=RequestFactory().get('/?upc=CHILD'))
|
|
|
36
|
+ assert list(view.get_queryset()) == [self.parent_product]
|