Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix failing payload for variant-stock-updated (#16627)

Maciej Korycinski4257c98ef540
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 0f3f0dc752..96746c2edd 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -1877,8 +1877,8 @@ class WebhookPlugin(BasePlugin):
return previous_value
event_type = WebhookEventAsyncType.PRODUCT_VARIANT_STOCK_UPDATED
if webhooks := self._get_webhooks_for_event(event_type, webhooks):
- product_variant_data_generator = (
- generate_product_variant_with_stock_payload([stock], self.requestor)
+ product_variant_data_generator = partial(
+ generate_product_variant_with_stock_payload, [stock], self.requestor
)
self.trigger_webhooks_async(
None,
diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.py
index 877d9dfbdb..1d3f3e3aec 100644
--- a/saleor/plugins/webhook/tests/test_webhook.py
+++ b/saleor/plugins/webhook/tests/test_webhook.py
@@ -867,6 +867,7 @@ def test_product_variant_out_of_stock(
legacy_data_generator=ANY,
allow_replica=False,
)
+ assert callable(mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"])
assert isinstance(
mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"], partial
)
@@ -896,6 +897,38 @@ def test_product_variant_back_in_stock(
legacy_data_generator=ANY,
allow_replica=False,
)
+ assert callable(mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"])
+ assert isinstance(
+ mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"], partial
+ )
+
+
+@freeze_time("2014-06-28 10:50")
[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")
[email protected]("saleor.plugins.webhook.plugin.trigger_webhooks_async")
+def test_product_variant_stock_updated(
+ mocked_webhook_trigger,
+ mocked_get_webhooks_for_event,
+ any_webhook,
+ settings,
+ variant_with_many_stocks,
+):
+ variant = variant_with_many_stocks.stocks.first()
+ mocked_get_webhooks_for_event.return_value = [any_webhook]
+ settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]
+ manager = get_plugins_manager(allow_replica=False)
+ manager.product_variant_stock_updated(variant)
+
+ mocked_webhook_trigger.assert_called_once_with(
+ None,
+ WebhookEventAsyncType.PRODUCT_VARIANT_STOCK_UPDATED,
+ [any_webhook],
+ variant,
+ None,
+ legacy_data_generator=ANY,
+ allow_replica=False,
+ )
+ assert callable(mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"])
assert isinstance(
mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"], partial
)