Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add pagination tests for webhooks
fowczrek9a0468ec5795
diff --git a/tests/api/pagination/test_discount.py b/tests/api/pagination/test_discount.pyindex 898c7c85aa..446f61174c 100644--- a/tests/api/pagination/test_discount.py+++ b/tests/api/pagination/test_discount.py@@ -6,7 +6,8 @@ from freezegun import freeze_timefrom saleor.discount import DiscountValueType, VoucherTypefrom saleor.discount.models import Sale, Voucher-from tests.api.utils import get_graphql_content++from ..utils import get_graphql_content@pytest.fixturediff --git a/tests/api/pagination/test_menu.py b/tests/api/pagination/test_menu.pyindex e76551d3e8..91b97917eb 100644--- a/tests/api/pagination/test_menu.py+++ b/tests/api/pagination/test_menu.py@@ -1,7 +1,8 @@import pytestfrom saleor.menu.models import Menu, MenuItem-from tests.api.utils import get_graphql_content++from ..utils import get_graphql_content@pytest.fixture@@ -51,21 +52,12 @@ QUERY_MENUS_PAGINATION = """],)def test_menus_pagination_with_sorting(- sort_by,- menus_order,- staff_api_client,- permission_manage_discounts,- menus_for_pagination,+ sort_by, menus_order, staff_api_client, menus_for_pagination,):page_size = 3variables = {"first": page_size, "after": None, "sortBy": sort_by}- response = staff_api_client.post_graphql(- QUERY_MENUS_PAGINATION,- variables,- permissions=[permission_manage_discounts],- check_no_permissions=False,- )+ response = staff_api_client.post_graphql(QUERY_MENUS_PAGINATION, variables,)content = get_graphql_content(response)menus_nodes = content["data"]["menus"]["edges"]assert menus_order[0] == menus_nodes[0]["node"]["name"]@@ -91,12 +83,7 @@ def test_menus_pagination_with_filtering(page_size = 2variables = {"first": page_size, "after": None, "filter": filter_by}- response = staff_api_client.post_graphql(- QUERY_MENUS_PAGINATION,- variables,- permissions=[permission_manage_discounts],- check_no_permissions=False,- )+ response = staff_api_client.post_graphql(QUERY_MENUS_PAGINATION, variables,)content = get_graphql_content(response)menus_nodes = content["data"]["menus"]["edges"]assert menus_order[0] == menus_nodes[0]["node"]["name"]@@ -155,21 +142,12 @@ QUERY_MENU_ITEMS_PAGINATION = """],)def test_menu_items_pagination_with_sorting(- sort_by,- menu_items_order,- staff_api_client,- permission_manage_discounts,- menu_items_for_pagination,+ sort_by, menu_items_order, staff_api_client, menu_items_for_pagination,):page_size = 3variables = {"first": page_size, "after": None, "sortBy": sort_by}- response = staff_api_client.post_graphql(- QUERY_MENU_ITEMS_PAGINATION,- variables,- permissions=[permission_manage_discounts],- check_no_permissions=False,- )+ response = staff_api_client.post_graphql(QUERY_MENU_ITEMS_PAGINATION, variables,)content = get_graphql_content(response)menu_items_nodes = content["data"]["menuItems"]["edges"]assert menu_items_order[0] == menu_items_nodes[0]["node"]["name"]@@ -186,21 +164,12 @@ def test_menu_items_pagination_with_sorting(],)def test_menu_items_pagination_with_filtering(- filter_by,- menu_items_order,- staff_api_client,- permission_manage_discounts,- menu_items_for_pagination,+ filter_by, menu_items_order, staff_api_client, menu_items_for_pagination,):page_size = 2variables = {"first": page_size, "after": None, "filter": filter_by}- response = staff_api_client.post_graphql(- QUERY_MENU_ITEMS_PAGINATION,- variables,- permissions=[permission_manage_discounts],- check_no_permissions=False,- )+ response = staff_api_client.post_graphql(QUERY_MENU_ITEMS_PAGINATION, variables,)content = get_graphql_content(response)menu_items_nodes = content["data"]["menuItems"]["edges"]assert menu_items_order[0] == menu_items_nodes[0]["node"]["name"]diff --git a/tests/api/pagination/test_webhook.py b/tests/api/pagination/test_webhook.pynew file mode 100644index 0000000000..1b18f7e3ba--- /dev/null+++ b/tests/api/pagination/test_webhook.py@@ -0,0 +1,140 @@+import pytest++from saleor.account.models import ServiceAccount+from saleor.webhook.models import Webhook++from ..utils import get_graphql_content+++def webhooks_for_pagination(db):+ service_accounts = ServiceAccount.objects.bulk_create(+ [+ ServiceAccount(name="ServiceAccount1", is_active=True),+ ServiceAccount(name="ServiceAccount2", is_active=True),+ ]+ )++ return Webhook.objects.bulk_create(+ [+ Webhook(+ name="Webhook1",+ service_account=service_accounts[1],+ target_url="http://www.example.com/test4",+ is_active=False,+ ),+ Webhook(+ name="WebhookWebhook1",+ service_account=service_accounts[0],+ target_url="http://www.example.com/test2",+ ),+ Webhook(+ name="WebhookWebhook2",+ service_account=service_accounts[1],+ target_url="http://www.example.com/test1",+ ),+ Webhook(+ name="Webhook2",+ service_account=service_accounts[1],+ target_url="http://www.example.com/test3",+ is_active=False,+ ),+ Webhook(+ name="Webhook3",+ service_account=service_accounts[0],+ target_url="http://www.example.com/test",+ ),+ ]+ )+++QUERY_WEBHOOKS_PAGINATION = """+ query (+ $first: Int, $last: Int, $after: String, $before: String,+ $sortBy: WebhookSortingInput, $filter: WebhookFilterInput+ ){+ webhooks(+ first: $first, last: $last, after: $after, before: $before,+ sortBy: $sortBy, filter: $filter+ ) {+ edges {+ node {+ name+ }+ }+ pageInfo{+ startCursor+ endCursor+ hasNextPage+ hasPreviousPage+ }+ }+ }+"""+++ "sort_by, webhooks_order",+ [+ ({"field": "NAME", "direction": "ASC"}, ["Webhook1", "Webhook2", "Webhook3"]),+ (+ {"field": "NAME", "direction": "DESC"},+ ["WebhookWebhook2", "WebhookWebhook1", "Webhook3"],+ ),+ (+ {"field": "SERVICE_ACCOUNT", "direction": "ASC"},+ ["Webhook3", "WebhookWebhook1", "Webhook2"],+ ),+ (+ {"field": "TARGET_URL", "direction": "ASC"},+ ["Webhook3", "WebhookWebhook2", "WebhookWebhook1"],+ ),+ ],+)+def test_webhooks_pagination_with_sorting(+ sort_by,+ webhooks_order,+ staff_api_client,+ permission_manage_webhooks,+ webhooks_for_pagination,+):+ page_size = 3++ variables = {"first": page_size, "after": None, "sortBy": sort_by}+ response = staff_api_client.post_graphql(+ QUERY_WEBHOOKS_PAGINATION, variables, permissions=[permission_manage_webhooks],+ )+ content = get_graphql_content(response)+ webhooks_nodes = content["data"]["webhooks"]["edges"]+ assert webhooks_order[0] == webhooks_nodes[0]["node"]["name"]+ assert webhooks_order[1] == webhooks_nodes[1]["node"]["name"]+ assert webhooks_order[2] == webhooks_nodes[2]["node"]["name"]+ assert len(webhooks_nodes) == page_size+++ "filter_by, webhooks_order",+ [+ ({"search": "WebhookWebhook"}, ["WebhookWebhook1", "WebhookWebhook2"]),+ ({"search": "Webhook1"}, ["Webhook1", "WebhookWebhook1"]),+ ({"isActive": True}, ["WebhookWebhook1", "WebhookWebhook2"]),+ ],+)+def test_webhooks_pagination_with_filtering(+ filter_by,+ webhooks_order,+ staff_api_client,+ permission_manage_webhooks,+ webhooks_for_pagination,+):+ page_size = 2++ variables = {"first": page_size, "after": None, "filter": filter_by}+ response = staff_api_client.post_graphql(+ QUERY_WEBHOOKS_PAGINATION, variables, permissions=[permission_manage_webhooks],+ )+ content = get_graphql_content(response)+ webhooks_nodes = content["data"]["webhooks"]["edges"]+ assert webhooks_order[0] == webhooks_nodes[0]["node"]["name"]+ assert webhooks_order[1] == webhooks_nodes[1]["node"]["name"]+ assert len(webhooks_nodes) == page_size