Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add missing translation resolvers (#6844)
Damian Wysockiad74072b8171
diff --git a/saleor/graphql/translations/tests/test_translations.py b/saleor/graphql/translations/tests/test_translations.pyindex d211db31a6..83811bfaf9 100644--- a/saleor/graphql/translations/tests/test_translations.py+++ b/saleor/graphql/translations/tests/test_translations.py@@ -2,19 +2,25 @@ import grapheneimport pytestfrom django.contrib.auth.models import Permission+from ....tests.utils import dummy_editorjsfrom ...tests.utils import assert_no_permission, get_graphql_contentfrom ..schema import TranslatableKindsfrom ..types import LanguageCodeEnumdef test_product_translation(user_api_client, product, channel_USD):- product.translations.create(language_code="pl", name="Produkt")+ description = dummy_editorjs("test desription")+ product.translations.create(+ language_code="pl", name="Produkt", description=description+ )query = """query productById($productId: ID!, $channel: String) {product(id: $productId, channel: $channel) {translation(languageCode: PL) {name+ description+ descriptionJsonlanguage {code}@@ -29,8 +35,14 @@ def test_product_translation(user_api_client, product, channel_USD):)data = get_graphql_content(response)["data"]- assert data["product"]["translation"]["name"] == "Produkt"- assert data["product"]["translation"]["language"]["code"] == "PL"+ translation_data = data["product"]["translation"]+ assert translation_data["name"] == "Produkt"+ assert translation_data["language"]["code"] == "PL"+ assert (+ translation_data["description"]+ == translation_data["descriptionJson"]+ == dummy_editorjs("test desription", json_format=True)+ )def test_product_translation_with_app(app_api_client, product, channel_USD):@@ -86,13 +98,18 @@ def test_product_variant_translation(user_api_client, variant, channel_USD):def test_collection_translation(user_api_client, published_collection, channel_USD):- published_collection.translations.create(language_code="pl", name="Kolekcja")+ description = dummy_editorjs("test desription")+ published_collection.translations.create(+ language_code="pl", name="Kolekcja", description=description+ )query = """query collectionById($collectionId: ID!, $channel: String) {collection(id: $collectionId, channel: $channel) {translation(languageCode: PL) {name+ description+ descriptionJsonlanguage {code}@@ -106,8 +123,14 @@ def test_collection_translation(user_api_client, published_collection, channel_Uresponse = user_api_client.post_graphql(query, variables)data = get_graphql_content(response)["data"]- assert data["collection"]["translation"]["name"] == "Kolekcja"- assert data["collection"]["translation"]["language"]["code"] == "PL"+ translation_data = data["collection"]["translation"]+ assert translation_data["name"] == "Kolekcja"+ assert translation_data["language"]["code"] == "PL"+ assert (+ translation_data["description"]+ == translation_data["descriptionJson"]+ == dummy_editorjs("test desription", json_format=True)+ )def test_category_translation(user_api_client, category):@@ -187,13 +210,16 @@ def test_sale_translation(staff_api_client, sale, permission_manage_discounts):def test_page_translation(user_api_client, page):- page.translations.create(language_code="pl", title="Strona")+ content = dummy_editorjs("test content")+ page.translations.create(language_code="pl", title="Strona", content=content)query = """query pageById($pageId: ID!) {page(id: $pageId) {translation(languageCode: PL) {title+ content+ contentJsonlanguage {code}@@ -206,8 +232,14 @@ def test_page_translation(user_api_client, page):response = user_api_client.post_graphql(query, {"pageId": page_id})data = get_graphql_content(response)["data"]- assert data["page"]["translation"]["title"] == "Strona"- assert data["page"]["translation"]["language"]["code"] == "PL"+ translation_data = data["page"]["translation"]+ assert translation_data["title"] == "Strona"+ assert translation_data["language"]["code"] == "PL"+ assert (+ translation_data["content"]+ == translation_data["contentJson"]+ == dummy_editorjs("test content", json_format=True)+ )def test_attribute_translation(user_api_client, color_attribute):diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.pyindex 1ddebb9170..44afb864f4 100644--- a/saleor/graphql/translations/types.py+++ b/saleor/graphql/translations/types.py@@ -141,6 +141,10 @@ class ProductTranslation(BaseTranslationType):interfaces = [graphene.relay.Node]only_fields = EXTENDED_TRANSLATABLE_FIELDS+ @staticmethod+ def resolve_description_json(root: product_models.ProductTranslation, _info):+ return root.description+class ProductTranslatableContent(CountableDjangoObjectType):description_json = graphene.JSONString(@@ -164,6 +168,10 @@ class ProductTranslatableContent(CountableDjangoObjectType):def resolve_product(root: product_models.Product, info):return ChannelContext(node=root, channel_slug=None)+ @staticmethod+ def resolve_description_json(root: product_models.Product, _info):+ return root.description+class CollectionTranslation(BaseTranslationType):description_json = graphene.JSONString(@@ -178,6 +186,10 @@ class CollectionTranslation(BaseTranslationType):interfaces = [graphene.relay.Node]only_fields = EXTENDED_TRANSLATABLE_FIELDS+ @staticmethod+ def resolve_description_json(root: product_models.CollectionTranslation, _info):+ return root.description+class CollectionTranslatableContent(CountableDjangoObjectType):description_json = graphene.JSONString(@@ -204,6 +216,10 @@ class CollectionTranslatableContent(CountableDjangoObjectType):ChannelContext(node=collection, channel_slug=None) if collection else None)+ @staticmethod+ def resolve_description_json(root: product_models.Collection, _info):+ return root.description+class CategoryTranslation(BaseTranslationType):description_json = graphene.JSONString(@@ -218,6 +234,10 @@ class CategoryTranslation(BaseTranslationType):interfaces = [graphene.relay.Node]only_fields = EXTENDED_TRANSLATABLE_FIELDS+ @staticmethod+ def resolve_description_json(root: product_models.CategoryTranslation, _info):+ return root.description+class CategoryTranslatableContent(CountableDjangoObjectType):description_json = graphene.JSONString(@@ -241,6 +261,10 @@ class CategoryTranslatableContent(CountableDjangoObjectType):def resolve_category(root: product_models.Category, _info):return root+ @staticmethod+ def resolve_description_json(root: product_models.Category, _info):+ return root.description+class PageTranslation(BaseTranslationType):content_json = graphene.JSONString(@@ -261,6 +285,10 @@ class PageTranslation(BaseTranslationType):"title",]+ @staticmethod+ def resolve_content_json(root: page_models.PageTranslation, _info):+ return root.content+class PageTranslatableContent(CountableDjangoObjectType):content_json = graphene.JSONString(@@ -297,6 +325,10 @@ class PageTranslatableContent(CountableDjangoObjectType):.first())+ @staticmethod+ def resolve_description_json(root: page_models.Page, _info):+ return root.content+class VoucherTranslation(BaseTranslationType):class Meta: