Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests, fix bugs
Krzysztof Świątek458b595a9d01
diff --git a/saleor/graphql/core/connection.py b/saleor/graphql/core/connection.pyindex 655573d4e5..f605983c39 100644--- a/saleor/graphql/core/connection.py+++ b/saleor/graphql/core/connection.py@@ -26,7 +26,10 @@ def from_global_cursor(cursor) -> typing.List[str]:values = unbase64(cursor)values = values.split("::")if isinstance(values, list):+ values = [None if value == "None" else value for value in values]return values+ if values == "None":+ values = Nonereturn [values]@@ -36,10 +39,7 @@ def get_field_value(instance: DjangoModel, field_name: str):field_path = field_name.split("__")attr = instancefor elem in field_path:- try:- attr = getattr(attr, elem)- except AttributeError:- return None+ attr = getattr(attr, elem)if callable(attr):return "%s" % attr()@@ -65,11 +65,27 @@ def prepare_filter("""filter_kwargs = Q()for index, field_name in enumerate(sorting_fields):+ if cursor[index] is None and sorting_direction == "gt":+ continue+field_expression = {}for cursor_id, cursor_value in enumerate(cursor[:index]):field_expression[sorting_fields[cursor_id]] = cursor_value- field_expression[f"{field_name}__{sorting_direction}"] = cursor[index]- filter_kwargs |= Q(**field_expression)++ if cursor[index] is not None and sorting_direction == "lt":+ field_expression[f"{field_name}__{sorting_direction}"] = cursor[index]+ filter_kwargs |= Q(**field_expression)+ elif cursor[index] is None and sorting_direction == "lt":+ field_expression[f"{field_name}__isnull"] = False+ filter_kwargs |= Q(**field_expression)+ else:+ extra_expression = Q()+ extra_expression |= Q(+ **{f"{field_name}__{sorting_direction}": cursor[index]}+ )+ extra_expression |= Q(**{f"{field_name}__isnull": True})+ filter_kwargs |= Q(extra_expression, **field_expression)+return filter_kwargs@@ -118,7 +134,6 @@ def connection_from_queryset_slice(sorting_fields = qs.model.sort_by_attribute_fields()elif not sorting_fields:raise ValueError("Error while preparing cursor values.")-requested_count = first or lastend_margin = requested_count + 1 if requested_count else Nonediff --git a/saleor/graphql/core/fields.py b/saleor/graphql/core/fields.pyindex 10a8b27194..bcbe52c4d3 100644--- a/saleor/graphql/core/fields.py+++ b/saleor/graphql/core/fields.py@@ -42,7 +42,6 @@ class BaseConnectionField(graphene.ConnectionField):class BaseDjangoConnectionField(DjangoConnectionField):-@classmethoddef resolve_connection(cls, connection, args, iterable):if isinstance(iterable, list):diff --git a/saleor/graphql/order/sorters.py b/saleor/graphql/order/sorters.pyindex 3d40716a45..28ac1f46c8 100644--- a/saleor/graphql/order/sorters.py+++ b/saleor/graphql/order/sorters.py@@ -1,6 +1,7 @@import graphene-from django.db.models import FilteredRelation, Max, Q, QuerySet+from django.db.models import CharField, ExpressionWrapper, OuterRef, QuerySet, Subquery+from ...payment.models import Paymentfrom ..core.types import SortInputObjectType@@ -8,7 +9,7 @@ class OrderSortField(graphene.Enum):NUMBER = ["pk"]CREATION_DATE = ["created", "status", "pk"]CUSTOMER = ["billing_address__last_name", "billing_address__first_name", "pk"]- PAYMENT = ["last_payment__charge_status", "status", "pk"]+ PAYMENT = ["last_charge_status", "status", "pk"]FULFILLMENT_STATUS = ["status", "user_email", "pk"]TOTAL = ["total_gross_amount", "status", "pk"]@@ -29,15 +30,13 @@ class OrderSortField(graphene.Enum):@staticmethoddef qs_with_payment(queryset: QuerySet) -> QuerySet:- last_payments = (- queryset.exclude(payments__isnull=True)- .annotate(payment_id=Max("payments__pk"))- .values_list("payment_id", flat=True)+ subquery = Subquery(+ Payment.objects.filter(order_id=OuterRef("pk"))+ .order_by("-pk")+ .values_list("charge_status")[:1])return queryset.annotate(- last_payment=FilteredRelation(- "payments", condition=Q(payments__pk__in=last_payments)- )+ last_charge_status=ExpressionWrapper(subquery, output_field=CharField()))diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.pyindex 066704cefe..e2ddae52c8 100644--- a/saleor/graphql/utils.py+++ b/saleor/graphql/utils.py@@ -146,15 +146,14 @@ def sort_queryset(queryset: QuerySet, sort_by: SortInputObjectType) -> QuerySet:raise GraphQLError("You must provide either `field` or `attributeId` to sort the products.")- elif sorting_attribute == "":- return queryset- elif sorting_attribute: # empty string as sorting_attribute is valid- graphene_type, attribute_pk = from_global_id(sorting_attribute)+ elif sorting_attribute is not None: # empty string as sorting_attribute is valid+ if sorting_attribute != "":+ graphene_type, sorting_attribute = from_global_id(sorting_attribute)descending = sorting_direction == OrderDirection.DESC# If the passed attribute ID is valid, execute the sorting- if attribute_pk.isnumeric() and graphene_type == "Attribute":- queryset = queryset.sort_by_attribute(attribute_pk, descending=descending)+ # if attribute_pk.isnumeric() and graphene_type == "Attribute":+ queryset = queryset.sort_by_attribute(sorting_attribute, descending=descending)return querysetsort_enum = sort_by._meta.sort_enumdiff --git a/saleor/product/models.py b/saleor/product/models.pyindex 729dfd8411..fb02917c18 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -5,7 +5,7 @@ from django.conf import settingsfrom django.contrib.postgres.aggregates import StringAggfrom django.contrib.postgres.fields import JSONFieldfrom django.db import models-from django.db.models import Case, Count, F, FilteredRelation, Q, When+from django.db.models import Case, Count, F, FilteredRelation, Q, Value, Whenfrom django.urls import reversefrom django.utils.encoding import smart_textfrom django.utils.html import strip_tags@@ -168,6 +168,14 @@ class ProductsQueryset(PublishedQuerySet)::param descending: The sorting direction."""qs: models.QuerySet = self+ # If the passed attribute ID is valid, execute the sorting+ if not (isinstance(attribute_pk, int) or attribute_pk.isnumeric()):+ return qs.annotate(+ concatenated_values_order=Value(+ None, output_field=models.IntegerField()+ ),+ concatenated_values=Value(None, output_field=models.CharField()),+ )# Retrieve all the products' attribute data IDs (assignments) and# product types that have the given attribute associated to them@@ -178,56 +186,60 @@ class ProductsQueryset(PublishedQuerySet):)if not associated_values:- if descending:- return qs.reverse()- return qs+ qs = qs.annotate(+ concatenated_values_order=Value(+ None, output_field=models.IntegerField()+ ),+ concatenated_values=Value(None, output_field=models.CharField()),+ )- attribute_associations, product_types_associated_to_attribute = zip(- *associated_values- )+ else:+ attribute_associations, product_types_associated_to_attribute = zip(+ *associated_values+ )- qs = qs.annotate(- # Contains to retrieve the attribute data (singular) of each product- # Refer to `AttributeProduct`.- filtered_attribute=FilteredRelation(- relation_name="attributes",- condition=Q(attributes__assignment_id__in=attribute_associations),- ),- # Implicit `GROUP BY` required for the `StringAgg` aggregation- grouped_ids=Count("id"),- # String aggregation of the attribute's values to efficiently sort them- concatenated_values=Case(- # If the product has no association data but has the given attribute- # associated to its product type, then consider the concatenated values- # as empty (non-null).- When(- Q(product_type_id__in=product_types_associated_to_attribute)- & Q(filtered_attribute=None),- then=models.Value(""),+ qs = qs.annotate(+ # Contains to retrieve the attribute data (singular) of each product+ # Refer to `AttributeProduct`.+ filtered_attribute=FilteredRelation(+ relation_name="attributes",+ condition=Q(attributes__assignment_id__in=attribute_associations),),- default=StringAgg(- F("filtered_attribute__values__name"),- delimiter=",",- ordering=(- [- f"filtered_attribute__values__{field_name}"- for field_name in AttributeValue._meta.ordering or []- ]+ # Implicit `GROUP BY` required for the `StringAgg` aggregation+ grouped_ids=Count("id"),+ # String aggregation of the attribute's values to efficiently sort them+ concatenated_values=Case(+ # If the product has no association data but has+ # the given attribute associated to its product type,+ # then consider the concatenated values as empty (non-null).+ When(+ Q(product_type_id__in=product_types_associated_to_attribute)+ & Q(filtered_attribute=None),+ then=models.Value(""),+ ),+ default=StringAgg(+ F("filtered_attribute__values__name"),+ delimiter=",",+ ordering=(+ [+ f"filtered_attribute__values__{field_name}"+ for field_name in AttributeValue._meta.ordering or []+ ]+ ),),+ output_field=models.CharField(),),- output_field=models.CharField(),- ),- concatenated_values_order=Case(- # Make the products having no such attribute be last in the sorting- When(concatenated_values=None, then=2),- # Put the products having an empty attribute value at the bottom of- # the other products.- When(concatenated_values="", then=1),- # Put the products having an attribute value to be always at the top- default=0,- output_field=models.IntegerField(),- ),- )+ concatenated_values_order=Case(+ # Make the products having no such attribute be last in the sorting+ When(concatenated_values=None, then=2),+ # Put the products having an empty attribute value at the bottom of+ # the other products.+ When(concatenated_values="", then=1),+ # Put the products having an attribute value to be always at the top+ default=0,+ output_field=models.IntegerField(),+ ),+ )# Sort by concatenated_values_order then# Sort each group of products (0, 1, 2, ...) per attribute values@@ -337,10 +349,7 @@ class Product(SeoModel, ModelWithMetadata, PublishableModel):@staticmethoddef sort_by_attribute_fields() -> list:- return [- "concatenated_values_order",- "concatenated_values",- "name"]+ return ["concatenated_values_order", "concatenated_values", "name"]class ProductTranslation(SeoModelTranslation):diff --git a/tests/api/test_pagination.py b/tests/api/test_pagination.pyindex 5c63c3a6e5..2122db8ae7 100644--- a/tests/api/test_pagination.py+++ b/tests/api/test_pagination.py@@ -1,19 +1,22 @@-import pytestfrom decimal import Decimal+import pytestfrom django.contrib.auth import models as auth_models-from django.db.models import Count, FilteredRelation, Max, Q+from django.db.models import Countfrom django.utils import timezone-from saleor.graphql.core.connection import to_global_cursor, get_field_value-from saleor.account.models import Address, User, ServiceAccount+from saleor.account.models import Address, ServiceAccount, Userfrom saleor.checkout.models import Checkoutfrom saleor.discount import DiscountValueTypefrom saleor.discount.models import Sale, Voucher+from saleor.graphql.core.connection import get_field_value, to_global_cursor+from saleor.graphql.order.sorters import OrderSortFieldfrom saleor.menu.models import Menu, MenuItemfrom saleor.order import OrderStatusfrom saleor.order.models import Orderfrom saleor.page.models import Page+from saleor.payment import ChargeStatus+from saleor.payment.models import Paymentfrom tests.api.utils import get_graphql_content@@ -189,18 +192,9 @@ def voucher_for_pagination():def menus_for_pagination():Menu.objects.bulk_create([- Menu(- name="The menu",- json_content={},- ),- Menu(- name="The example menu",- json_content={},- ),- Menu(- name="Just menu",- json_content={},- ),+ Menu(name="The menu", json_content={},),+ Menu(name="The example menu", json_content={},),+ Menu(name="Just menu", json_content={},),])menu1 = Menu.objects.filter(name="The menu").first()@@ -270,42 +264,167 @@ def orders_for_pagination(customer_user):phone="+48713988102",)- Order.objects.bulk_create(+ order1 = Order.objects.create(+ user=customer_user,+ status=OrderStatus.FULFILLED,+ token="order_token_1",+ total_gross_amount=Decimal("10"),+ billing_address=address1,+ )+ order2 = Order.objects.create(+ user=customer_user,+ status=OrderStatus.FULFILLED,+ token="order_token_2",+ total_gross_amount=Decimal("20"),+ billing_address=address2,+ )+ order3 = Order.objects.create(+ user=customer_user,+ status=OrderStatus.FULFILLED,+ token="order_token_3",+ total_gross_amount=Decimal("10"),+ billing_address=address3,+ )+ order4 = Order.objects.create(+ user=customer_user,+ status=OrderStatus.FULFILLED,+ token="order_token_4",+ total_gross_amount=Decimal("20"),+ billing_address=address4,+ )+ order5 = Order.objects.create(+ user=customer_user,+ status=OrderStatus.FULFILLED,+ token="order_token_5",+ total_gross_amount=Decimal("50"),+ billing_address=address5,+ )++ Payment.objects.bulk_create([- Order(- user=customer_user,- status=OrderStatus.FULFILLED,- token="order_token_1",- total_gross_amount=Decimal("10"),- billing_address=address1+ Payment(+ gateway="Dummy",+ token="payment1",+ order=order1,+ is_active=True,+ cc_first_digits="4111",+ cc_last_digits="1111",+ cc_brand="VISA",+ cc_exp_month=12,+ cc_exp_year=2027,+ total=order1.total.gross.amount,+ currency=order1.total.gross.currency,+ charge_status=ChargeStatus.NOT_CHARGED,+ to_confirm=True,+ billing_first_name=order1.billing_address.first_name,+ billing_last_name=order1.billing_address.last_name,+ billing_company_name=order1.billing_address.company_name,+ billing_address_1=order1.billing_address.street_address_1,+ billing_address_2=order1.billing_address.street_address_2,+ billing_city=order1.billing_address.city,+ billing_postal_code=order1.billing_address.postal_code,+ billing_country_code=order1.billing_address.country.code,+ billing_country_area=order1.billing_address.country_area,+ billing_email=order1.user_email,),- Order(- user=customer_user,- status=OrderStatus.FULFILLED,- token="order_token_2",- total_gross_amount=Decimal("20"),- billing_address=address2+ Payment(+ gateway="Dummy",+ token="payment2",+ order=order1,+ is_active=True,+ cc_first_digits="4111",+ cc_last_digits="1111",+ cc_brand="VISA",+ cc_exp_month=12,+ cc_exp_year=2027,+ total=order1.total.gross.amount,+ currency=order1.total.gross.currency,+ charge_status=ChargeStatus.NOT_CHARGED,+ to_confirm=True,+ billing_first_name=order1.billing_address.first_name,+ billing_last_name=order1.billing_address.last_name,+ billing_company_name=order1.billing_address.company_name,+ billing_address_1=order1.billing_address.street_address_1,+ billing_address_2=order1.billing_address.street_address_2,+ billing_city=order1.billing_address.city,+ billing_postal_code=order1.billing_address.postal_code,+ billing_country_code=order1.billing_address.country.code,+ billing_country_area=order1.billing_address.country_area,+ billing_email=order1.user_email,),- Order(- user=customer_user,- status=OrderStatus.FULFILLED,- token="order_token_3",- total_gross_amount=Decimal("10"),- billing_address=address3+ Payment(+ gateway="Dummy",+ token="payment3",+ order=order3,+ is_active=True,+ cc_first_digits="4111",+ cc_last_digits="1111",+ cc_brand="VISA",+ cc_exp_month=12,+ cc_exp_year=2027,+ total=order3.total.gross.amount,+ currency=order3.total.gross.currency,+ charge_status=ChargeStatus.FULLY_CHARGED,+ captured_amount=order5.total.gross.amount,+ billing_first_name=order3.billing_address.first_name,+ billing_last_name=order3.billing_address.last_name,+ billing_company_name=order3.billing_address.company_name,+ billing_address_1=order3.billing_address.street_address_1,+ billing_address_2=order3.billing_address.street_address_2,+ billing_city=order3.billing_address.city,+ billing_postal_code=order3.billing_address.postal_code,+ billing_country_code=order3.billing_address.country.code,+ billing_country_area=order3.billing_address.country_area,+ billing_email=order3.user_email,),- Order(- user=customer_user,- status=OrderStatus.FULFILLED,- token="order_token_4",- total_gross_amount=Decimal("20"),- billing_address=address4+ Payment(+ gateway="Dummy",+ token="payment4",+ order=order4,+ is_active=True,+ cc_first_digits="4111",+ cc_last_digits="1111",+ cc_brand="VISA",+ cc_exp_month=12,+ cc_exp_year=2027,+ total=order4.total.gross.amount,+ currency=order4.total.gross.currency,+ charge_status=ChargeStatus.NOT_CHARGED,+ billing_first_name=order4.billing_address.first_name,+ billing_last_name=order4.billing_address.last_name,+ billing_company_name=order4.billing_address.company_name,+ billing_address_1=order4.billing_address.street_address_1,+ billing_address_2=order4.billing_address.street_address_2,+ billing_city=order4.billing_address.city,+ billing_postal_code=order4.billing_address.postal_code,+ billing_country_code=order4.billing_address.country.code,+ billing_country_area=order4.billing_address.country_area,+ billing_email=order4.user_email,),- Order(- user=customer_user,- status=OrderStatus.FULFILLED,- token="order_token_5",- total_gross_amount=Decimal("50"),- billing_address=address5+ Payment(+ gateway="Dummy",+ token="payment5",+ order=order4,+ is_active=True,+ cc_first_digits="4111",+ cc_last_digits="1111",+ cc_brand="VISA",+ cc_exp_month=12,+ cc_exp_year=2027,+ total=order4.total.gross.amount,+ currency=order4.total.gross.currency,+ charge_status=ChargeStatus.FULLY_CHARGED,+ captured_amount=order4.total.gross.amount,+ billing_first_name=order4.billing_address.first_name,+ billing_last_name=order4.billing_address.last_name,+ billing_company_name=order4.billing_address.company_name,+ billing_address_1=order4.billing_address.street_address_1,+ billing_address_2=order4.billing_address.street_address_2,+ billing_city=order4.billing_address.city,+ billing_postal_code=order4.billing_address.postal_code,+ billing_country_code=order4.billing_address.country.code,+ billing_country_area=order4.billing_address.country_area,+ billing_email=order4.user_email,),])@@ -315,31 +434,11 @@ def orders_for_pagination(customer_user):def pages_for_pagination():Page.objects.bulk_create([- Page(- name="About",- slug="about",- is_published=False- ),- Page(- name="Abou2",- slug="about",- is_published=False- ),- Page(- name="About3",- slug="about",- is_published=False- ),- Page(- name="Page1",- slug="slug_page_1",- is_published=True- ),- Page(- name="Page2",- slug="slug_page_2",- is_published=True- ),+ Page(title="About", slug="about", is_published=False),+ Page(title="About", slug="about2", is_published=False),+ Page(title="About3", slug="about3", is_published=False),+ Page(title="Page1", slug="slug_page_1", is_published=True),+ Page(title="Page2", slug="slug_page_2", is_published=True),])@@ -383,22 +482,15 @@ def create_cursor_from_voucher_code(code, fields_list):def create_cursor_from_menu_name(name, fields_list):- menu = Menu.objects.filter(name=name).annotate(items_count=Count("items__id")).first()+ menu = (+ Menu.objects.filter(name=name).annotate(items_count=Count("items__id")).first()+ )return create_global_cursor(menu, fields_list)def create_cursor_from_order_token(token, fields_list):order_qs = Order.objects.filter(token=token)- last_payments = (- order_qs.exclude(payments__isnull=True)- .annotate(payment_id=Max("payments__pk"))- .values_list("payment_id", flat=True)- )- order = order_qs.annotate(- last_payment=FilteredRelation(- "payments", condition=Q(payments__pk__in=last_payments)- )- ).first()+ order = OrderSortField.qs_with_payment(order_qs).first()return create_global_cursor(order, fields_list)@@ -407,6 +499,11 @@ def create_cursor_from_page_slug(slug, fields_list):return create_global_cursor(page, fields_list)+def create_cursor_from_payment_token(token, fields_list):+ payment = Payment.objects.get(token=token)+ return create_global_cursor(payment, fields_list)++def _test_pagination(staff_api_client,query,@@ -863,90 +960,42 @@ def test_sales_pagination((None,["code"],- [- "An-example-v",- "Example-code",- "The-code",- "Voucher-ex",- "code",- ],+ ["An-example-v", "Example-code", "The-code", "Voucher-ex", "code",],),({"field": "CODE", "direction": "ASC"},["code"],- [- "An-example-v",- "Example-code",- "The-code",- "Voucher-ex",- "code",- ],+ ["An-example-v", "Example-code", "The-code", "Voucher-ex", "code",],),({"field": "START_DATE", "direction": "ASC"},["start_date", "name", "code"],- [- "code",- "The-code",- "Example-code",- "Voucher-ex",- "An-example-v",- ],+ ["code", "The-code", "Example-code", "Voucher-ex", "An-example-v",],),({"field": "END_DATE", "direction": "ASC"},["end_date", "name", "code"],- [- "The-code",- "Voucher-ex",- "Example-code",- "code",- "An-example-v",- ],+ ["The-code", "Voucher-ex", "Example-code", "code", "An-example-v",],),({"field": "VALUE", "direction": "ASC"},["discount_value", "name", "code"],- [- "code",- "An-example-v",- "Example-code",- "Voucher-ex",- "The-code",- ],+ ["code", "An-example-v", "Example-code", "Voucher-ex", "The-code",],),({"field": "TYPE", "direction": "ASC"},["type", "name", "code"],- [- "An-example-v",- "The-code",- "Voucher-ex",- "Example-code",- "code",- ],+ ["An-example-v", "The-code", "Voucher-ex", "Example-code", "code",],),({"field": "USAGE_LIMIT", "direction": "ASC"},["usage_limit", "name", "code"],- [- "An-example-v",- "code",- "Example-code",- "Voucher-ex",- "The-code",- ],+ ["An-example-v", "code", "Example-code", "Voucher-ex", "The-code",],),({"field": "MINIMUM_SPENT_AMOUNT", "direction": "ASC"},["min_spent_amount", "name", "code"],- [- "The-code",- "code",- "Voucher-ex",- "An-example-v",- "Example-code",- ],+ ["The-code", "code", "Voucher-ex", "An-example-v", "Example-code",],),],)@@ -975,9 +1024,13 @@ def test_voucher_pagination(}}"""- start_cursor_page1 = create_cursor_from_voucher_code(voucher_order[0], cursor_fields)+ start_cursor_page1 = create_cursor_from_voucher_code(+ voucher_order[0], cursor_fields+ )end_cursor_page1 = create_cursor_from_voucher_code(voucher_order[2], cursor_fields)- start_cursor_page2 = create_cursor_from_voucher_code(voucher_order[3], cursor_fields)+ start_cursor_page2 = create_cursor_from_voucher_code(+ voucher_order[3], cursor_fields+ )end_cursor_page2 = create_cursor_from_voucher_code(voucher_order[4], cursor_fields)_test_pagination(@@ -1000,35 +1053,17 @@ def test_voucher_pagination((None,["pk"],- [- "navbar",- "footer",- "The menu",- "The example menu",- "Just menu",- ],+ ["navbar", "footer", "The menu", "The example menu", "Just menu",],),({"field": "NAME", "direction": "ASC"},["name", "pk"],- [- "Just menu",- "The example menu",- "The menu",- "footer",- "navbar",- ],+ ["Just menu", "The example menu", "The menu", "footer", "navbar",],),({"field": "ITEMS_COUNT", "direction": "ASC"},["items_count", "name", "pk"],- [- "footer",- "navbar",- "The menu",- "The example menu",- "Just menu",- ],+ ["footer", "navbar", "The menu", "The example menu", "Just menu",],),],)@@ -1038,7 +1073,7 @@ def test_menus_pagination(menus_order,staff_api_client,permission_manage_plugins,- menus_for_pagination+ menus_for_pagination,):query = """query ($first: Int, $last: Int, $after: String, $before: String, $sortBy: MenuSortingInput){@@ -1124,12 +1159,12 @@ def test_menus_pagination(),({"field": "PAYMENT", "direction": "ASC"},- ["last_payment__charge_status", "status", "pk"],+ OrderSortField.PAYMENT.value,[- "order_token_1",- "order_token_2","order_token_3","order_token_4",+ "order_token_1",+ "order_token_2","order_token_5",],),@@ -1163,7 +1198,7 @@ def test_orders_pagination(orders_order,staff_api_client,permission_manage_orders,- orders_for_pagination+ orders_for_pagination,):query = """query ($first: Int, $last: Int, $after: String, $before: String, $sortBy: OrderSortingInput){@@ -1206,29 +1241,18 @@ def test_orders_pagination(({"field": "VISIBILITY", "direction": "ASC"},["is_published", "title", "slug"],- [- "about",- "about2",- "about3",- "slug_page_1",- "slug_page_2",- ]+ ["about", "about2", "about3", "slug_page_1", "slug_page_2",],),- (- None,- ["slug"],- [- "about",- "about2",- "about3",- "slug_page_1",- "slug_page_2",- ]- ),+ (None, ["slug"], ["about", "about2", "about3", "slug_page_1", "slug_page_2",]),],)def test_page_pagination(- order_by, cursor_fields, page_order, staff_api_client, permission_manage_pages, pages_for_pagination+ order_by,+ cursor_fields,+ page_order,+ staff_api_client,+ permission_manage_pages,+ pages_for_pagination,):query = """query ($after: String, $sortBy: PageSortingInput){@@ -1236,6 +1260,7 @@ def test_page_pagination(edges {node {title+ slug}}pageInfo{@@ -1248,10 +1273,10 @@ def test_page_pagination(}"""- start_cursor_page1 = create_cursor_from_order_token(page_order[0], cursor_fields)- end_cursor_page1 = create_cursor_from_order_token(page_order[2], cursor_fields)- start_cursor_page2 = create_cursor_from_order_token(page_order[3], cursor_fields)- end_cursor_page2 = create_cursor_from_order_token(page_order[4], cursor_fields)+ start_cursor_page1 = create_cursor_from_page_slug(page_order[0], cursor_fields)+ end_cursor_page1 = create_cursor_from_page_slug(page_order[2], cursor_fields)+ start_cursor_page2 = create_cursor_from_page_slug(page_order[3], cursor_fields)+ end_cursor_page2 = create_cursor_from_page_slug(page_order[4], cursor_fields)_test_pagination(staff_api_client,query,@@ -1263,3 +1288,53 @@ def test_page_pagination(end_cursor_page2,resolver_name="pages",)+++ "cursor_fields, payment_order",+ [(["pk"], ["payment1", "payment2", "payment3", "payment4", "payment5",]),],+)+def test_payment_pagination(+ cursor_fields,+ payment_order,+ staff_api_client,+ permission_manage_orders,+ orders_for_pagination,+):+ query = """+ query ($after: String){+ payments(first: 3, after: $after) {+ edges {+ node {+ token+ }+ }+ pageInfo{+ startCursor+ endCursor+ hasNextPage+ hasPreviousPage+ }+ }+ }+ """++ start_cursor_page1 = create_cursor_from_payment_token(+ payment_order[0], cursor_fields+ )+ end_cursor_page1 = create_cursor_from_payment_token(payment_order[2], cursor_fields)+ start_cursor_page2 = create_cursor_from_payment_token(+ payment_order[3], cursor_fields+ )+ end_cursor_page2 = create_cursor_from_payment_token(payment_order[4], cursor_fields)+ _test_pagination(+ staff_api_client,+ query,+ None,+ permission_manage_orders,+ start_cursor_page1,+ end_cursor_page1,+ start_cursor_page2,+ end_cursor_page2,+ resolver_name="payments",+ )