Skip to content

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

Add test for translate sale query

fowczarek5e8c61dae636
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index 7544986387..48faddffeb 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -150,11 +150,9 @@ class TranslationQueries(graphene.ObjectType):
return ProductVariant.objects.filter(pk=kind_id).first()
elif kind == TranslatableKinds.PAGE:
return Page.objects.filter(pk=kind_id).first()
- # TODO test data not visible without perms
# TODO No dashbord options to create translation create issue
elif kind == TranslatableKinds.SHIPPING_METHOD:
return ShippingMethod.objects.filter(pk=kind_id).first()
- # TODO test data not visible without perms
elif kind == TranslatableKinds.SALE:
return Sale.objects.filter(pk=kind_id).first()
# TODO test data not visible without perms
diff --git a/tests/api/test_translations.py b/tests/api/test_translations.py
index ba1d52afb8..85b70b349a 100644
--- a/tests/api/test_translations.py
+++ b/tests/api/test_translations.py
@@ -1809,3 +1809,56 @@ def test_translation_query_shipping_method(
assert data["shippingMethod"]["name"] == shipping_method.name
else:
assert not data["shippingMethod"]
+
+
+QUERY_TRANSLATION_SALE = """
+ query translation(
+ $kind: TranslatableKinds!, $id: ID!, $languageCode: LanguageCodeEnum!
+ ){
+ translation(kind: $kind, id: $id){
+ __typename
+ ...on SaleStrings{
+ id
+ name
+ translation(languageCode: $languageCode){
+ name
+ }
+ sale {
+ id
+ name
+ }
+ }
+ }
+ }
+"""
+
+
+ "perm_codenames, return_sale",
+ [
+ (["manage_translations"], False),
+ (["manage_translations", "manage_discounts"], True),
+ ],
+)
+def test_translation_query_sale(
+ staff_api_client, sale, sale_translation_fr, perm_codenames, return_sale
+):
+ sale_id = graphene.Node.to_global_id("Sale", sale.id)
+ perms = list(Permission.objects.filter(codename__in=perm_codenames))
+
+ variables = {
+ "id": sale_id,
+ "kind": TranslatableKinds.SALE.name,
+ "languageCode": LanguageCodeEnum.FR.name,
+ }
+ response = staff_api_client.post_graphql(
+ QUERY_TRANSLATION_SALE, variables, permissions=perms
+ )
+ content = get_graphql_content(response, ignore_errors=True)
+ data = content["data"]["translation"]
+ assert data["name"] == sale.name
+ assert data["translation"]["name"] == sale_translation_fr.name
+ if return_sale:
+ assert data["sale"]["name"] == sale.name
+ else:
+ assert not data["sale"]
diff --git a/tests/conftest.py b/tests/conftest.py
index 7bac8e9bcd..3f4a060f96 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -22,7 +22,13 @@ from saleor.checkout.models import Checkout
from saleor.checkout.utils import add_variant_to_checkout
from saleor.core.payments import PaymentInterface
from saleor.discount import DiscountInfo, DiscountValueType, VoucherType
-from saleor.discount.models import Sale, Voucher, VoucherCustomer, VoucherTranslation
+from saleor.discount.models import (
+ Sale,
+ SaleTranslation,
+ Voucher,
+ VoucherCustomer,
+ VoucherTranslation,
+)
from saleor.giftcard.models import GiftCard
from saleor.menu.models import Menu, MenuItem
from saleor.menu.utils import update_menu
@@ -1351,6 +1357,13 @@ def shipping_method_translation_fr(shipping_method):
)
+def sale_translation_fr(sale):
+ return SaleTranslation.objects.create(
+ language_code="fr", sale=sale, name="French sale name"
+ )
+
+
@pytest.fixture
def payment_dummy(db, order_with_lines):
return Payment.objects.create(