Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Upgrade order pagination tests
Michał Sipa5dfa18c54416
diff --git a/tests/api/pagination/test_order.py b/tests/api/pagination/test_order.pyindex 51d3e271b4..33d8c3ecff 100644--- a/tests/api/pagination/test_order.py+++ b/tests/api/pagination/test_order.py@@ -10,6 +10,54 @@ from saleor.payment import ChargeStatusfrom ..utils import get_graphql_content+from prices import TaxedMoney, Money+++def orders_for_pagination(db):+ orders = Order.objects.bulk_create(+ [+ Order(+ token=str(uuid.uuid4()),+ total=TaxedMoney(net=Money(1, "USD"), gross=Money(1, "USD")),+ ),+ Order(+ token=str(uuid.uuid4()),+ total=TaxedMoney(net=Money(2, "USD"), gross=Money(2, "USD")),+ ),+ Order(+ token=str(uuid.uuid4()),+ total=TaxedMoney(net=Money(3, "USD"), gross=Money(3, "USD")),+ ),+ ]+ )+ return orders+++def draft_orders_for_pagination(db):+ orders = Order.objects.bulk_create(+ [+ Order(+ token=str(uuid.uuid4()),+ total=TaxedMoney(net=Money(1, "USD"), gross=Money(1, "USD")),+ status=OrderStatus.DRAFT,+ ),+ Order(+ token=str(uuid.uuid4()),+ total=TaxedMoney(net=Money(2, "USD"), gross=Money(2, "USD")),+ status=OrderStatus.DRAFT,+ ),+ Order(+ token=str(uuid.uuid4()),+ total=TaxedMoney(net=Money(3, "USD"), gross=Money(3, "USD")),+ status=OrderStatus.DRAFT,+ ),+ ]+ )+ return orders++QUERY_ORDERS_WITH_PAGINATION = """query ($first: Int, $last: Int, $after: String, $before: String,@@ -55,6 +103,12 @@ QUERY_DRAFT_ORDERS_WITH_PAGINATION = """node {idnumber+ total{+ gross{+ amount+ }+ }+ created}}pageInfo{@@ -69,7 +123,7 @@ QUERY_DRAFT_ORDERS_WITH_PAGINATION = """@pytest.mark.parametrize(- "orders_filter, count",+ "orders_filter, orders_order, expected_total_count",[({@@ -78,18 +132,23 @@ QUERY_DRAFT_ORDERS_WITH_PAGINATION = """"lte": str(date.today()),}},- 1,+ [3.0, 2.0],+ 3,),- ({"created": {"gte": str(date.today() - timedelta(days=3))}}, 1),- ({"created": {"lte": str(date.today())}}, 2),- ({"created": {"lte": str(date.today() - timedelta(days=3))}}, 1),- ({"created": {"gte": str(date.today() + timedelta(days=1))}}, 0),+ ({"created": {"gte": str(date.today() - timedelta(days=3))}}, [3.0, 2.0], 3),+ ({"created": {"lte": str(date.today())}}, [0.0, 3.0], 4),+ ({"created": {"lte": str(date.today() - timedelta(days=3))}}, [0.0], 1),+ ({"created": {"gte": str(date.today() + timedelta(days=1))}}, [], 0),],)def test_order_query_pagination_with_filter_created(- orders_filter, count, staff_api_client, permission_manage_orders,+ orders_filter,+ orders_order,+ expected_total_count,+ staff_api_client,+ permission_manage_orders,+ orders_for_pagination,):- Order.objects.create()with freeze_time("2012-01-14"):Order.objects.create()page_size = 2@@ -97,83 +156,108 @@ def test_order_query_pagination_with_filter_created(staff_api_client.user.user_permissions.add(permission_manage_orders)response = staff_api_client.post_graphql(QUERY_ORDERS_WITH_PAGINATION, variables)content = get_graphql_content(response)+orders = content["data"]["orders"]["edges"]+ total_count = content["data"]["orders"]["totalCount"]++ for i in range(total_count if total_count < page_size else page_size):+ assert orders[i]["node"]["total"]["gross"]["amount"] == orders_order[i]- assert len(orders) == count+ assert expected_total_count == total_count@pytest.mark.parametrize(- "orders_filter, count, payment_status",+ "orders_filter, expected_total_count, payment_status, orders_order",[- ({"paymentStatus": "FULLY_CHARGED"}, 1, ChargeStatus.FULLY_CHARGED),- ({"paymentStatus": "NOT_CHARGED"}, 2, ChargeStatus.NOT_CHARGED),- ({"paymentStatus": "PARTIALLY_CHARGED"}, 1, ChargeStatus.PARTIALLY_CHARGED),- ({"paymentStatus": "PARTIALLY_REFUNDED"}, 1, ChargeStatus.PARTIALLY_REFUNDED),- ({"paymentStatus": "FULLY_REFUNDED"}, 1, ChargeStatus.FULLY_REFUNDED),- ({"paymentStatus": "FULLY_CHARGED"}, 0, ChargeStatus.FULLY_REFUNDED),- ({"paymentStatus": "NOT_CHARGED"}, 1, ChargeStatus.FULLY_REFUNDED),+ ({"paymentStatus": "FULLY_CHARGED"}, 1, ChargeStatus.FULLY_CHARGED, [98.4]),+ ({"paymentStatus": "NOT_CHARGED"}, 4, ChargeStatus.NOT_CHARGED, [3.0, 2.0]),+ (+ {"paymentStatus": "PARTIALLY_CHARGED"},+ 1,+ ChargeStatus.PARTIALLY_CHARGED,+ [98.4],+ ),+ (+ {"paymentStatus": "PARTIALLY_REFUNDED"},+ 1,+ ChargeStatus.PARTIALLY_REFUNDED,+ [98.4],+ ),+ ({"paymentStatus": "FULLY_REFUNDED"}, 1, ChargeStatus.FULLY_REFUNDED, [98.4]),+ ({"paymentStatus": "FULLY_CHARGED"}, 0, ChargeStatus.FULLY_REFUNDED, []),+ ({"paymentStatus": "NOT_CHARGED"}, 3, ChargeStatus.FULLY_REFUNDED, [3.0, 2.0]),],)def test_order_query_pagination_with_filter_payment_status(orders_filter,- count,+ expected_total_count,payment_status,+ orders_order,staff_api_client,payment_dummy,permission_manage_orders,+ orders_for_pagination,):payment_dummy.charge_status = payment_statuspayment_dummy.save()- payment_dummy.id = None- payment_dummy.order = Order.objects.create()- payment_dummy.charge_status = ChargeStatus.NOT_CHARGED- payment_dummy.save()+ for order in orders_for_pagination:+ payment_dummy.id = None+ payment_dummy.order = order+ payment_dummy.charge_status = ChargeStatus.NOT_CHARGED+ payment_dummy.save()page_size = 2variables = {"first": page_size, "after": None, "filter": orders_filter}staff_api_client.user.user_permissions.add(permission_manage_orders)response = staff_api_client.post_graphql(QUERY_ORDERS_WITH_PAGINATION, variables)content = get_graphql_content(response)+orders = content["data"]["orders"]["edges"]+ total_count = content["data"]["orders"]["totalCount"]+ assert total_count == expected_total_count- assert len(orders) == count+ for i in range(total_count if total_count < page_size else page_size):+ assert orders[i]["node"]["total"]["gross"]["amount"] == orders_order[i]@pytest.mark.parametrize(- "orders_filter, count, status",+ "orders_filter, expected_total_count, status, orders_order",[- ({"status": "UNFULFILLED"}, 2, OrderStatus.UNFULFILLED),- ({"status": "PARTIALLY_FULFILLED"}, 1, OrderStatus.PARTIALLY_FULFILLED),- ({"status": "FULFILLED"}, 1, OrderStatus.FULFILLED),- ({"status": "CANCELED"}, 1, OrderStatus.CANCELED),+ ({"status": "UNFULFILLED"}, 4, OrderStatus.UNFULFILLED, [3.0, 2.0]),+ ({"status": "PARTIALLY_FULFILLED"}, 1, OrderStatus.PARTIALLY_FULFILLED, [0.0]),+ ({"status": "FULFILLED"}, 1, OrderStatus.FULFILLED, [0.0]),+ ({"status": "CANCELED"}, 1, OrderStatus.CANCELED, [0.0]),],)def test_order_query_pagination_with_filter_status(orders_filter,- count,+ expected_total_count,status,+ orders_order,staff_api_client,- payment_dummy,permission_manage_orders,order,+ orders_for_pagination,):order.status = statusorder.save()- Order.objects.create()-page_size = 2variables = {"first": page_size, "after": None, "filter": orders_filter}staff_api_client.user.user_permissions.add(permission_manage_orders)response = staff_api_client.post_graphql(QUERY_ORDERS_WITH_PAGINATION, variables)content = get_graphql_content(response)+orders = content["data"]["orders"]["edges"]order_id = graphene.Node.to_global_id("Order", order.pk)- orders_ids_from_response = [o["node"]["id"] for o in orders]- assert len(orders) == count- assert order_id in orders_ids_from_response+ orders = content["data"]["orders"]["edges"]+ total_count = content["data"]["orders"]["totalCount"]+ assert total_count == expected_total_count++ for i in range(total_count if total_count < page_size else page_size):+ assert orders[i]["node"]["total"]["gross"]["amount"] == orders_order[i]@pytest.mark.parametrize(@@ -191,13 +275,13 @@ def test_order_query_pagination_with_filter_customer_fields(staff_api_client,permission_manage_orders,customer_user,+ orders_for_pagination,):setattr(customer_user, user_field, user_value)customer_user.save()customer_user.refresh_from_db()- order = Order(user=customer_user, token=str(uuid.uuid4()))- Order.objects.bulk_create([order, Order(token=str(uuid.uuid4()))])+ order = Order.objects.create(user=customer_user, token=str(uuid.uuid4()))page_size = 2variables = {"first": page_size, "after": None, "filter": orders_filter}@@ -226,14 +310,14 @@ def test_draft_order_query_pagination_with_filter_customer_fields(staff_api_client,permission_manage_orders,customer_user,+ draft_orders_for_pagination,):setattr(customer_user, user_field, user_value)customer_user.save()customer_user.refresh_from_db()- order = Order(status=OrderStatus.DRAFT, user=customer_user, token=str(uuid.uuid4()))- Order.objects.bulk_create(- [order, Order(token=str(uuid.uuid4()), status=OrderStatus.DRAFT)]+ order = Order.objects.create(+ status=OrderStatus.DRAFT, user=customer_user, token=str(uuid.uuid4()))page_size = 2@@ -251,7 +335,7 @@ def test_draft_order_query_pagination_with_filter_customer_fields(@pytest.mark.parametrize(- "orders_filter, count",+ "orders_filter, expected_total_count, orders_order",[({@@ -260,18 +344,23 @@ def test_draft_order_query_pagination_with_filter_customer_fields("lte": str(date.today()),}},- 1,+ 3,+ [3.0, 2.0],),- ({"created": {"gte": str(date.today() - timedelta(days=3))}}, 1),- ({"created": {"lte": str(date.today())}}, 2),- ({"created": {"lte": str(date.today() - timedelta(days=3))}}, 1),- ({"created": {"gte": str(date.today() + timedelta(days=1))}}, 0),+ ({"created": {"gte": str(date.today() - timedelta(days=3))}}, 3, [3.0, 2.0]),+ ({"created": {"lte": str(date.today())}}, 4, [0.0, 3.0]),+ ({"created": {"lte": str(date.today() - timedelta(days=3))}}, 1, [0.0]),+ ({"created": {"gte": str(date.today() + timedelta(days=1))}}, 0, []),],)def test_draft_order_query_pagination_with_filter_created(- orders_filter, count, staff_api_client, permission_manage_orders,+ orders_filter,+ expected_total_count,+ orders_order,+ staff_api_client,+ permission_manage_orders,+ draft_orders_for_pagination,):- Order.objects.create(status=OrderStatus.DRAFT)with freeze_time("2012-01-14"):Order.objects.create(status=OrderStatus.DRAFT)page_size = 2@@ -281,27 +370,38 @@ def test_draft_order_query_pagination_with_filter_created(QUERY_DRAFT_ORDERS_WITH_PAGINATION, variables)content = get_graphql_content(response)+orders = content["data"]["draftOrders"]["edges"]+ total_count = content["data"]["draftOrders"]["totalCount"]++ for i in range(total_count if total_count < page_size else page_size):+ assert orders[i]["node"]["total"]["gross"]["amount"] == orders_order[i]- assert len(orders) == count+ assert expected_total_count == total_count@pytest.mark.parametrize(- "orders_filter, count",+ "orders_filter, expected_total_count, orders_order",[- ({"search": "test_discount"}, 2),- ({"search": "test_discount1"}, 1),- ({"search": "translated_discount1_name"}, 1),- ({"search": "user"}, 2),- ({"search": "[email protected]"}, 1),- ({"search": "[email protected]"}, 1),- ({"search": "Leslie"}, 1),- ({"search": "Wade"}, 1),- ({"search": ""}, 3),+ ({"search": "test_discount"}, 2, [0.0, 0.0]),+ ({"search": "test_discount1"}, 1, [0.0]),+ ({"search": "translated_discount1_name"}, 1, [0.0]),+ ({"search": "user"}, 2, [0.0, 0.0]),+ ({"search": "[email protected]"}, 1, [0.0]),+ ({"search": "[email protected]"}, 1, [0.0]),+ ({"search": "Leslie"}, 1, [0.0]),+ ({"search": "Wade"}, 1, [0.0]),+ ({"search": ""}, 6, [0.0, 0.0]),],)def test_orders_query_pagination_with_filter_search(- orders_filter, count, staff_api_client, permission_manage_orders, customer_user,+ orders_filter,+ expected_total_count,+ orders_order,+ staff_api_client,+ permission_manage_orders,+ customer_user,+ orders_for_pagination,):Order.objects.bulk_create([@@ -326,7 +426,13 @@ def test_orders_query_pagination_with_filter_search(staff_api_client.user.user_permissions.add(permission_manage_orders)response = staff_api_client.post_graphql(QUERY_ORDERS_WITH_PAGINATION, variables)content = get_graphql_content(response)- assert content["data"]["orders"]["totalCount"] == count++ orders = content["data"]["orders"]["edges"]+ total_count = content["data"]["orders"]["totalCount"]++ assert expected_total_count == total_count+ for i in range(total_count if total_count < page_size else page_size):+ assert orders[i]["node"]["total"]["gross"]["amount"] == orders_order[i]def test_orders_query_pagination_with_filter_search_by_id(@@ -341,25 +447,27 @@ def test_orders_query_pagination_with_filter_search_by_id(@pytest.mark.parametrize(- "draft_orders_filter, count",+ "draft_orders_filter, expected_total_count, orders_order",[- ({"search": "test_discount"}, 2),- ({"search": "test_discount1"}, 1),- ({"search": "translated_discount1_name"}, 1),- ({"search": "user"}, 2),- ({"search": "[email protected]"}, 1),- ({"search": "[email protected]"}, 1),- ({"search": "Leslie"}, 1),- ({"search": "Wade"}, 1),- ({"search": ""}, 3),+ ({"search": "test_discount"}, 2, [0.0, 0.0]),+ ({"search": "test_discount1"}, 1, [0.0]),+ ({"search": "translated_discount1_name"}, 1, [0.0]),+ ({"search": "user"}, 2, [0.0, 0.0]),+ ({"search": "[email protected]"}, 1, [0.0]),+ ({"search": "[email protected]"}, 1, [0.0]),+ ({"search": "Leslie"}, 1, [0.0]),+ ({"search": "Wade"}, 1, [0.0]),+ ({"search": ""}, 6, [0.0, 0.0]),],)def test_draft_orders_query_pagination_with_filter_search(draft_orders_filter,- count,+ expected_total_count,+ orders_order,staff_api_client,permission_manage_orders,customer_user,+ draft_orders_for_pagination,):Order.objects.bulk_create([@@ -392,7 +500,12 @@ def test_draft_orders_query_pagination_with_filter_search(QUERY_DRAFT_ORDERS_WITH_PAGINATION, variables)content = get_graphql_content(response)- assert content["data"]["draftOrders"]["totalCount"] == count+ orders = content["data"]["draftOrders"]["edges"]+ total_count = content["data"]["draftOrders"]["totalCount"]++ assert expected_total_count == total_count+ for i in range(total_count if total_count < page_size else page_size):+ assert orders[i]["node"]["total"]["gross"]["amount"] == orders_order[i]def test_draft_orders_query_pagination_with_filter_search_by_id(