Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add test

fowczarekc5226aff6486
diff --git a/tests/conftest.py b/tests/conftest.py
index e8a706a104..dea3ca2e3d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -255,11 +255,22 @@ def category_with_image(db, image): # pylint: disable=W0613
@pytest.fixture
-def categories_tree(db):
+def categories_tree(db, product_type): # pylint: disable=W0613
parent = Category.objects.create(name='Parent', slug='parent')
parent.children.create(name='Child', slug='child')
+ child = parent.children.first()
+
+ product_attr = product_type.product_attributes.first()
+ attr_value = product_attr.values.first()
+ attributes = {smart_text(product_attr.pk): smart_text(attr_value.pk)}
+
+ Product.objects.create(
+ name='Test product', price=Money('10.00', 'USD'),
+ product_type=product_type, attributes=attributes, category=child)
+
return parent
+
@pytest.fixture
def non_default_category(db): # pylint: disable=W0613
return Category.objects.create(name='Not default', slug='not-default')
diff --git a/tests/test_category.py b/tests/test_category.py
new file mode 100644
index 0000000000..999e42316b
--- /dev/null
+++ b/tests/test_category.py
@@ -0,0 +1,12 @@
+from saleor.product.filters import ProductCategoryFilter
+
+
+def test(product_type, categories_tree):
+ product_filter = ProductCategoryFilter(data={}, category=categories_tree)
+ (product_attributes, variant_attributes) = product_filter._get_attributes()
+
+ attribut = product_type.product_attributes.get()
+ variant = product_type.variant_attributes.get()
+
+ assert attribut in product_attributes
+ assert variant in variant_attributes