mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 11:42:54 +03:00
Add extra tests for LocalizedRef
This commit is contained in:
parent
06f7ee15f0
commit
2741a6a2a2
@ -48,18 +48,32 @@ class LocalizedExpressionsTestCase(TestCase):
|
|||||||
other=obj
|
other=obj
|
||||||
)
|
)
|
||||||
|
|
||||||
for lang_code, _ in settings.LANGUAGES:
|
def create_queryset(ref):
|
||||||
translation.activate(lang_code)
|
return (
|
||||||
|
|
||||||
queryset = (
|
|
||||||
cls.TestModel1.objects
|
cls.TestModel1.objects
|
||||||
.annotate(
|
.annotate(mytexts=ref)
|
||||||
mytexts=LocalizedRef('features__text')
|
.values_list('mytexts', flat=True)
|
||||||
)
|
|
||||||
.values_list(
|
|
||||||
'mytexts', flat=True
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# assert that it properly selects the currently active language
|
||||||
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
|
translation.activate(lang_code)
|
||||||
|
queryset = create_queryset(LocalizedRef('features__text'))
|
||||||
|
|
||||||
for index, value in enumerate(queryset):
|
for index, value in enumerate(queryset):
|
||||||
|
assert translation.get_language() in value
|
||||||
assert str(index) in value
|
assert str(index) in value
|
||||||
|
|
||||||
|
# ensure that the default language is used in case no
|
||||||
|
# language is active at all
|
||||||
|
translation.deactivate_all()
|
||||||
|
queryset = create_queryset(LocalizedRef('features__text'))
|
||||||
|
for index, value in enumerate(queryset):
|
||||||
|
assert settings.LANGUAGE_CODE in value
|
||||||
|
assert str(index) in value
|
||||||
|
|
||||||
|
# ensures that overriding the language works properly
|
||||||
|
queryset = create_queryset(LocalizedRef('features__text', 'ro'))
|
||||||
|
for index, value in enumerate(queryset):
|
||||||
|
assert 'ro' in value
|
||||||
|
assert str(index) in value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user