Skip to content

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

Add test for translate attribute value query

fowczarek145f87dc5bd7
diff --git a/tests/api/test_translations.py b/tests/api/test_translations.py
index fd659f5287..ca82c94db7 100644
--- a/tests/api/test_translations.py
+++ b/tests/api/test_translations.py
@@ -1576,3 +1576,52 @@ def test_translation_query_attribute(
assert data["name"] == attribute.name
assert data["translation"]["name"] == translated_attribute.name
assert data["attribute"]["name"] == attribute.name
+
+
+QUERY_TRANSLATION_ATTRIBUTE_VALUE = """
+ query translation(
+ $kind: TranslatableKinds!, $id: ID!, $languageCode: LanguageCodeEnum!
+ ){
+ translation(kind: $kind, id: $id){
+ __typename
+ ...on AttributeValueStrings{
+ id
+ name
+ translation(languageCode: $languageCode){
+ name
+ }
+ attributeValue {
+ id
+ name
+ }
+ }
+ }
+ }
+"""
+
+
+def test_translation_query_attribute_value(
+ staff_api_client,
+ pink_attribute_value,
+ translated_attribute_value,
+ permission_manage_translations,
+):
+ attribute_value_id = graphene.Node.to_global_id(
+ "AttributeValue", pink_attribute_value.id
+ )
+
+ variables = {
+ "id": attribute_value_id,
+ "kind": TranslatableKinds.ATTRIBUTE_VALUE.name,
+ "languageCode": LanguageCodeEnum.FR.name,
+ }
+ response = staff_api_client.post_graphql(
+ QUERY_TRANSLATION_ATTRIBUTE_VALUE,
+ variables,
+ permissions=[permission_manage_translations],
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["translation"]
+ assert data["name"] == pink_attribute_value.name
+ assert data["translation"]["name"] == translated_attribute_value.name
+ assert data["attributeValue"]["name"] == pink_attribute_value.name
diff --git a/tests/conftest.py b/tests/conftest.py
index 218cfc4c3d..540c4ec535 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -39,6 +39,7 @@ from saleor.product.models import (
Attribute,
AttributeTranslation,
AttributeValue,
+ AttributeValueTranslation,
Category,
CategoryTranslation,
Collection,
@@ -1268,7 +1269,16 @@ def translated_variant_fr(product):
def translated_attribute(product):
attribute = product.product_type.product_attributes.first()
return AttributeTranslation.objects.create(
- language_code="fr", attribute=attribute, name="Name tranlsated to french"
+ language_code="fr", attribute=attribute, name="French attribute name"
+ )
+
+
+def translated_attribute_value(pink_attribute_value):
+ return AttributeValueTranslation.objects.create(
+ language_code="fr",
+ attribute_value=pink_attribute_value,
+ name="French attribute value name",
)