Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tests
Pacu2131e125a92f7
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex 3fa13736c3..0f5f32ed41 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -74,12 +74,12 @@ class FulfillmentCreate(BaseMutation):elif quantity > order_line.quantity_unfulfilled:msg = npgettext_lazy('Fulfill order line mutation error',- '%(quantity)d item remaining to fulfill.',- '%(quantity)d items remaining to fulfill.',+ 'Only %(quantity)d item remaining to fulfill.',+ 'Only %(quantity)d items remaining to fulfill.','quantity') % {'quantity': order_line.quantity_unfulfilled,'order_line': order_line}- cls.add_error(errors, order_line.variant.name, msg)+ cls.add_error(errors, order_line, msg)return errors@classmethod@@ -103,7 +103,6 @@ class FulfillmentCreate(BaseMutation):fulfillment.save()order_lines = cleaned_input.get('order_lines')quantities = cleaned_input.get('quantities')-fulfillment_lines = []for order_line, quantity in zip(order_lines, quantities):fulfill_order_line(order_line, quantity)diff --git a/saleor/order/__init__.py b/saleor/order/__init__.pyindex cc684df2eb..6239fbec32 100644--- a/saleor/order/__init__.py+++ b/saleor/order/__init__.py@@ -193,6 +193,7 @@ def display_order_event(order_event):'user_name': order_event.user})if event_type == OrderEvents.TRACKING_UPDATED.value:return pgettext_lazy(+ 'Dashboard message related to an order','Fulfillment #%(fulfillment)s tracking was updated to'' %(tracking_number)s by %(user_name)s') % {'fulfillment': params['composed_id'],diff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.pyindex 22971a936c..80d16e65a1 100644--- a/tests/api/test_fulfillment.py+++ b/tests/api/test_fulfillment.py@@ -1,41 +1,44 @@import jsonimport graphene+import pytestfrom django.shortcuts import reverse-from saleor.order import OrderEvents, OrderEventsEmails-from saleor.order.models import FulfillmentStatusfrom tests.utils import get_graphql_content+from saleor.order import OrderEvents, OrderEventsEmails+from saleor.order.models import FulfillmentStatus-def test_create_fulfillment(admin_api_client, order_with_lines, admin_user):- order = order_with_lines- query = """- mutation fulfillOrder(- $order: ID, $lines: [FulfillmentLineInput]!, $tracking: String,- $notify: Boolean+CREATE_FULFILLMENT_QUERY = """+ mutation fulfillOrder(+ $order: ID, $lines: [FulfillmentLineInput]!, $tracking: String,+ $notify: Boolean+ ) {+ orderFulfillmentCreate(+ order: $order,+ input: {+ lines: $lines, trackingNumber: $tracking,+ notifyCustomer: $notify}) {- orderFulfillmentCreate(- order: $order,- input: {- lines: $lines, trackingNumber: $tracking,- notifyCustomer: $notify}- ) {- errors {- field- message- }- fulfillment {- fulfillmentOrder- status- trackingNumber- lines {- totalCount- }+ errors {+ field+ message+ }+ fulfillment {+ fulfillmentOrder+ status+ trackingNumber+ lines {+ totalCount}}}+}+"""- """++def test_create_fulfillment(admin_api_client, order_with_lines, admin_user):+ order = order_with_lines+ query = CREATE_FULFILLMENT_QUERYorder_id = graphene.Node.to_global_id('Order', order.id)order_line = order.lines.first()order_line_id = graphene.Node.to_global_id('OrderLine', order_line.id)@@ -68,6 +71,29 @@ def test_create_fulfillment(admin_api_client, order_with_lines, admin_user):'email_type': OrderEventsEmails.FULFILLMENT.value}+ 'quantity, error_message',+ (+ (0, 'Quantity must be larger than 0.'),+ (100, 'Only 3 items remaining to fulfill.')))+def test_create_fulfillment_not_sufficient_quantity(+ admin_api_client, order_with_lines, admin_user, quantity,+ error_message):+ query = CREATE_FULFILLMENT_QUERY+ order_line = order_with_lines.lines.first()+ order_line_id = graphene.Node.to_global_id('OrderLine', order_line.id)+ variables = json.dumps({+ 'order': graphene.Node.to_global_id('Order', order_with_lines.id),+ 'lines': [{'orderLineId': order_line_id, 'quantity': quantity}]})+ response = admin_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ data = content['data']['orderFulfillmentCreate']+ assert 'errors' in data+ assert data['errors'][0]['field'] == str(order_line)+ assert data['errors'][0]['message'] == error_message++def test_fulfillment_update_tracking(admin_api_client, fulfillment):query = """mutation updateFulfillment($id: ID!, $tracking: String) {