Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tests for adding note to order and updating order
Adam Janikf3220c0a2180
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex 5ab7d2f503..43ff1a1e08 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -57,14 +57,6 @@ class DraftOrderInput(InputObjectType):description='ID of the voucher associated with the order')-class OrderUpdateInput(graphene.InputObjectType):- billing_address = AddressInput(- description='Address associated with the payment.')- user_email = graphene.String(description='Email address of the customer.')- shipping_address = AddressInput(- description='Address to where the order will be shipped.')--def check_lines_quantity(variants, quantities):"""Check if stock is sufficient for each line in the list of dicts.diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 4de52aa170..9455a0ca67 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -5,13 +5,14 @@ from payments import PaymentError, PaymentStatusfrom saleor.graphql.core.mutations import BaseMutation, ModelMutationfrom saleor.graphql.core.types import Decimal, Error-from saleor.graphql.order.mutations.draft_orders import (- DraftOrderUpdate, OrderUpdateInput)+from saleor.graphql.order.mutations.draft_orders import DraftOrderUpdatefrom saleor.graphql.order.types import Orderfrom saleor.graphql.utils import get_nodefrom saleor.order import CustomPaymentChoices, modelsfrom saleor.order.utils import cancel_order+from .draft_orders import AddressInput+def try_payment_action(action, money, errors):try:@@ -20,6 +21,14 @@ def try_payment_action(action, money, errors):errors.append(Error(field='payment', message=str(e)))+class OrderUpdateInput(graphene.InputObjectType):+ billing_address = AddressInput(+ description='Address associated with the payment.')+ user_email = graphene.String(description='Email address of the customer.')+ shipping_address = AddressInput(+ description='Address to where the order will be shipped.')++class OrderUpdate(DraftOrderUpdate):class Arguments:id = graphene.ID(@@ -37,7 +46,7 @@ class OrderAddNoteInput(graphene.InputObjectType):order = graphene.ID(description='ID of the order.')user = graphene.ID(description='ID of the user who added note.')content = graphene.String(description='Note content.')- is_public = graphene.String(+ is_public = graphene.Boolean(description='Determine if note is visible by customer or not.')@@ -57,7 +66,7 @@ class OrderAddNote(ModelMutation):@classmethoddef save(cls, info, instance, cleaned_input):- super.save(info, instance, cleaned_input)+ super().save(info, instance, cleaned_input)msg = 'Added note'instance.order.history.create(content=msg, user=info.context.user)diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex cdc15b4024..ec463ef8b2 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -251,3 +251,81 @@ def test_draft_order_complete(admin_api_client, draft_order):data = content['data']['draftOrderComplete']['order']order.refresh_from_db()assert data['status'] == order.status.upper()+++def test_order_update(admin_api_client, order_with_lines):+ order = order_with_lines+ query = """+ mutation orderUpdate(+ $id: ID!, $email: String, $first_name: String, $last_name: String,+ $country_code: String) {+ orderUpdate(+ id: $id, input: {+ userEmail: $email, shippingAddress:+ {firstName: $first_name, country: $country_code},+ billingAddress:+ {lastName: $last_name, country: $country_code}}) {+ errors {+ field+ message+ }+ order {+ userEmail+ }+ }+ }+ """+ email = '[email protected]'+ first_name = 'Test fname'+ last_name = 'Test lname'+ assert not order.user_email == email+ assert not order.shipping_address.first_name == first_name+ assert not order.billing_address.last_name == last_name+ order_id = graphene.Node.to_global_id('Order', order.id)+ variables = json.dumps(+ {'id': order_id, 'email': email, 'first_name': first_name,+ 'last_name': last_name, 'country_code': 'PL'})+ response = admin_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ data = content['data']['orderUpdate']['order']+ assert data['userEmail'] == email++ order.refresh_from_db()+ assert order.shipping_address.first_name == first_name+ assert order.billing_address.last_name == last_name+++def test_order_add_note(admin_api_client, order_with_lines, admin_user):+ order = order_with_lines+ query = """+ mutation addNote(+ $id: ID!, $note: String, $user: ID, $is_public: Boolean) {+ orderAddNote(+ input: {order: $id, content: $note, user: $user,+ isPublic: $is_public}) {+ orderNote {+ content+ isPublic+ user {+ }+ }+ }+ }+ """+ assert not order.notes.all()+ order_id = graphene.Node.to_global_id('Order', order.id)+ note = 'nuclear note'+ user = graphene.Node.to_global_id('User', admin_user.id)+ is_public = True+ variables = json.dumps(+ {'id': order_id, 'user': user, 'is_public': is_public,+ 'note': note})+ response = admin_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ data = content['data']['orderAddNote']['orderNote']+ assert data['content'] == note+ assert data['isPublic'] == is_public+ assert data['user']['email'] == admin_user.email