Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for translate collection query
fowczarek3d7c1043168d
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.pyindex aebe16709a..bbbdf6c821 100644--- a/saleor/graphql/translations/schema.py+++ b/saleor/graphql/translations/schema.py@@ -138,7 +138,7 @@ class TranslationQueries(graphene.ObjectType):_type, kind_id = graphene.Node.from_global_id(id)if kind == TranslatableKinds.PRODUCT:return Product.objects.filter(pk=kind_id).first()- elif kind == TranslatableKinds.COLLECTION: # TODO test hidden data+ elif kind == TranslatableKinds.COLLECTION:return Collection.objects.filter(pk=kind_id).first()elif kind == TranslatableKinds.CATEGORY:return Category.objects.filter(pk=kind_id).first()diff --git a/tests/api/test_translations.py b/tests/api/test_translations.pyindex 82f9929c9a..6b7364771b 100644--- a/tests/api/test_translations.py+++ b/tests/api/test_translations.py@@ -1425,3 +1425,65 @@ def test_translation_query_product(assert data["product"]["name"] == product.nameelse:assert not data["product"]+++QUERY_TRANSLATION_COLLECTION = """+ query translation(+ $kind: TranslatableKinds!, $id: ID!, $languageCode: LanguageCodeEnum!+ ){+ translation(kind: $kind, id: $id){+ __typename+ ...on CollectionStrings{+ id+ name+ translation(languageCode: $languageCode){+ name+ }+ collection{+ id+ name+ }+ }+ }+ }+"""+++ "is_published, perm_codenames, return_product",+ [+ (True, ["manage_translations"], True),+ (False, ["manage_translations"], False),+ (False, ["manage_translations", "manage_products"], True),+ ],+)+def test_translation_query_collection(+ staff_api_client,+ collection,+ collection_translation_fr,+ is_published,+ perm_codenames,+ return_product,+):+ collection.is_published = is_published+ collection.save()++ collection_id = graphene.Node.to_global_id("Collection", collection.id)+ perms = list(Permission.objects.filter(codename__in=perm_codenames))++ variables = {+ "id": collection_id,+ "kind": TranslatableKinds.COLLECTION.name,+ "languageCode": LanguageCodeEnum.FR.name,+ }+ response = staff_api_client.post_graphql(+ QUERY_TRANSLATION_COLLECTION, variables, permissions=perms+ )+ content = get_graphql_content(response)+ data = content["data"]["translation"]+ assert data["name"] == collection.name+ assert data["translation"]["name"] == collection_translation_fr.name+ if return_product:+ assert data["collection"]["name"] == collection.name+ else:+ assert not data["collection"]diff --git a/tests/conftest.py b/tests/conftest.pyindex 26bcd52a6b..450a91c6fe 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -41,6 +41,7 @@ from saleor.product.models import (AttributeValue,Category,Collection,+ CollectionTranslation,DigitalContent,DigitalContentUrl,Product,@@ -1287,6 +1288,16 @@ def product_translation_fr(product):)+def collection_translation_fr(collection):+ return CollectionTranslation.objects.create(+ language_code="fr",+ collection=collection,+ name="French collection name",+ description="French description",+ )++@pytest.fixturedef payment_dummy(db, order_with_lines):return Payment.objects.create(