Skip to content

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

Change AppError to more meaningfull. Add test to cover missing part of fetching data

Maciej Korycinskidaab10a324cf
diff --git a/saleor/app/error_codes.py b/saleor/app/error_codes.py
index ebbace2a9e..dd79d64984 100644
--- a/saleor/app/error_codes.py
+++ b/saleor/app/error_codes.py
@@ -7,7 +7,7 @@ class AppErrorCode(Enum):
INVALID = "invalid"
INVALID_STATUS = "invalid_status"
INVALID_PERMISSION = "invalid_permission"
- INVALID_MANIFEST_URL = "invalid_manifest_url"
+ INVALID_URL_FORMAT = "invalid_url_format"
INVALID_MANIFEST_FORMAT = "invalid_manifest_format"
MANIFEST_URL_CANT_CONNECT = "manifest_url_cant_connect"
NOT_FOUND = "not_found"
diff --git a/saleor/graphql/app/mutations.py b/saleor/graphql/app/mutations.py
index 6541bb7103..0506fef0ec 100644
--- a/saleor/graphql/app/mutations.py
+++ b/saleor/graphql/app/mutations.py
@@ -393,7 +393,7 @@ class AppInstall(ModelMutation):
url_validator(url)
except (ValidationError, AttributeError):
msg = "Enter a valid URL."
- code = AppErrorCode.INVALID_MANIFEST_URL.value
+ code = AppErrorCode.INVALID_URL_FORMAT.value
raise ValidationError({"manifest_url": ValidationError(msg, code=code)})
@classmethod
@@ -450,7 +450,7 @@ class AppFetchManifest(BaseMutation):
raise ValidationError({"manifest_url": ValidationError(msg, code=code)})
except Exception:
msg = "Can't fetch manifest data. Please try later."
- code = AppErrorCode.INVALID.valuer
+ code = AppErrorCode.INVALID.value
raise ValidationError({"manifest_url": ValidationError(msg, code=code)})
@classmethod
@@ -460,7 +460,7 @@ class AppFetchManifest(BaseMutation):
url_validator(manifest_url)
except (ValidationError, AttributeError):
msg = "Enter a valid URL."
- code = AppErrorCode.INVALID_MANIFEST_URL.value
+ code = AppErrorCode.INVALID_URL_FORMAT.value
raise ValidationError({"manifest_url": ValidationError(msg, code=code)})
@classmethod
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index a17fa683f5..4ad0f4c2a7 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -268,7 +268,7 @@ enum AppErrorCode {
INVALID
INVALID_STATUS
INVALID_PERMISSION
- INVALID_MANIFEST_URL
+ INVALID_URL_FORMAT
INVALID_MANIFEST_FORMAT
MANIFEST_URL_CANT_CONNECT
NOT_FOUND
diff --git a/tests/api/app/mutations/test_app_fetch_manifest.py b/tests/api/app/mutations/test_app_fetch_manifest.py
index 50dd99a4c3..b416cfa6af 100644
--- a/tests/api/app/mutations/test_app_fetch_manifest.py
+++ b/tests/api/app/mutations/test_app_fetch_manifest.py
@@ -1,4 +1,7 @@
+from unittest.mock import Mock
+
import pytest
+import requests
from tests.api.utils import assert_no_permission, get_graphql_content
@@ -136,3 +139,28 @@ def test_app_fetch_manifest_wrong_format_of_response(
"message": "Incorrect structure of manifest.",
"code": "INVALID_MANIFEST_FORMAT",
}
+
+
+def test_app_fetch_manifest_handle_exception(
+ staff_user, staff_api_client, permission_manage_apps, monkeypatch
+):
+ mocked_get = Mock()
+ mocked_get.side_effect = Exception()
+
+ monkeypatch.setattr(requests, "get", mocked_get)
+ manifest_url = "http://localhost:3000/manifest-wrong-format"
+ query = APP_FETCH_MANIFEST_MUTATION
+ variables = {
+ "manifest_url": manifest_url,
+ }
+ staff_user.user_permissions.set([permission_manage_apps])
+ response = staff_api_client.post_graphql(query, variables=variables,)
+ content = get_graphql_content(response)
+ errors = content["data"]["appFetchManifest"]["appErrors"]
+
+ assert len(errors) == 1
+ assert errors[0] == {
+ "code": "INVALID",
+ "field": "manifestUrl",
+ "message": "Can't fetch manifest data. Please try later.",
+ }