Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Split apps and webhooks fixtures (#16853)
Krzysztof Waliczek3383aefcdfc3
diff --git a/conftest.py b/conftest.pyindex 7837d72825..7d49d49d3a 100644--- a/conftest.py+++ b/conftest.py@@ -24,14 +24,14 @@ prepare_test_db_connections()pytest_plugins = ["saleor.tests.fixtures",+ "saleor.app.tests.fixtures","saleor.discount.tests.test_utils.fixtures","saleor.plugins.tests.fixtures","saleor.graphql.tests.fixtures","saleor.graphql.checkout.tests.benchmark.fixtures","saleor.graphql.account.tests.benchmark.fixtures","saleor.graphql.giftcard.tests.benchmark.fixtures",- "saleor.graphql.webhook.tests.benchmark.fixtures",- "saleor.webhook.tests.subscription_webhooks.fixtures",+ "saleor.webhook.tests.fixtures","saleor.tax.tests.fixtures","saleor.channel.tests.fixtures","saleor.page.tests.fixtures",diff --git a/saleor/app/tests/fixtures/__init__.py b/saleor/app/tests/fixtures/__init__.pynew file mode 100644index 0000000000..7c7c8b8eeb--- /dev/null+++ b/saleor/app/tests/fixtures/__init__.py@@ -0,0 +1,6 @@+from .app import * # noqa: F403+from .app_extension import * # noqa: F403+from .app_installation import * # noqa: F403+from .webhooks.payment_app import * # noqa: F403+from .webhooks.shipping_app import * # noqa: F403+from .webhooks.tax_app import * # noqa: F403diff --git a/saleor/app/tests/fixtures/app.py b/saleor/app/tests/fixtures/app.pynew file mode 100644index 0000000000..13cf6109a9--- /dev/null+++ b/saleor/app/tests/fixtures/app.py@@ -0,0 +1,100 @@+import pytest+from django.utils import timezone++from ....app.models import App+from ....app.types import AppType+++def app(db):+ app = App.objects.create(+ name="Sample app objects",+ is_active=True,+ identifier="saleor.app.test",+ manifest_url="http://localhost:3000/manifest",+ )+ return app+++def app_marked_to_be_removed(db):+ app = App.objects.create(+ name="Sample app objects",+ is_active=True,+ identifier="saleor.app.test",+ manifest_url="http://localhost:3000/manifest",+ removed_at=timezone.now(),+ )+ return app+++def webhook_app(+ db,+ permission_manage_shipping,+ permission_manage_gift_card,+ permission_manage_discounts,+ permission_manage_menus,+ permission_manage_products,+ permission_manage_staff,+ permission_manage_orders,+ permission_manage_users,+):+ app = App.objects.create(name="Webhook app", is_active=True)+ app.permissions.add(permission_manage_shipping)+ app.permissions.add(permission_manage_gift_card)+ app.permissions.add(permission_manage_discounts)+ app.permissions.add(permission_manage_menus)+ app.permissions.add(permission_manage_products)+ app.permissions.add(permission_manage_staff)+ app.permissions.add(permission_manage_orders)+ app.permissions.add(permission_manage_users)+ return app+++def app_with_token(db):+ app = App.objects.create(name="Sample app objects", is_active=True)+ app.tokens.create(name="Test")+ return app+++def removed_app(db):+ app = App.objects.create(+ name="Deleted app ",+ is_active=True,+ removed_at=(timezone.now() - timezone.timedelta(days=1, hours=1)),+ )+ return app+++def external_app(db):+ app = App.objects.create(+ name="External App",+ is_active=True,+ type=AppType.THIRDPARTY,+ identifier="mirumee.app.sample",+ about_app="About app text.",+ data_privacy="Data privacy text.",+ data_privacy_url="http://www.example.com/privacy/",+ homepage_url="http://www.example.com/homepage/",+ support_url="http://www.example.com/support/contact/",+ configuration_url="http://www.example.com/app-configuration/",+ app_url="http://www.example.com/app/",+ )+ app.tokens.create(name="Default")+ return app+++def apps_without_webhooks(db):+ return App.objects.bulk_create(+ [+ App(name="App1", is_active=True),+ App(name="App2", is_active=False),+ App(name="App3", is_active=True),+ App(name="App4", is_active=False),+ ]+ )diff --git a/saleor/app/tests/fixtures/app_extension.py b/saleor/app/tests/fixtures/app_extension.pynew file mode 100644index 0000000000..261dd7e638--- /dev/null+++ b/saleor/app/tests/fixtures/app_extension.py@@ -0,0 +1,50 @@+import pytest++from ....app.models import AppExtension+from ....app.types import AppExtensionMount+++def app_with_extensions(app_with_token, permission_manage_products):+ first_app_extension = AppExtension(+ app=app_with_token,+ label="Create product with App",+ url="www.example.com/app-product",+ mount=AppExtensionMount.PRODUCT_OVERVIEW_MORE_ACTIONS,+ )+ extensions = AppExtension.objects.bulk_create(+ [+ first_app_extension,+ AppExtension(+ app=app_with_token,+ label="Update product with App",+ url="www.example.com/app-product-update",+ mount=AppExtensionMount.PRODUCT_DETAILS_MORE_ACTIONS,+ ),+ ]+ )+ first_app_extension.permissions.add(permission_manage_products)+ return app_with_token, extensions+++def removed_app_with_extensions(removed_app, permission_manage_products):+ first_app_extension = AppExtension(+ app=removed_app,+ label="Create product with App",+ url="www.example.com/app-product",+ mount=AppExtensionMount.PRODUCT_OVERVIEW_MORE_ACTIONS,+ )+ extensions = AppExtension.objects.bulk_create(+ [+ first_app_extension,+ AppExtension(+ app=removed_app,+ label="Update product with App",+ url="www.example.com/app-product-update",+ mount=AppExtensionMount.PRODUCT_DETAILS_MORE_ACTIONS,+ ),+ ]+ )+ first_app_extension.permissions.add(permission_manage_products)+ return removed_app, extensionsdiff --git a/saleor/app/tests/fixtures/app_installation.py b/saleor/app/tests/fixtures/app_installation.pynew file mode 100644index 0000000000..73fecad192--- /dev/null+++ b/saleor/app/tests/fixtures/app_installation.py@@ -0,0 +1,12 @@+import pytest++from ....app.models import AppInstallation+++def app_installation():+ app_installation = AppInstallation.objects.create(+ app_name="External App",+ manifest_url="http://localhost:3000/manifest",+ )+ return app_installationdiff --git a/saleor/app/tests/fixtures/webhooks/payment_app.py b/saleor/app/tests/fixtures/webhooks/payment_app.pynew file mode 100644index 0000000000..18f4a97e97--- /dev/null+++ b/saleor/app/tests/fixtures/webhooks/payment_app.py@@ -0,0 +1,156 @@+import pytest++from .....app.models import App+from .....webhook.event_types import WebhookEventSyncType+from .....webhook.models import Webhook, WebhookEvent+from .....webhook.tests.subscription_webhooks import subscription_queries+++def payment_app(db, permission_manage_payments):+ app = App.objects.create(+ name="Payment App", is_active=True, identifier="saleor.payment.test.app"+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="payment-webhook-1",+ app=app,+ target_url="https://payment-gateway.com/api/",+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in WebhookEventSyncType.PAYMENT_EVENTS+ ]+ )+ return app+++def payment_app_with_subscription_webhooks(db, permission_manage_payments):+ app = App.objects.create(+ name="Payment App", is_active=True, identifier="saleor.payment.test.app"+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="payment-subscription-webhook-1",+ app=app,+ target_url="https://payment-gateway.com/api/",+ subscription_query=subscription_queries.PAYMENT_AUTHORIZE,+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in WebhookEventSyncType.PAYMENT_EVENTS+ ]+ )+ return app+++def list_stored_payment_methods_app(db, permission_manage_payments):+ app = App.objects.create(+ name="List payment methods app",+ is_active=True,+ identifier="saleor.payment.app.list.stored.method",+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="list_stored_payment_methods",+ app=app,+ target_url="http://localhost:8000/endpoint/",+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.LIST_STORED_PAYMENT_METHODS,+ )+ return app+++def stored_payment_method_request_delete_app(db, permission_manage_payments):+ app = App.objects.create(+ name="Payment method request delete",+ is_active=True,+ identifier="saleor.payment.app.payment.method.request.delete",+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="stored_payment_method_request_delete",+ app=app,+ target_url="http://localhost:8000/endpoint/",+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.STORED_PAYMENT_METHOD_DELETE_REQUESTED,+ )+ return app+++def payment_gateway_initialize_tokenization_app(db, permission_manage_payments):+ app = App.objects.create(+ name="Payment method request delete",+ is_active=True,+ identifier="saleor.payment.app.payment.gateway.initialize.tokenization",+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="payment_gateway_initialize_tokenization",+ app=app,+ target_url="http://localhost:8000/endpoint/",+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.PAYMENT_GATEWAY_INITIALIZE_TOKENIZATION_SESSION,+ )+ return app+++def payment_method_initialize_tokenization_app(db, permission_manage_payments):+ app = App.objects.create(+ name="Payment method initialize tokenization",+ is_active=True,+ identifier="saleor.payment.app.payment.method.initialize.tokenization",+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="payment_method_initialize_tokenization",+ app=app,+ target_url="http://localhost:8000/endpoint/",+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.PAYMENT_METHOD_INITIALIZE_TOKENIZATION_SESSION,+ )+ return app+++def payment_method_process_tokenization_app(db, permission_manage_payments):+ app = App.objects.create(+ name="Payment method process tokenization",+ is_active=True,+ identifier="saleor.payment.app.payment.method.process.tokenization",+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="payment_method_process_tokenization",+ app=app,+ target_url="http://localhost:8000/endpoint/",+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.PAYMENT_METHOD_PROCESS_TOKENIZATION_SESSION,+ )+ return appdiff --git a/saleor/app/tests/fixtures/webhooks/shipping_app.py b/saleor/app/tests/fixtures/webhooks/shipping_app.pynew file mode 100644index 0000000000..2582af223b--- /dev/null+++ b/saleor/app/tests/fixtures/webhooks/shipping_app.py@@ -0,0 +1,61 @@+import pytest++from .....app.models import App+from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType+from .....webhook.models import Webhook, WebhookEvent+++def shipping_app(db, permission_manage_shipping):+ app = App.objects.create(name="Shipping App", is_active=True)+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_shipping)++ webhook = Webhook.objects.create(+ name="shipping-webhook-1",+ app=app,+ target_url="https://shipping-app.com/api/",+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in [+ WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,+ WebhookEventAsyncType.FULFILLMENT_CREATED,+ ]+ ]+ )+ return app+++def shipping_app_with_subscription(db, permission_manage_shipping):+ app = App.objects.create(name="Shipping App with subscription", is_active=True)+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_shipping)++ webhook = Webhook.objects.create(+ name="shipping-webhook-1",+ app=app,+ target_url="https://shipping-app.com/api/",+ subscription_query="""+ subscription {+ event {+ ... on ShippingListMethodsForCheckout {+ __typename+ }+ }+}++ """,+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in [+ WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,+ WebhookEventAsyncType.FULFILLMENT_CREATED,+ ]+ ]+ )+ return appdiff --git a/saleor/app/tests/fixtures/webhooks/tax_app.py b/saleor/app/tests/fixtures/webhooks/tax_app.pynew file mode 100644index 0000000000..ca68b7cbab--- /dev/null+++ b/saleor/app/tests/fixtures/webhooks/tax_app.py@@ -0,0 +1,92 @@+import pytest++from .....app.models import App+from .....app.types import AppType+from .....graphql.core.utils import to_global_id_or_none+from .....webhook.event_types import WebhookEventSyncType+from .....webhook.models import Webhook, WebhookEvent+from .....webhook.tests.subscription_webhooks import subscription_queries+++def tax_app(db, permission_handle_taxes):+ app = App.objects.create(name="Tax App", is_active=True)+ app.identifier = to_global_id_or_none(app)+ app.save()+ app.permissions.add(permission_handle_taxes)++ webhook = Webhook.objects.create(+ name="tax-webhook-1",+ app=app,+ target_url="https://tax-app.com/api/",+ subscription_query=subscription_queries.CALCULATE_TAXES_SUBSCRIPTION_QUERY,+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in [+ WebhookEventSyncType.ORDER_CALCULATE_TAXES,+ WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,+ ]+ ]+ )+ return app+++def external_tax_app(db, permission_handle_taxes):+ app = App.objects.create(+ name="External App",+ is_active=True,+ type=AppType.THIRDPARTY,+ identifier="mirumee.app.simple.tax",+ about_app="About app text.",+ data_privacy="Data privacy text.",+ data_privacy_url="http://www.example.com/privacy/",+ homepage_url="http://www.example.com/homepage/",+ support_url="http://www.example.com/support/contact/",+ configuration_url="http://www.example.com/app-configuration/",+ app_url="http://www.example.com/app/",+ )+ app.tokens.create(name="Default")+ app.permissions.add(permission_handle_taxes)++ webhook = Webhook.objects.create(+ name="external-tax-webhook-1",+ app=app,+ target_url="https://tax-app.example.com/api/",+ subscription_query=subscription_queries.CALCULATE_TAXES_SUBSCRIPTION_QUERY,+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in [+ WebhookEventSyncType.ORDER_CALCULATE_TAXES,+ WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,+ ]+ ]+ )+ return app+++def tax_app_with_subscription_webhooks(db, permission_handle_taxes):+ app = App.objects.create(name="Tax App with subscription", is_active=True)+ app.permissions.add(permission_handle_taxes)++ webhook = Webhook.objects.create(+ name="tax-subscription-webhook-1",+ app=app,+ target_url="https://tax-app.com/api/",+ subscription_query=subscription_queries.CALCULATE_TAXES_SUBSCRIPTION_QUERY,+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in [+ WebhookEventSyncType.ORDER_CALCULATE_TAXES,+ WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,+ ]+ ]+ )+ return appdiff --git a/saleor/graphql/webhook/tests/benchmark/fixtures.py b/saleor/graphql/webhook/tests/benchmark/fixtures.pydeleted file mode 100644index 9c662e6799..0000000000--- a/saleor/graphql/webhook/tests/benchmark/fixtures.py+++ /dev/null@@ -1,85 +0,0 @@-from itertools import cycle--import pytest--from .....app.models import App-from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType-from .....webhook.models import Webhook, WebhookEvent--NUMBER_OF_WEBHOOKS_PER_APP = 6---def _prepare_async_and_sync_events(webhook):- return [- WebhookEvent(- webhook=webhook, event_type=WebhookEventSyncType.PAYMENT_AUTHORIZE- ),- WebhookEvent(webhook=webhook, event_type=WebhookEventAsyncType.ANY),- ]---def _prepare_sync_event(webhook):- return [- WebhookEvent(- webhook=webhook,- event_type=WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,- )- ]---def _prepare_async_event(webhook):- return [- WebhookEvent(webhook=webhook, event_type=WebhookEventAsyncType.CHANNEL_CREATED)- ]---def events_cycle():- return cycle(- (- _prepare_async_and_sync_events,- _prepare_sync_event,- _prepare_async_event,- lambda x: [],- lambda x: [],- )- )---def webhook_events(webhooks_without_events, events_cycle):- webhook_events = []-- for webhook in webhooks_without_events:- webhook_events.extend(next(events_cycle)(webhook))-- return WebhookEvent.objects.bulk_create(webhook_events)---def apps_without_webhooks(db):- return App.objects.bulk_create(- [- App(name="App1", is_active=True),- App(name="App2", is_active=False),- App(name="App3", is_active=True),- App(name="App4", is_active=False),- ]- )---def webhooks_without_events(apps_without_webhooks):- webhooks = []-- for app in apps_without_webhooks[:2]:- for index in range(NUMBER_OF_WEBHOOKS_PER_APP):- webhook = Webhook(- name=f"Webhook_{index}",- app=app,- target_url=f"http://localhost/test_{index}",- is_active=index % 2,- )- webhooks.append(webhook)-- return Webhook.objects.bulk_create(webhooks)diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex 6907fd5b1a..5636e80fc4 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -6,7 +6,7 @@ from contextlib import contextmanagerfrom decimal import Decimalfrom functools import partialfrom io import BytesIO-from typing import Callable, Optional, Union+from typing import Callable, Optionalfrom unittest.mock import MagicMockimport graphene@@ -25,8 +25,6 @@ from PIL import Imagefrom prices import Moneyfrom ..account.models import Address, Group, StaffNotificationRecipient, User-from ..app.models import App, AppExtension, AppInstallation-from ..app.types import AppExtensionMount, AppTypefrom ..attribute import AttributeEntityType, AttributeInputType, AttributeTypefrom ..attribute.models import (Attribute,@@ -42,7 +40,7 @@ from ..checkout.utils import (add_variant_to_checkout,add_voucher_to_checkout,)-from ..core import EventDeliveryStatus, JobStatus+from ..core import JobStatusfrom ..core.models import EventDelivery, EventDeliveryAttempt, EventPayloadfrom ..core.payments import PaymentInterfacefrom ..core.postgres import FlatConcatSearchVector@@ -76,7 +74,6 @@ from ..discount.models import ()from ..giftcard import GiftCardEventsfrom ..giftcard.models import GiftCard, GiftCardEvent, GiftCardTag-from ..graphql.core.utils import to_global_id_or_nonefrom ..menu.models import Menufrom ..payment import ChargeStatus, TransactionKindfrom ..payment.interface import AddressData, GatewayConfig, GatewayResponse, PaymentData@@ -124,132 +121,10 @@ from ..warehouse.models import (Stock,Warehouse,)-from ..webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType-from ..webhook.models import Webhook, WebhookEvent-from ..webhook.observability import WebhookData-from ..webhook.tests.subscription_webhooks import subscription_queries-from ..webhook.transport.utils import WebhookResponse, to_payment_app_id+from ..webhook.event_types import WebhookEventAsyncType+from ..webhook.transport.utils import to_payment_app_idfrom .utils import dummy_editorjs-CALCULATE_TAXES_SUBSCRIPTION_QUERY = """-subscription CalculateTaxes {- event {- ...CalculateTaxesEvent- }-}--fragment CalculateTaxesEvent on Event {- __typename- ... on CalculateTaxes {- taxBase {- ...TaxBase- }- recipient {- privateMetadata {- key- value- }- }- }-}--fragment TaxBase on TaxableObject {- pricesEnteredWithTax- currency- channel {- slug- }- discounts {- ...TaxDiscount- }- address {- ...Address- }- shippingPrice {- amount- }- lines {- ...TaxBaseLine- }- sourceObject {- __typename- ... on Checkout {- avataxEntityCode: metafield(key: "avataxEntityCode")- user {- ...User- }- }- ... on Order {- avataxEntityCode: metafield(key: "avataxEntityCode")- user {- ...User- }- }- }-}--fragment TaxDiscount on TaxableObjectDiscount {- name- amount {- amount- }-}--fragment Address on Address {- streetAddress1- streetAddress2- city- countryArea- postalCode- country {- code- }-}--fragment TaxBaseLine on TaxableObjectLine {- sourceLine {- __typename- ... on CheckoutLine {- id- checkoutProductVariant: variant {- id- product {- taxClass {- id- name- }- }- }- }- ... on OrderLine {- id- orderProductVariant: variant {- id- product {- taxClass {- id- name- }- }- }- }- }- quantity- unitPrice {- amount- }- totalPrice {- amount- }-}--fragment User on User {- id- avataxCustomerCode: metafield(key: "avataxCustomerCode")-}-"""-class CaptureQueriesContext(BaseCaptureQueriesContext):IGNORED_QUERIES = settings.PATTERNS_IGNORED_IN_QUERY_CAPTURES # type: ignore@@ -5871,383 +5746,6 @@ def other_description_json():}-def app(db):- app = App.objects.create(- name="Sample app objects",- is_active=True,- identifier="saleor.app.test",- manifest_url="http://localhost:3000/manifest",- )- return app---def app_marked_to_be_removed(db):- app = App.objects.create(- name="Sample app objects",- is_active=True,- identifier="saleor.app.test",- manifest_url="http://localhost:3000/manifest",- removed_at=timezone.now(),- )- return app---def webhook_app(- db,- permission_manage_shipping,- permission_manage_gift_card,- permission_manage_discounts,- permission_manage_menus,- permission_manage_products,- permission_manage_staff,- permission_manage_orders,- permission_manage_users,-):- app = App.objects.create(name="Webhook app", is_active=True)- app.permissions.add(permission_manage_shipping)- app.permissions.add(permission_manage_gift_card)- app.permissions.add(permission_manage_discounts)- app.permissions.add(permission_manage_menus)- app.permissions.add(permission_manage_products)- app.permissions.add(permission_manage_staff)- app.permissions.add(permission_manage_orders)- app.permissions.add(permission_manage_users)- return app---def app_with_token(db):- app = App.objects.create(name="Sample app objects", is_active=True)- app.tokens.create(name="Test")- return app---def removed_app(db):- app = App.objects.create(- name="Deleted app ",- is_active=True,- removed_at=(timezone.now() - datetime.timedelta(days=1, hours=1)),- )- return app---def app_with_extensions(app_with_token, permission_manage_products):- first_app_extension = AppExtension(- app=app_with_token,- label="Create product with App",- url="www.example.com/app-product",- mount=AppExtensionMount.PRODUCT_OVERVIEW_MORE_ACTIONS,- )- extensions = AppExtension.objects.bulk_create(- [- first_app_extension,- AppExtension(- app=app_with_token,- label="Update product with App",- url="www.example.com/app-product-update",- mount=AppExtensionMount.PRODUCT_DETAILS_MORE_ACTIONS,- ),- ]- )- first_app_extension.permissions.add(permission_manage_products)- return app_with_token, extensions---def removed_app_with_extensions(removed_app, permission_manage_products):- first_app_extension = AppExtension(- app=removed_app,- label="Create product with App",- url="www.example.com/app-product",- mount=AppExtensionMount.PRODUCT_OVERVIEW_MORE_ACTIONS,- )- extensions = AppExtension.objects.bulk_create(- [- first_app_extension,- AppExtension(- app=removed_app,- label="Update product with App",- url="www.example.com/app-product-update",- mount=AppExtensionMount.PRODUCT_DETAILS_MORE_ACTIONS,- ),- ]- )- first_app_extension.permissions.add(permission_manage_products)- return removed_app, extensions---def payment_app(db, permission_manage_payments):- app = App.objects.create(- name="Payment App", is_active=True, identifier="saleor.payment.test.app"- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="payment-webhook-1",- app=app,- target_url="https://payment-gateway.com/api/",- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in WebhookEventSyncType.PAYMENT_EVENTS- ]- )- return app---def payment_app_with_subscription_webhooks(db, permission_manage_payments):- app = App.objects.create(- name="Payment App", is_active=True, identifier="saleor.payment.test.app"- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="payment-subscription-webhook-1",- app=app,- target_url="https://payment-gateway.com/api/",- subscription_query=subscription_queries.PAYMENT_AUTHORIZE,- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in WebhookEventSyncType.PAYMENT_EVENTS- ]- )- return app---def shipping_app(db, permission_manage_shipping):- app = App.objects.create(name="Shipping App", is_active=True)- app.tokens.create(name="Default")- app.permissions.add(permission_manage_shipping)-- webhook = Webhook.objects.create(- name="shipping-webhook-1",- app=app,- target_url="https://shipping-app.com/api/",- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in [- WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,- WebhookEventAsyncType.FULFILLMENT_CREATED,- ]- ]- )- return app---def shipping_app_with_subscription(db, permission_manage_shipping):- app = App.objects.create(name="Shipping App with subscription", is_active=True)- app.tokens.create(name="Default")- app.permissions.add(permission_manage_shipping)-- webhook = Webhook.objects.create(- name="shipping-webhook-1",- app=app,- target_url="https://shipping-app.com/api/",- subscription_query="""- subscription {- event {- ... on ShippingListMethodsForCheckout {- __typename- }- }-}-- """,- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in [- WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,- WebhookEventAsyncType.FULFILLMENT_CREATED,- ]- ]- )- return app---def list_stored_payment_methods_app(db, permission_manage_payments):- app = App.objects.create(- name="List payment methods app",- is_active=True,- identifier="saleor.payment.app.list.stored.method",- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="list_stored_payment_methods",- app=app,- target_url="http://localhost:8000/endpoint/",- )- webhook.events.create(- event_type=WebhookEventSyncType.LIST_STORED_PAYMENT_METHODS,- )- return app---def stored_payment_method_request_delete_app(db, permission_manage_payments):- app = App.objects.create(- name="Payment method request delete",- is_active=True,- identifier="saleor.payment.app.payment.method.request.delete",- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="stored_payment_method_request_delete",- app=app,- target_url="http://localhost:8000/endpoint/",- )- webhook.events.create(- event_type=WebhookEventSyncType.STORED_PAYMENT_METHOD_DELETE_REQUESTED,- )- return app---def payment_gateway_initialize_tokenization_app(db, permission_manage_payments):- app = App.objects.create(- name="Payment method request delete",- is_active=True,- identifier="saleor.payment.app.payment.gateway.initialize.tokenization",- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="payment_gateway_initialize_tokenization",- app=app,- target_url="http://localhost:8000/endpoint/",- )- webhook.events.create(- event_type=WebhookEventSyncType.PAYMENT_GATEWAY_INITIALIZE_TOKENIZATION_SESSION,- )- return app---def payment_method_initialize_tokenization_app(db, permission_manage_payments):- app = App.objects.create(- name="Payment method initialize tokenization",- is_active=True,- identifier="saleor.payment.app.payment.method.initialize.tokenization",- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="payment_method_initialize_tokenization",- app=app,- target_url="http://localhost:8000/endpoint/",- )- webhook.events.create(- event_type=WebhookEventSyncType.PAYMENT_METHOD_INITIALIZE_TOKENIZATION_SESSION,- )- return app---def payment_method_process_tokenization_app(db, permission_manage_payments):- app = App.objects.create(- name="Payment method process tokenization",- is_active=True,- identifier="saleor.payment.app.payment.method.process.tokenization",- )- app.tokens.create(name="Default")- app.permissions.add(permission_manage_payments)-- webhook = Webhook.objects.create(- name="payment_method_process_tokenization",- app=app,- target_url="http://localhost:8000/endpoint/",- )- webhook.events.create(- event_type=WebhookEventSyncType.PAYMENT_METHOD_PROCESS_TOKENIZATION_SESSION,- )- return app---def tax_app(db, permission_handle_taxes):- app = App.objects.create(name="Tax App", is_active=True)- app.identifier = to_global_id_or_none(app)- app.save()- app.permissions.add(permission_handle_taxes)-- webhook = Webhook.objects.create(- name="tax-webhook-1",- app=app,- target_url="https://tax-app.com/api/",- subscription_query=CALCULATE_TAXES_SUBSCRIPTION_QUERY,- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in [- WebhookEventSyncType.ORDER_CALCULATE_TAXES,- WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,- ]- ]- )- return app---def external_tax_app(db, permission_handle_taxes):- app = App.objects.create(- name="External App",- is_active=True,- type=AppType.THIRDPARTY,- identifier="mirumee.app.simple.tax",- about_app="About app text.",- data_privacy="Data privacy text.",- data_privacy_url="http://www.example.com/privacy/",- homepage_url="http://www.example.com/homepage/",- support_url="http://www.example.com/support/contact/",- configuration_url="http://www.example.com/app-configuration/",- app_url="http://www.example.com/app/",- )- app.tokens.create(name="Default")- app.permissions.add(permission_handle_taxes)-- webhook = Webhook.objects.create(- name="external-tax-webhook-1",- app=app,- target_url="https://tax-app.example.com/api/",- subscription_query=CALCULATE_TAXES_SUBSCRIPTION_QUERY,- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in [- WebhookEventSyncType.ORDER_CALCULATE_TAXES,- WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,- ]- ]- )- return app--@pytest.fixturedef tax_line_data_response():return {@@ -6276,109 +5774,6 @@ def tax_data_response(tax_line_data_response):}-def tax_app_with_subscription_webhooks(db, permission_handle_taxes):- app = App.objects.create(name="Tax App with subscription", is_active=True)- app.permissions.add(permission_handle_taxes)-- webhook = Webhook.objects.create(- name="tax-subscription-webhook-1",- app=app,- target_url="https://tax-app.com/api/",- subscription_query=CALCULATE_TAXES_SUBSCRIPTION_QUERY,- )- webhook.events.bulk_create(- [- WebhookEvent(event_type=event_type, webhook=webhook)- for event_type in [- WebhookEventSyncType.ORDER_CALCULATE_TAXES,- WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,- ]- ]- )- return app---def observability_webhook(db, permission_manage_observability):- app = App.objects.create(name="Observability App", is_active=True)- app.tokens.create(name="Default")- app.permissions.add(permission_manage_observability)-- webhook = Webhook.objects.create(- name="observability-webhook-1",- app=app,- target_url="https://observability-app.com/api/",- )- webhook.events.create(event_type=WebhookEventAsyncType.OBSERVABILITY)- return webhook---def observability_webhook_data(observability_webhook):- return WebhookData(- id=observability_webhook.id,- saleor_domain="mirumee.com",- target_url=observability_webhook.target_url,- secret_key=observability_webhook.secret_key,- )---def external_app(db):- app = App.objects.create(- name="External App",- is_active=True,- type=AppType.THIRDPARTY,- identifier="mirumee.app.sample",- about_app="About app text.",- data_privacy="Data privacy text.",- data_privacy_url="http://www.example.com/privacy/",- homepage_url="http://www.example.com/homepage/",- support_url="http://www.example.com/support/contact/",- configuration_url="http://www.example.com/app-configuration/",- app_url="http://www.example.com/app/",- )- app.tokens.create(name="Default")- return app---def webhook(app):- webhook = Webhook.objects.create(- name="Simple webhook", app=app, target_url="http://www.example.com/test"- )- webhook.events.create(event_type=WebhookEventAsyncType.ORDER_CREATED)- return webhook---def webhook_without_name(app):- webhook = Webhook.objects.create(app=app, target_url="http://www.example.com/test")- webhook.events.create(event_type=WebhookEventAsyncType.ORDER_CREATED)- return webhook---def webhook_removed_app(removed_app):- webhook = Webhook.objects.create(- name="Removed app webhook",- app=removed_app,- target_url="http://www.example.com/test",- )- webhook.events.create(event_type=WebhookEventAsyncType.ORDER_CREATED)- return webhook---def any_webhook(app):- webhook = Webhook.objects.create(- name="Any webhook", app=app, target_url="http://www.example.com/any"- )- webhook.events.create(event_type=WebhookEventAsyncType.ANY)- return webhook--@pytest.fixturedef fake_payment_interface(mocker):return mocker.Mock(spec=PaymentInterface)@@ -6531,15 +5926,6 @@ def checkout_with_prices(return checkout_with_items-def app_installation():- app_installation = AppInstallation.objects.create(- app_name="External App",- manifest_url="http://localhost:3000/manifest",- )- return app_installation--@pytest.fixturedef user_export_file(staff_user):job = ExportFile.objects.create(user=staff_user)@@ -6797,30 +6183,6 @@ def event_attempt_removed_app(event_delivery_removed_app):)-def webhook_response():- return WebhookResponse(- content="test_content",- request_headers={"headers": "test_request"},- response_headers={"headers": "test_response"},- response_status_code=200,- duration=2.0,- status=EventDeliveryStatus.SUCCESS,- )---def webhook_response_failed():- return WebhookResponse(- content="example_content_response",- request_headers={"headers": "test_request"},- response_headers={"headers": "test_response"},- response_status_code=500,- duration=2.0,- status=EventDeliveryStatus.FAILED,- )--@pytest.fixturedef check_payment_balance_input():return {@@ -7586,326 +6948,6 @@ def setup_mock_for_cache():return _mocked_cache-def setup_checkout_webhooks(- permission_handle_taxes,- permission_manage_shipping,- permission_manage_checkouts,-):- subscription_async_webhooks = """- fragment CheckoutFragment on Checkout {- shippingPrice {- gross {- amount- }- }- totalPrice {- gross {- amount- }- }- }-- subscription {- event {- ... on CheckoutCreated {- checkout {- ...CheckoutFragment- }- }- ... on CheckoutUpdated {- checkout {- ...CheckoutFragment- }- }- ... on CheckoutFullyPaid {- checkout {- ...CheckoutFragment- }- }- ... on CheckoutMetadataUpdated {- checkout {- ...CheckoutFragment- }- }- }- }- """-- def _setup(additional_checkout_event):- tax_app, shipping_app, additional_app = App.objects.bulk_create(- [- App(- name="Sample tax app",- is_active=True,- identifier="saleor.app.tax",- ),- App(- name="Sample shipping app",- is_active=True,- identifier="saleor.app.shipping",- ),- App(- name="Sample async webhook app",- is_active=True,- identifier="saleor.app.additional",- ),- ]- )- tax_app.permissions.add(permission_handle_taxes)- shipping_app.permissions.set(- [permission_manage_shipping, permission_manage_checkouts]- )- additional_app.permissions.add(permission_manage_checkouts)- (- tax_webhook,- shipping_webhook,- shipping_filter_webhook,- additional_webhook,- ) = Webhook.objects.bulk_create(- [- Webhook(- name="Tax webhook",- app=tax_app,- target_url="http://127.0.0.1/test",- subscription_query="subscription{ event{ ...on CalculateTaxes{ __typename } } }",- ),- Webhook(- name="Shipping webhook",- app=shipping_app,- target_url="http://127.0.0.1/test",- subscription_query="subscription { event { ... on ShippingListMethodsForCheckout { __typename } } }",- ),- Webhook(- name="Shipping webhook",- app=shipping_app,- target_url="http://127.0.0.1/test",- subscription_query="subscription { event { ... on CheckoutFilterShippingMethods { __typename } } }",- ),- Webhook(- name="Checkout additional webhook",- app=additional_app,- target_url="http://127.0.0.1/test",- subscription_query=subscription_async_webhooks,- ),- ]- )-- WebhookEvent.objects.bulk_create(- [- WebhookEvent(- event_type=WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,- webhook_id=tax_webhook.id,- ),- WebhookEvent(- event_type=WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,- webhook_id=shipping_filter_webhook.id,- ),- WebhookEvent(- event_type=WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,- webhook_id=shipping_webhook.id,- ),- WebhookEvent(- event_type=additional_checkout_event,- webhook_id=additional_webhook.id,- ),- ]- )- return (- tax_webhook,- shipping_webhook,- shipping_filter_webhook,- additional_webhook,- )-- return _setup---def setup_order_webhooks(- permission_handle_taxes,- permission_manage_shipping,- permission_manage_orders,-):- subscription_async_webhooks = """- fragment OrderFragment on Order {- shippingPrice {- gross {- amount- }- }- total {- gross {- amount- }- }- }-- subscription {- event {- ... on OrderCreated {- order {- ...OrderFragment- }- }- ... on OrderUpdated {- order {- ...OrderFragment- }- }- ... on OrderPaid {- order {- ...OrderFragment- }- }- ... on OrderExpired {- order {- ...OrderFragment- }- }- ... on OrderRefunded {- order {- ...OrderFragment- }- }- ... on OrderConfirmed {- order {- ...OrderFragment- }- }- ... on OrderFullyPaid {- order {- ...OrderFragment- }- }- ... on OrderFulfilled {- order {- ...OrderFragment- }- }- ... on OrderCancelled {- order {- ...OrderFragment- }- }- ... on OrderBulkCreated {- orders {- ...OrderFragment- }- }- ... on OrderFullyRefunded {- order {- ...OrderFragment- }- }- ... on OrderMetadataUpdated {- order {- ...OrderFragment- }- }- ... on DraftOrderCreated {- order {- ...OrderFragment- }- }- ... on DraftOrderUpdated {- order {- ...OrderFragment- }- }- ... on DraftOrderDeleted {- order {- ...OrderFragment- }- }- }- }- """-- def _setup(additional_order_event: Union[str, list[str]]):- tax_app, shipping_app, additional_app = App.objects.bulk_create(- [- App(- name="Sample tax app",- is_active=True,- identifier="saleor.app.tax",- ),- App(- name="Sample shipping app",- is_active=True,- identifier="saleor.app.shipping",- ),- App(- name="Sample async webhook app",- is_active=True,- identifier="saleor.app.additional",- ),- ]- )- tax_app.permissions.add(permission_handle_taxes)- shipping_app.permissions.set(- [permission_manage_shipping, permission_manage_orders]- )- additional_app.permissions.add(permission_manage_orders)- (- tax_webhook,- shipping_filter_webhook,- additional_webhook,- ) = Webhook.objects.bulk_create(- [- Webhook(- name="Tax webhook",- app=tax_app,- target_url="http://127.0.0.1/test",- subscription_query="subscription{ event{ ...on CalculateTaxes{ __typename } } }",- ),- Webhook(- name="Shipping webhook",- app=shipping_app,- target_url="http://127.0.0.1/test",- subscription_query="subscription { event { ... on OrderFilterShippingMethods { __typename } } }",- ),- Webhook(- name="Checkout additional webhook",- app=additional_app,- target_url="http://127.0.0.1/test",- subscription_query=subscription_async_webhooks,- ),- ]- )- if isinstance(additional_order_event, str):- additional_order_event = [- additional_order_event,- ]- additional_events = [- WebhookEvent(- event_type=event,- webhook_id=additional_webhook.id,- )- for event in additional_order_event- ]- WebhookEvent.objects.bulk_create(- [- WebhookEvent(- event_type=WebhookEventSyncType.ORDER_CALCULATE_TAXES,- webhook_id=tax_webhook.id,- ),- WebhookEvent(- event_type=WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,- webhook_id=shipping_filter_webhook.id,- ),- ]- + additional_events- )- return (- tax_webhook,- shipping_filter_webhook,- additional_webhook,- )-- return _setup--@pytest.fixturedef tax_configuration_flat_rates(channel_USD):tc = channel_USD.tax_configurationdiff --git a/saleor/webhook/tests/fixtures/__init__.py b/saleor/webhook/tests/fixtures/__init__.pynew file mode 100644index 0000000000..9444437799--- /dev/null+++ b/saleor/webhook/tests/fixtures/__init__.py@@ -0,0 +1,5 @@+from .subscription_webhooks import * # noqa: F403+from .webhook import * # noqa: F403+from .webhook_data import * # noqa: F403+from .webhook_event import * # noqa: F403+from .webhook_response import * # noqa: F403diff --git a/saleor/webhook/tests/subscription_webhooks/fixtures.py b/saleor/webhook/tests/fixtures/subscription_webhooks.pysimilarity index 99%rename from saleor/webhook/tests/subscription_webhooks/fixtures.pyrename to saleor/webhook/tests/fixtures/subscription_webhooks.pyindex 4f09280657..4f500866b3 100644--- a/saleor/webhook/tests/subscription_webhooks/fixtures.py+++ b/saleor/webhook/tests/fixtures/subscription_webhooks.py@@ -2,7 +2,7 @@ import pytestfrom ...event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ...models import Webhook-from . import subscription_queries as queries+from ..subscription_webhooks import subscription_queries as queries@pytest.fixturediff --git a/saleor/webhook/tests/fixtures/utils.py b/saleor/webhook/tests/fixtures/utils.pynew file mode 100644index 0000000000..28e29532cb--- /dev/null+++ b/saleor/webhook/tests/fixtures/utils.py@@ -0,0 +1,26 @@+from ....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType+from ....webhook.models import WebhookEvent+++def prepare_async_and_sync_events(webhook):+ return [+ WebhookEvent(+ webhook=webhook, event_type=WebhookEventSyncType.PAYMENT_AUTHORIZE+ ),+ WebhookEvent(webhook=webhook, event_type=WebhookEventAsyncType.ANY),+ ]+++def prepare_sync_event(webhook):+ return [+ WebhookEvent(+ webhook=webhook,+ event_type=WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,+ )+ ]+++def prepare_async_event(webhook):+ return [+ WebhookEvent(webhook=webhook, event_type=WebhookEventAsyncType.CHANNEL_CREATED)+ ]diff --git a/saleor/webhook/tests/fixtures/webhook.py b/saleor/webhook/tests/fixtures/webhook.pynew file mode 100644index 0000000000..84d144d163--- /dev/null+++ b/saleor/webhook/tests/fixtures/webhook.py@@ -0,0 +1,396 @@+from typing import Union++import pytest++from ....app.models import App+from ....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType+from ....webhook.models import Webhook, WebhookEvent+++def webhook(app):+ webhook = Webhook.objects.create(+ name="Simple webhook", app=app, target_url="http://www.example.com/test"+ )+ webhook.events.create(event_type=WebhookEventAsyncType.ORDER_CREATED)+ return webhook+++def webhook_without_name(app):+ webhook = Webhook.objects.create(app=app, target_url="http://www.example.com/test")+ webhook.events.create(event_type=WebhookEventAsyncType.ORDER_CREATED)+ return webhook+++def webhook_removed_app(removed_app):+ webhook = Webhook.objects.create(+ name="Removed app webhook",+ app=removed_app,+ target_url="http://www.example.com/test",+ )+ webhook.events.create(event_type=WebhookEventAsyncType.ORDER_CREATED)+ return webhook+++def any_webhook(app):+ webhook = Webhook.objects.create(+ name="Any webhook", app=app, target_url="http://www.example.com/any"+ )+ webhook.events.create(event_type=WebhookEventAsyncType.ANY)+ return webhook+++def observability_webhook(db, permission_manage_observability):+ app = App.objects.create(name="Observability App", is_active=True)+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_observability)++ webhook = Webhook.objects.create(+ name="observability-webhook-1",+ app=app,+ target_url="https://observability-app.com/api/",+ )+ webhook.events.create(event_type=WebhookEventAsyncType.OBSERVABILITY)+ return webhook+++def webhooks_without_events(apps_without_webhooks):+ NUMBER_OF_WEBHOOKS_PER_APP = 6+ webhooks = []++ for app in apps_without_webhooks[:2]:+ for index in range(NUMBER_OF_WEBHOOKS_PER_APP):+ webhook = Webhook(+ name=f"Webhook_{index}",+ app=app,+ target_url=f"http://localhost/test_{index}",+ is_active=index % 2,+ )+ webhooks.append(webhook)++ return Webhook.objects.bulk_create(webhooks)+++def setup_checkout_webhooks(+ permission_handle_taxes,+ permission_manage_shipping,+ permission_manage_checkouts,+):+ subscription_async_webhooks = """+ fragment CheckoutFragment on Checkout {+ shippingPrice {+ gross {+ amount+ }+ }+ totalPrice {+ gross {+ amount+ }+ }+ }++ subscription {+ event {+ ... on CheckoutCreated {+ checkout {+ ...CheckoutFragment+ }+ }+ ... on CheckoutUpdated {+ checkout {+ ...CheckoutFragment+ }+ }+ ... on CheckoutFullyPaid {+ checkout {+ ...CheckoutFragment+ }+ }+ ... on CheckoutMetadataUpdated {+ checkout {+ ...CheckoutFragment+ }+ }+ }+ }+ """++ def _setup(additional_checkout_event):+ tax_app, shipping_app, additional_app = App.objects.bulk_create(+ [+ App(+ name="Sample tax app",+ is_active=True,+ identifier="saleor.app.tax",+ ),+ App(+ name="Sample shipping app",+ is_active=True,+ identifier="saleor.app.shipping",+ ),+ App(+ name="Sample async webhook app",+ is_active=True,+ identifier="saleor.app.additional",+ ),+ ]+ )+ tax_app.permissions.add(permission_handle_taxes)+ shipping_app.permissions.set(+ [permission_manage_shipping, permission_manage_checkouts]+ )+ additional_app.permissions.add(permission_manage_checkouts)+ (+ tax_webhook,+ shipping_webhook,+ shipping_filter_webhook,+ additional_webhook,+ ) = Webhook.objects.bulk_create(+ [+ Webhook(+ name="Tax webhook",+ app=tax_app,+ target_url="http://127.0.0.1/test",+ subscription_query="subscription{ event{ ...on CalculateTaxes{ __typename } } }",+ ),+ Webhook(+ name="Shipping webhook",+ app=shipping_app,+ target_url="http://127.0.0.1/test",+ subscription_query="subscription { event { ... on ShippingListMethodsForCheckout { __typename } } }",+ ),+ Webhook(+ name="Shipping webhook",+ app=shipping_app,+ target_url="http://127.0.0.1/test",+ subscription_query="subscription { event { ... on CheckoutFilterShippingMethods { __typename } } }",+ ),+ Webhook(+ name="Checkout additional webhook",+ app=additional_app,+ target_url="http://127.0.0.1/test",+ subscription_query=subscription_async_webhooks,+ ),+ ]+ )++ WebhookEvent.objects.bulk_create(+ [+ WebhookEvent(+ event_type=WebhookEventSyncType.CHECKOUT_CALCULATE_TAXES,+ webhook_id=tax_webhook.id,+ ),+ WebhookEvent(+ event_type=WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,+ webhook_id=shipping_filter_webhook.id,+ ),+ WebhookEvent(+ event_type=WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,+ webhook_id=shipping_webhook.id,+ ),+ WebhookEvent(+ event_type=additional_checkout_event,+ webhook_id=additional_webhook.id,+ ),+ ]+ )+ return (+ tax_webhook,+ shipping_webhook,+ shipping_filter_webhook,+ additional_webhook,+ )++ return _setup+++def setup_order_webhooks(+ permission_handle_taxes,+ permission_manage_shipping,+ permission_manage_orders,+):+ subscription_async_webhooks = """+ fragment OrderFragment on Order {+ shippingPrice {+ gross {+ amount+ }+ }+ total {+ gross {+ amount+ }+ }+ }++ subscription {+ event {+ ... on OrderCreated {+ order {+ ...OrderFragment+ }+ }+ ... on OrderUpdated {+ order {+ ...OrderFragment+ }+ }+ ... on OrderPaid {+ order {+ ...OrderFragment+ }+ }+ ... on OrderExpired {+ order {+ ...OrderFragment+ }+ }+ ... on OrderRefunded {+ order {+ ...OrderFragment+ }+ }+ ... on OrderConfirmed {+ order {+ ...OrderFragment+ }+ }+ ... on OrderFullyPaid {+ order {+ ...OrderFragment+ }+ }+ ... on OrderFulfilled {+ order {+ ...OrderFragment+ }+ }+ ... on OrderCancelled {+ order {+ ...OrderFragment+ }+ }+ ... on OrderBulkCreated {+ orders {+ ...OrderFragment+ }+ }+ ... on OrderFullyRefunded {+ order {+ ...OrderFragment+ }+ }+ ... on OrderMetadataUpdated {+ order {+ ...OrderFragment+ }+ }+ ... on DraftOrderCreated {+ order {+ ...OrderFragment+ }+ }+ ... on DraftOrderUpdated {+ order {+ ...OrderFragment+ }+ }+ ... on DraftOrderDeleted {+ order {+ ...OrderFragment+ }+ }+ }+ }+ """++ def _setup(additional_order_event: Union[str, list[str]]):+ tax_app, shipping_app, additional_app = App.objects.bulk_create(+ [+ App(+ name="Sample tax app",+ is_active=True,+ identifier="saleor.app.tax",+ ),+ App(+ name="Sample shipping app",+ is_active=True,+ identifier="saleor.app.shipping",+ ),+ App(+ name="Sample async webhook app",+ is_active=True,+ identifier="saleor.app.additional",+ ),+ ]+ )+ tax_app.permissions.add(permission_handle_taxes)+ shipping_app.permissions.set(+ [permission_manage_shipping, permission_manage_orders]+ )+ additional_app.permissions.add(permission_manage_orders)+ (+ tax_webhook,+ shipping_filter_webhook,+ additional_webhook,+ ) = Webhook.objects.bulk_create(+ [+ Webhook(+ name="Tax webhook",+ app=tax_app,+ target_url="http://127.0.0.1/test",+ subscription_query="subscription{ event{ ...on CalculateTaxes{ __typename } } }",+ ),+ Webhook(+ name="Shipping webhook",+ app=shipping_app,+ target_url="http://127.0.0.1/test",+ subscription_query="subscription { event { ... on OrderFilterShippingMethods { __typename } } }",+ ),+ Webhook(+ name="Checkout additional webhook",+ app=additional_app,+ target_url="http://127.0.0.1/test",+ subscription_query=subscription_async_webhooks,+ ),+ ]+ )+ if isinstance(additional_order_event, str):+ additional_order_event = [+ additional_order_event,+ ]+ additional_events = [+ WebhookEvent(+ event_type=event,+ webhook_id=additional_webhook.id,+ )+ for event in additional_order_event+ ]+ WebhookEvent.objects.bulk_create(+ [+ WebhookEvent(+ event_type=WebhookEventSyncType.ORDER_CALCULATE_TAXES,+ webhook_id=tax_webhook.id,+ ),+ WebhookEvent(+ event_type=WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,+ webhook_id=shipping_filter_webhook.id,+ ),+ ]+ + additional_events+ )+ return (+ tax_webhook,+ shipping_filter_webhook,+ additional_webhook,+ )++ return _setupdiff --git a/saleor/webhook/tests/fixtures/webhook_data.py b/saleor/webhook/tests/fixtures/webhook_data.pynew file mode 100644index 0000000000..78e0f62427--- /dev/null+++ b/saleor/webhook/tests/fixtures/webhook_data.py@@ -0,0 +1,13 @@+import pytest++from ....webhook.observability import WebhookData+++def observability_webhook_data(observability_webhook):+ return WebhookData(+ id=observability_webhook.id,+ saleor_domain="mirumee.com",+ target_url=observability_webhook.target_url,+ secret_key=observability_webhook.secret_key,+ )diff --git a/saleor/webhook/tests/fixtures/webhook_event.py b/saleor/webhook/tests/fixtures/webhook_event.pynew file mode 100644index 0000000000..4a270d892c--- /dev/null+++ b/saleor/webhook/tests/fixtures/webhook_event.py@@ -0,0 +1,33 @@+from itertools import cycle++import pytest++from ....webhook.models import WebhookEvent+from .utils import (+ prepare_async_and_sync_events,+ prepare_async_event,+ prepare_sync_event,+)+++def events_cycle():+ return cycle(+ (+ prepare_async_and_sync_events,+ prepare_sync_event,+ prepare_async_event,+ lambda x: [],+ lambda x: [],+ )+ )+++def webhook_events(webhooks_without_events, events_cycle):+ webhook_events = []++ for webhook in webhooks_without_events:+ webhook_events.extend(next(events_cycle)(webhook))++ return WebhookEvent.objects.bulk_create(webhook_events)diff --git a/saleor/webhook/tests/fixtures/webhook_response.py b/saleor/webhook/tests/fixtures/webhook_response.pynew file mode 100644index 0000000000..b6aa852f55--- /dev/null+++ b/saleor/webhook/tests/fixtures/webhook_response.py@@ -0,0 +1,28 @@+import pytest++from ....core import EventDeliveryStatus+from ....webhook.transport.utils import WebhookResponse+++def webhook_response():+ return WebhookResponse(+ content="test_content",+ request_headers={"headers": "test_request"},+ response_headers={"headers": "test_response"},+ response_status_code=200,+ duration=2.0,+ status=EventDeliveryStatus.SUCCESS,+ )+++def webhook_response_failed():+ return WebhookResponse(+ content="example_content_response",+ request_headers={"headers": "test_request"},+ response_headers={"headers": "test_response"},+ response_status_code=500,+ duration=2.0,+ status=EventDeliveryStatus.FAILED,+ )diff --git a/saleor/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/webhook/tests/subscription_webhooks/subscription_queries.pyindex 751d711d77..63a007fa2f 100644--- a/saleor/webhook/tests/subscription_webhooks/subscription_queries.py+++ b/saleor/webhook/tests/subscription_webhooks/subscription_queries.py@@ -2055,6 +2055,125 @@ subscription {}"""+CALCULATE_TAXES_SUBSCRIPTION_QUERY = """+subscription CalculateTaxes {+ event {+ ...CalculateTaxesEvent+ }+}++fragment CalculateTaxesEvent on Event {+ __typename+ ... on CalculateTaxes {+ taxBase {+ ...TaxBase+ }+ recipient {+ privateMetadata {+ key+ value+ }+ }+ }+}++fragment TaxBase on TaxableObject {+ pricesEnteredWithTax+ currency+ channel {+ slug+ }+ discounts {+ ...TaxDiscount+ }+ address {+ ...Address+ }+ shippingPrice {+ amount+ }+ lines {+ ...TaxBaseLine+ }+ sourceObject {+ __typename+ ... on Checkout {+ avataxEntityCode: metafield(key: "avataxEntityCode")+ user {+ ...User+ }+ }+ ... on Order {+ avataxEntityCode: metafield(key: "avataxEntityCode")+ user {+ ...User+ }+ }+ }+}++fragment TaxDiscount on TaxableObjectDiscount {+ name+ amount {+ amount+ }+}++fragment Address on Address {+ streetAddress1+ streetAddress2+ city+ countryArea+ postalCode+ country {+ code+ }+}++fragment TaxBaseLine on TaxableObjectLine {+ sourceLine {+ __typename+ ... on CheckoutLine {+ id+ checkoutProductVariant: variant {+ id+ product {+ taxClass {+ id+ name+ }+ }+ }+ }+ ... on OrderLine {+ id+ orderProductVariant: variant {+ id+ product {+ taxClass {+ id+ name+ }+ }+ }+ }+ }+ quantity+ unitPrice {+ amount+ }+ totalPrice {+ amount+ }+}++fragment User on User {+ id+ avataxCustomerCode: metafield(key: "avataxCustomerCode")+}+"""+TranslationTypes = Enum("TranslationTypes",{