Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add benchmark test for Payment transactions (#9902)
Krzysztof Kwaśniakab62a427d64e
diff --git a/saleor/graphql/order/tests/benchmark/fixtures.py b/saleor/graphql/order/tests/benchmark/fixtures.pyindex eac7377387..f7dbaffbeb 100644--- a/saleor/graphql/order/tests/benchmark/fixtures.py+++ b/saleor/graphql/order/tests/benchmark/fixtures.py@@ -8,11 +8,26 @@ from .....account.models import Userfrom .....order import OrderEvents, OrderStatusfrom .....order.models import Fulfillment, FulfillmentLine, Order, OrderEvent, OrderLinefrom .....payment import ChargeStatus-from .....payment.models import Payment+from .....payment.models import Payment, TransactionORDER_COUNT_IN_BENCHMARKS = 10EVENTS_PER_ORDER = 5LINES_PER_ORDER = 3+TRANSACTIONS_PER_PAYMENT = 3+++def _prepare_payment_transactions(payments):+ transactions = []++ for payment in payments:+ transactions.extend(+ [+ Transaction(payment=payment, gateway_response=str(index))+ for index in range(TRANSACTIONS_PER_PAYMENT)+ ]+ )++ return transactionsdef _prepare_payments_for_order(order):@@ -49,7 +64,8 @@ def _prepare_events_for_order(order):def _prepare_lines_for_order(order, variant_with_image):price = TaxedMoney(- net=Money(amount=5, currency="USD"), gross=Money(amount=5, currency="USD")+ net=Money(amount=5, currency="USD"),+ gross=Money(amount=5, currency="USD"),)return [OrderLine(@@ -109,12 +125,15 @@ def orders_for_benchmarks(fulfillments = []fulfillment_lines = []lines = []+ transactions = []for index, order in enumerate(created_orders):new_payments = _prepare_payments_for_order(order)+ new_transactions = _prepare_payment_transactions(new_payments)new_events = _prepare_events_for_order(order)new_lines = _prepare_lines_for_order(order, variant_with_image)payments.extend(new_payments)+ transactions.extend(new_transactions)events.extend(new_events)lines.extend(new_lines)fulfillment = Fulfillment(order=order, fulfillment_order=order.number)@@ -130,6 +149,7 @@ def orders_for_benchmarks()Payment.objects.bulk_create(payments)+ Transaction.objects.bulk_create(transactions)OrderEvent.objects.bulk_create(events)Fulfillment.objects.bulk_create(fulfillments)OrderLine.objects.bulk_create(lines)diff --git a/saleor/graphql/payment/tests/benchmark/__init__.py b/saleor/graphql/payment/tests/benchmark/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/graphql/payment/tests/benchmark/test_payment_transactions.py b/saleor/graphql/payment/tests/benchmark/test_payment_transactions.pynew file mode 100644index 0000000000..a8e714da3f--- /dev/null+++ b/saleor/graphql/payment/tests/benchmark/test_payment_transactions.py@@ -0,0 +1,71 @@+import pytest++from .....payment.models import Transaction+from ....tests.utils import get_graphql_content++PAYMENT_TRANSACTIONS_QUERY = """+query {+ orders(first:100) {+ edges {+ node {+ payments {+ id+ gateway+ isActive+ created+ modified+ token+ checkout {+ id+ }+ order {+ id+ }+ customerIpAddress+ actions+ total {+ amount+ }+ capturedAmount {+ amount+ }+ transactions {+ id+ }+ availableRefundAmount {+ amount+ }+ availableCaptureAmount {+ amount+ }+ creditCard {+ brand+ }+ }+ }+ }+ }+}+"""++[email protected]_queries(autouse=False)+def test_payment_transactions(+ staff_api_client, orders_for_benchmarks, permission_manage_orders, count_queries+):+ transactions_count = 0+ content = get_graphql_content(+ staff_api_client.post_graphql(+ PAYMENT_TRANSACTIONS_QUERY,+ permissions=[permission_manage_orders],+ check_no_permissions=False,+ )+ )++ edges = content["data"]["orders"]["edges"]+ for edge in edges:+ for payment in edge["node"]["payments"]:+ transactions_count += len(payment["transactions"])++ assert transactions_count == Transaction.objects.count() > 1