Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
tests
Tomasz Magulski4d2b8caaa478
diff --git a/saleor/app/tests/test_installation_utils.py b/saleor/app/tests/test_installation_utils.pyindex d5984cb21a..049343b44c 100644--- a/saleor/app/tests/test_installation_utils.py+++ b/saleor/app/tests/test_installation_utils.py@@ -216,3 +216,84 @@ def test_install_app_extension_incorrect_values(# when & thenwith pytest.raises(ValidationError):install_app(app_installation, activate=True)+++def test_install_app_with_webhook(+ app_manifest, app_manifest_webhook, app_installation, monkeypatch+):+ # given+ app_manifest["webhooks"] = [app_manifest_webhook]++ mocked_get_response = Mock()+ mocked_get_response.json.return_value = app_manifest+ monkeypatch.setattr(requests, "get", Mock(return_value=mocked_get_response))+ monkeypatch.setattr("saleor.app.installation_utils.send_app_token", Mock())++ # when+ app, _ = install_app(app_installation, activate=True)++ # then+ assert app.id == App.objects.get().id++ webhook = app.webhooks.get()+ assert webhook.name == app_manifest_webhook["name"]+ assert sorted(webhook.events.values_list("event_type", flat=True)) == sorted(+ app_manifest_webhook["events"]+ )+ assert webhook.subscription_query == app_manifest_webhook["query"]+ assert webhook.target_url == app_manifest_webhook["targetUrl"]+ assert webhook.is_active == app_manifest_webhook["isActive"]+++def test_install_app_webhook_incorrect_url(+ app_manifest, app_manifest_webhook, app_installation, monkeypatch+):+ # given+ app_manifest_webhook["targetUrl"] = "ftp://user:[email protected]/deep/cover"+ app_manifest["webhooks"] = [app_manifest_webhook]++ mocked_get_response = Mock()+ mocked_get_response.json.return_value = app_manifest+ monkeypatch.setattr(requests, "get", Mock(return_value=mocked_get_response))++ # when & then+ with pytest.raises(ValidationError) as excinfo:+ install_app(app_installation, activate=True)++ error_dict = excinfo.value.error_dict+ assert "target_url" in error_dict+ assert error_dict["target_url"][0].message == "Enter a valid URL."+++def test_install_app_webhook_incorrect_query(+ app_manifest, app_manifest_webhook, app_installation, monkeypatch+):+ # given+ app_manifest_webhook[+ "query"+ ] = """+ no {+ that's {+ not {+ ... on a {+ valid graphql {+ query+ }+ }+ }+ }+ }+ """+ app_manifest["webhooks"] = [app_manifest_webhook]++ mocked_get_response = Mock()+ mocked_get_response.json.return_value = app_manifest+ monkeypatch.setattr(requests, "get", Mock(return_value=mocked_get_response))++ # when & then+ with pytest.raises(ValidationError) as excinfo:+ install_app(app_installation, activate=True)++ error_dict = excinfo.value.error_dict+ assert "query" in error_dict+ assert error_dict["query"][0].message == "Subscription query is not valid"diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex 72c9514ee5..3564e94d89 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -5699,6 +5699,47 @@ def app_manifest():}+def app_manifest_webhook():+ return {+ "name": "webhook",+ "events": [+ "ORDER_CREATED",+ "ORDER_FULLY_PAID",+ "CUSTOMER_CREATED",+ "FULFILLMENT_CREATED",+ ],+ "query": """+ subscription {+ event {+ ... on OrderCreated {+ order {+ id+ }+ }+ ... on OrderFullyPaid {+ order {+ id+ }+ }+ ... on CustomerCreated {+ user {+ id+ }+ }+ ... on FulfillmentCreated {+ fulfillment {+ id+ }+ }+ }+ }+ """,+ "targetUrl": "https://app.example/api/webhook",+ "isActive": True,+ }++@pytest.fixturedef event_payload():"""Return event payload."""