Skip to content

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

Rebase, apply changes and update changelog; split test in two cases

Adam Janikd4a2e1e693aa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0be87657a1..e9e84cfadc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ All notable, unreleased changes to this project will be documented in this file.
## [Unreleased]
- Refactor error handling in mutations #3891 by @maarcingebala @akjanik
- Use only_fields instead of exclude_fields in gql api - #3940 by @michaljelonek
+- Add mutation for bulk delete order lines - #3935 by @akjanik
## 2.5.0
diff --git a/saleor/graphql/order/bulk_mutations/draft_orders.py b/saleor/graphql/order/bulk_mutations/draft_orders.py
index af5f6bfe85..cdb11c40ba 100644
--- a/saleor/graphql/order/bulk_mutations/draft_orders.py
+++ b/saleor/graphql/order/bulk_mutations/draft_orders.py
@@ -38,10 +38,10 @@ class DraftOrderLinesBulkDelete(ModelBulkDeleteMutation):
model = models.OrderLine
@classmethod
- def clean_instance(cls, info, instance, errors):
+ def clean_instance(cls, info, instance):
if instance.order.status != OrderStatus.DRAFT:
- cls.add_error(errors, 'id',
- 'Cannot delete line for non-draft orders.')
+ raise ValidationError(
+ {'id': 'Cannot delete line for non-draft orders.'})
@classmethod
def user_is_allowed(cls, user, input):
diff --git a/tests/api/test_bulk_delete.py b/tests/api/test_bulk_delete.py
index 735319a096..15487104a3 100644
--- a/tests/api/test_bulk_delete.py
+++ b/tests/api/test_bulk_delete.py
@@ -13,6 +13,18 @@ from saleor.shipping.models import ShippingMethod, ShippingZone
from .utils import get_graphql_content
+MUTATION_DELETE_ORDER_LINES = """
+ mutation draftOrderLinesBulkDelete($ids: [ID]!) {
+ draftOrderLinesBulkDelete(ids: $ids) {
+ count
+ errors {
+ field
+ message
+ }
+ }
+ }
+ """
+
@pytest.fixture
def attribute_list():
@@ -286,38 +298,40 @@ def test_delete_draft_orders(
id__in=[order.id for order in orders]).count() == len(orders)
-def test_delete_draft_orders_lines(
+def test_fail_to_delete_non_draft_order_lines(
staff_api_client, order_with_lines, permission_manage_orders):
order = order_with_lines
order_lines = [line for line in order]
+ # Set anything but OrderStatus.DRAFT
order.status = OrderStatus.CANCELED
-
- query = """
- mutation draftOrderLinesBulkDelete($ids: [ID]!) {
- draftOrderLinesBulkDelete(ids: $ids) {
- count
- errors {
- field
- message
- }
- }
- }
- """
+ order.save()
variables = {'ids': [
graphene.Node.to_global_id('OrderLine', order_line.id)
for order_line in order_lines]}
response = staff_api_client.post_graphql(
- query, variables,
+ MUTATION_DELETE_ORDER_LINES, variables,
permissions=[permission_manage_orders])
+
content = get_graphql_content(response)
assert 'errors' in content['data']['draftOrderLinesBulkDelete']
assert content['data']['draftOrderLinesBulkDelete']['count'] == 0
+
+def test_delete_draft_order_lines(
+ staff_api_client, order_with_lines, permission_manage_orders):
+ order = order_with_lines
+ order_lines = [line for line in order]
+ # Only lines in draft order can be deleted
order.status = OrderStatus.DRAFT
order.save()
+
+ variables = {'ids': [
+ graphene.Node.to_global_id('OrderLine', order_line.id)
+ for order_line in order_lines]}
+
response = staff_api_client.post_graphql(
- query, variables, check_no_permissions=False,
+ MUTATION_DELETE_ORDER_LINES, variables,
permissions=[permission_manage_orders])
content = get_graphql_content(response)