Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test checkout & payments queries
Pacu296d35cf379f5
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex 79e285ff69..38f679152a 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -78,6 +78,7 @@ class Query(ProductQueries):checkout = graphene.Field(Checkout, description='Single checkout.',token=graphene.Argument(graphene.UUID))+ # FIXME we could optimize the below fieldcheckouts = DjangoConnectionField(Checkout,description='List of checkouts.')checkout_lines = PrefetchingConnectionField(@@ -129,8 +130,7 @@ class Query(ProductQueries):payment_client_token = graphene.Field(graphene.String, args={'gateway': PaymentGatewayEnum()})payments = PrefetchingConnectionField(- Payment,- description='List of payments')+ Payment, description='List of payments')sale = graphene.Field(Sale, id=graphene.Argument(graphene.ID, required=True),description='Lookup a sale by ID.')diff --git a/saleor/graphql/payment/resolvers.py b/saleor/graphql/payment/resolvers.pyindex 9b233eca9a..224b28d7be 100644--- a/saleor/graphql/payment/resolvers.py+++ b/saleor/graphql/payment/resolvers.py@@ -6,12 +6,10 @@ PAYMENT_SEARCH_FIELDS = ['id']def resolve_payments(info, query):- # FIXME Add testsqueryset = models.Payment.objects.all().distinct()queryset = filter_by_query_param(queryset, query, PAYMENT_SEARCH_FIELDS)return querysetdef resolve_payment_client_token(gateway=None):- # FIXME Add testsreturn gateway_get_client_token(gateway)diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex efadb4ae85..1c46cc8c27 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -89,7 +89,6 @@ def create_transaction(def gateway_get_client_token(gateway_name: str):- # FIXME Add testsgateway, gateway_params = get_payment_gateway(gateway_name)return gateway.get_client_token(**gateway_params)diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 9e59139de7..f0523bebd0 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -523,3 +523,67 @@ def test_checkout_shipping_method_update(assert checkout.shipping_method == shipping_methodmock_clean_shipping.assert_called_once_with(checkout, shipping_method, [], ANY, ANY, remove=False)+++def test_query_checkout_line(cart_with_item, user_api_client):+ query = """+ query checkoutLine($id: ID) {+ checkoutLine(id: $id) {+ id+ }+ }+ """+ checkout = cart_with_item+ line = checkout.lines.first()+ line_id = graphene.Node.to_global_id('CheckoutLine', line.pk)+ variables = {'id': line_id}+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ received_id = content['data']['checkoutLine']['id']+ assert received_id == line_id+++def test_query_checkouts(+ cart_with_item, staff_api_client, permission_manage_orders):+ query = """+ {+ checkouts {+ edges {+ node {+ token+ }+ }+ }+ }+ """+ checkout = cart_with_item+ response = staff_api_client.post_graphql(+ query, {}, permissions=[permission_manage_orders])+ content = get_graphql_content(response)+ received_checkout = content['data']['checkouts']['edges'][0]['node']+ assert str(checkout.token) == received_checkout['token']+++def test_query_checkout_lines(+ cart_with_item, staff_api_client, permission_manage_orders):+ query = """+ {+ checkoutLines {+ edges {+ node {+ id+ }+ }+ }+ }+ """+ checkout = cart_with_item+ response = staff_api_client.post_graphql(+ query, permissions=[permission_manage_orders])+ content = get_graphql_content(response)+ lines = content['data']['checkoutLines']['edges']+ checkout_lines_ids = [line['node']['id'] for line in lines]+ expected_lines_ids = [+ graphene.Node.to_global_id('CheckoutLine', item.pk)+ for item in checkout]+ assert expected_lines_ids == checkout_lines_idsdiff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex f6306f12ce..695ddac952 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -1,11 +1,14 @@+from unittest.mock import patch+import graphenefrom tests.api.utils import get_graphql_content+from saleor.core.utils import get_country_name_by_code+from saleor.graphql.payment.types import (+ OrderAction, PaymentChargeStatusEnum, PaymentGatewayEnum)from saleor.payment.models import (ChargeStatus, Payment, Transaction, TransactionKind)-from saleor.graphql.payment.types import (- PaymentChargeStatusEnum, PaymentGatewayEnum, OrderAction)-from saleor.core.utils import get_country_name_by_code+VOID_QUERY = """mutation PaymentVoid($paymentId: ID!) {@@ -339,3 +342,62 @@ def test_payments_query('brand': pay.cc_brand,'firstDigits': pay.cc_first_digits,'lastDigits': pay.cc_last_digits}+++def test_query_payment(payment_dummy, user_api_client):+ query = """+ query payment($id: ID) {+ payment(id: $id) {+ id+ }+ }+ """+ payment = payment_dummy+ payment_id = graphene.Node.to_global_id('Payment', payment.pk)+ variables = {'id': payment_id}+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ received_id = content['data']['payment']['id']+ assert received_id == payment_id+++def test_query_payments(+ payment_dummy, permission_manage_orders, staff_api_client):+ query = """+ {+ payments {+ edges {+ node {+ id+ }+ }+ }+ }+ """+ payment = payment_dummy+ payment_id = graphene.Node.to_global_id('Payment', payment.pk)+ response = staff_api_client.post_graphql(+ query, {}, permissions=[permission_manage_orders])+ content = get_graphql_content(response)+ edges = content['data']['payments']['edges']+ payment_ids = [edge['node']['id'] for edge in edges]+ assert payment_ids == [payment_id]+++@patch('saleor.graphql.payment.resolvers.gateway_get_client_token')+def test_query_payment_client_token(mock_get_client_token, user_api_client):+ query = """+ query paymentClientToken($gateway: GatewaysEnum) {+ paymentClientToken(gateway: $gateway)+ }+ """+ example_token = 'example-token'+ mock_get_client_token.return_value = example_token+ variables = {'gateway': PaymentGatewayEnum.BRAINTREE.name}+ response = user_api_client.post_graphql(query, variables)++ content = get_graphql_content(response)+ assert mock_get_client_token.called_once_with(+ PaymentGatewayEnum.BRAINTREE.name)+ token = content['data']['paymentClientToken']+ assert token == example_token