Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tests for create function for deleteing categories
IKarbowiake4df38589271
diff --git a/tests/api/test_bulk_delete.py b/tests/api/test_bulk_delete.pyindex 49113c8d63..d921f4b2de 100644--- a/tests/api/test_bulk_delete.py+++ b/tests/api/test_bulk_delete.py@@ -195,10 +195,7 @@ def test_delete_categories(staff_api_client, category_list, permission_manage_pr).exists()-@patch(- "saleor.graphql.product.bulk_mutations.products"- ".update_products_minimal_variant_prices_task"-)+@patch("saleor.product.utils.update_products_minimal_variant_prices_task")def test_delete_categories_with_subcategories_and_products(mock_update_products_minimal_variant_prices_task,staff_api_client,diff --git a/tests/api/test_category.py b/tests/api/test_category.pyindex ac98b7a1bc..2e430f17fe 100644--- a/tests/api/test_category.py+++ b/tests/api/test_category.py@@ -1,5 +1,5 @@import json-from unittest.mock import Mock+from unittest.mock import Mock, patchimport grapheneimport pytest@@ -379,7 +379,9 @@ def test_category_delete_mutation(category.refresh_from_db()+@patch("saleor.product.utils.update_products_minimal_variant_prices_task")def test_category_delete_mutation_for_categories_tree(+ mock_update_products_minimal_variant_prices_task,staff_api_client,categories_tree_with_published_products,permission_manage_products,@@ -388,6 +390,8 @@ def test_category_delete_mutation_for_categories_tree(parent_product = parent.products.first()child_product = parent.children.first().products.first()+ product_list = [child_product, parent_product]+variables = {"id": graphene.Node.to_global_id("Category", parent.id)}response = staff_api_client.post_graphql(MUTATION_CATEGORY_DELETE, variables, permissions=[permission_manage_products]@@ -398,13 +402,19 @@ def test_category_delete_mutation_for_categories_tree(with pytest.raises(parent._meta.model.DoesNotExist):parent.refresh_from_db()- for product in [child_product, parent_product]:+ 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.is_publishedassert not product.publication_date+@patch("saleor.product.utils.update_products_minimal_variant_prices_task")def test_category_delete_mutation_for_children_from_categories_tree(+ mock_update_products_minimal_variant_prices_task,staff_api_client,categories_tree_with_published_products,permission_manage_products,@@ -424,6 +434,10 @@ def test_category_delete_mutation_for_children_from_categories_tree(with pytest.raises(child._meta.model.DoesNotExist):child.refresh_from_db()+ mock_update_products_minimal_variant_prices_task.delay.assert_called_once_with(+ product_ids=[child_product.pk]+ )+parent_product.refresh_from_db()assert parent_product.categoryassert parent_product.is_publisheddiff --git a/tests/api/test_product_minimal_variant_price.py b/tests/api/test_product_minimal_variant_price.pyindex 492f344438..22e79068ea 100644--- a/tests/api/test_product_minimal_variant_price.py+++ b/tests/api/test_product_minimal_variant_price.py@@ -262,10 +262,7 @@ def test_product_variant_delete_updates_minimal_variant_price()-@patch(- "saleor.graphql.product.mutations.products"- ".update_products_minimal_variant_prices_task"-)+@patch("saleor.product.utils.update_products_minimal_variant_prices_task")def test_category_delete_updates_minimal_variant_price(mock_update_products_minimal_variant_prices_task,staff_api_client,diff --git a/tests/test_category.py b/tests/test_category.pyindex d8930756bc..ecfc5046e6 100644--- a/tests/test_category.py+++ b/tests/test_category.py@@ -1,4 +1,8 @@+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_categoriesdef test_product_category_filter_filters_from_child_category(@@ -12,3 +16,42 @@ def test_product_category_filter_filters_from_child_category(assert product_attr in attributesassert 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_datediff --git a/tests/test_product_attributes.py b/tests/test_product_attributes.pyindex 6a71fbc86c..2eaaa054c4 100644--- a/tests/test_product_attributes.py+++ b/tests/test_product_attributes.py@@ -9,7 +9,6 @@ from saleor.product.tasks import _update_variants_namesfrom saleor.product.utils.attributes import (associate_attribute_values_to_instance,generate_name_for_variant,- unpublished_products_before_category_delete,)@@ -137,18 +136,3 @@ def test_associate_attribute_to_product_instance_without_values(product):# Ensure the values were cleared and no new assignment entry was createdassert new_assignment.pk == old_assignment.pkassert new_assignment.values.count() == 0---def test_unpublished_products_before_category_delete_for_category_tree(- categories_tree_with_published_products-):- parent = categories_tree_with_published_products- parent_product = parent.products.first()- child_product = parent.children.first().products.first()-- unpublished_products_before_category_delete(parent)-- for product in [child_product, parent_product]:- product.refresh_from_db()- assert not product.is_published- assert not product.publication_date