This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_category.py
57 lines (42 loc) · 1.84 KB
/
test_category.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from unittest.mock import patch
from saleor.product.filters import ProductCategoryFilter
from saleor.product.models import Category
from saleor.product.utils import collect_categories_tree_products, delete_categories
def test_product_category_filter_filters_from_child_category(
product_type, categories_tree
):
product_filter = ProductCategoryFilter(data={}, category=categories_tree)
attributes = product_filter._get_attributes()
product_attr = product_type.product_attributes.get()
variant_attr = product_type.variant_attributes.get()
assert product_attr in attributes
assert variant_attr in attributes
def test_collect_categories_tree_products(categories_tree):
parent = categories_tree
child = parent.children.first()
products = parent.products.all() | child.products.all()
result = collect_categories_tree_products(parent)
assert len(result) == len(products)
assert set(result.values_list("pk", flat=True)) == set(
products.values_list("pk", flat=True)
)
@patch("saleor.product.utils.update_products_minimal_variant_prices_task")
def test_delete_categories(
mock_update_products_minimal_variant_prices_task,
categories_tree_with_published_products,
):
parent = categories_tree_with_published_products
child = parent.children.first()
product_list = [child.products.first(), parent.products.first()]
delete_categories([parent.pk])
assert not Category.objects.filter(
id__in=[category.id for category in [parent, child]]
).exists()
mock_update_products_minimal_variant_prices_task.delay.assert_called_once_with(
product_ids=[p.pk for p in product_list]
)
for product in product_list:
product.refresh_from_db()
assert not product.category
assert not product.is_published
assert not product.publication_date