forked from saleor/saleor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_translation.py
127 lines (93 loc) · 4.42 KB
/
test_translation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import pytest
from saleor.product.models import (
AttributeTranslation, AttributeValueTranslation, CategoryTranslation,
CollectionTranslation, ProductTranslation, ProductVariantTranslation)
from saleor.shipping.models import ShippingMethodTranslation
@pytest.fixture
def product_translation_pl(product):
return ProductTranslation.objects.create(
language_code='pl', product=product, name='Polish name',
description="Polish description")
@pytest.fixture
def attribute_value_translation_fr(translated_attribute):
value = translated_attribute.attribute.values.first()
return AttributeValueTranslation.objects.create(
language_code='fr', attribute_value=value,
name='French name')
@pytest.fixture
def shipping_method_translation_fr(shipping_method):
return ShippingMethodTranslation.objects.create(
language_code='fr', shipping_method=shipping_method,
name='French name')
def test_translation(product, settings, product_translation_fr):
assert product.translated.name == 'Test product'
assert not product.translated.description
settings.LANGUAGE_CODE = 'fr'
assert product.translated.name == 'French name'
assert product.translated.description == 'French description'
def test_translation_str_returns_str_of_instance(
product, product_translation_fr, settings):
assert str(product.translated) == str(product)
settings.LANGUAGE_CODE = 'fr'
assert str(
product.translated.translation) == str(product_translation_fr)
def test_wrapper_gets_proper_wrapper(
product, product_translation_fr, settings, product_translation_pl):
assert product.translated.translation is None
settings.LANGUAGE_CODE = 'fr'
assert product.translated.translation == product_translation_fr
settings.LANGUAGE_CODE = 'pl'
assert product.translated.translation == product_translation_pl
def test_getattr(
product, settings, product_translation_fr, product_type):
settings.LANGUAGE_CODE = 'fr'
assert product.translated.product_type == product_type
def test_translation_not_override_id(
settings, product, product_translation_fr):
settings.LANGUAGE_CODE = 'fr'
translated_product = product.translated
assert translated_product.id == product.id
assert not translated_product.id == product_translation_fr
def test_collection_translation(settings, collection):
settings.LANGUAGE_CODE = 'fr'
french_name = 'French name'
CollectionTranslation.objects.create(
language_code='fr', name=french_name, collection=collection)
assert collection.translated.name == french_name
def test_category_translation(settings, category):
settings.LANGUAGE_CODE = 'fr'
french_name = 'French name'
french_description = 'French description'
CategoryTranslation.objects.create(
language_code='fr', name=french_name, description=french_description,
category=category)
assert category.translated.name == french_name
assert category.translated.description == french_description
def test_product_variant_translation(settings, variant):
settings.LANGUAGE_CODE = 'fr'
french_name = 'French name'
ProductVariantTranslation.objects.create(
language_code='fr', name=french_name, product_variant=variant)
assert variant.translated.name == french_name
def test_attribute_translation(settings, color_attribute):
AttributeTranslation.objects.create(
language_code='fr', attribute=color_attribute,
name='French name')
assert not color_attribute.translated.name == 'French name'
settings.LANGUAGE_CODE = 'fr'
assert color_attribute.translated.name == 'French name'
def test_attribute_value_translation(
settings, product, attribute_value_translation_fr):
attribute = product.product_type.product_attributes.first().values.first()
assert not attribute.translated.name == 'French name'
settings.LANGUAGE_CODE = 'fr'
assert attribute.translated.name == 'French name'
def test_voucher_translation(settings, voucher, voucher_translation_fr):
assert not voucher.translated.name == 'French name'
settings.LANGUAGE_CODE = 'fr'
assert voucher.translated.name == 'French name'
def shipping_method_translation(
settings, shipping_method, shipping_method_translation_fr):
assert not shipping_method.translated.name == 'French name'
settings.LANGUAGE_CODE = 'fr'
assert shipping_method.translated.name == 'French name'