mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-12-14 07:42:24 +03:00
Re-format all files
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from django.db.models import F
|
||||
from django.conf import settings
|
||||
from django.utils import translation
|
||||
from django.db.models import F
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils import translation
|
||||
|
||||
from localized_fields.value import LocalizedValue
|
||||
|
||||
@@ -13,16 +13,14 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
"""Assures that the current language
|
||||
is set back to the default."""
|
||||
"""Assures that the current language is set back to the default."""
|
||||
|
||||
translation.activate(settings.LANGUAGE_CODE)
|
||||
|
||||
@staticmethod
|
||||
def test_init():
|
||||
"""Tests whether the __init__ function
|
||||
of the :see:LocalizedValue class works
|
||||
as expected."""
|
||||
"""Tests whether the __init__ function of the :see:LocalizedValue class
|
||||
works as expected."""
|
||||
|
||||
keys = get_init_values()
|
||||
value = LocalizedValue(keys)
|
||||
@@ -32,9 +30,8 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_init_default_values():
|
||||
"""Tests whether the __init__ function
|
||||
of the :see:LocalizedValue accepts the
|
||||
default value or an empty dict properly."""
|
||||
"""Tests whether the __init__ function of the :see:LocalizedValue
|
||||
accepts the default value or an empty dict properly."""
|
||||
|
||||
value = LocalizedValue()
|
||||
|
||||
@@ -43,21 +40,20 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_init_array():
|
||||
"""Tests whether the __init__ function
|
||||
of :see:LocalizedValue properly handles an
|
||||
array.
|
||||
"""Tests whether the __init__ function of :see:LocalizedValue properly
|
||||
handles an array.
|
||||
|
||||
Arrays can be passed to LocalizedValue as
|
||||
a result of a ArrayAgg operation."""
|
||||
Arrays can be passed to LocalizedValue as a result of a ArrayAgg
|
||||
operation.
|
||||
"""
|
||||
|
||||
value = LocalizedValue(['my value'])
|
||||
assert value.get(settings.LANGUAGE_CODE) == 'my value'
|
||||
value = LocalizedValue(["my value"])
|
||||
assert value.get(settings.LANGUAGE_CODE) == "my value"
|
||||
|
||||
@staticmethod
|
||||
def test_get_explicit():
|
||||
"""Tests whether the the :see:LocalizedValue
|
||||
class's :see:get function works properly
|
||||
when specifying an explicit value."""
|
||||
"""Tests whether the the :see:LocalizedValue class's :see:get function
|
||||
works properly when specifying an explicit value."""
|
||||
|
||||
keys = get_init_values()
|
||||
localized_value = LocalizedValue(keys)
|
||||
@@ -67,9 +63,8 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_get_default_language():
|
||||
"""Tests whether the :see:LocalizedValue
|
||||
class's see:get function properly
|
||||
gets the value in the default language."""
|
||||
"""Tests whether the :see:LocalizedValue class's see:get function
|
||||
properly gets the value in the default language."""
|
||||
|
||||
keys = get_init_values()
|
||||
localized_value = LocalizedValue(keys)
|
||||
@@ -80,8 +75,8 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_set():
|
||||
"""Tests whether the :see:LocalizedValue
|
||||
class's see:set function works properly."""
|
||||
"""Tests whether the :see:LocalizedValue class's see:set function works
|
||||
properly."""
|
||||
|
||||
localized_value = LocalizedValue()
|
||||
|
||||
@@ -92,21 +87,21 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_eq():
|
||||
"""Tests whether the __eq__ operator
|
||||
of :see:LocalizedValue works properly."""
|
||||
"""Tests whether the __eq__ operator of :see:LocalizedValue works
|
||||
properly."""
|
||||
|
||||
a = LocalizedValue({'en': 'a', 'ar': 'b'})
|
||||
b = LocalizedValue({'en': 'a', 'ar': 'b'})
|
||||
a = LocalizedValue({"en": "a", "ar": "b"})
|
||||
b = LocalizedValue({"en": "a", "ar": "b"})
|
||||
|
||||
assert a == b
|
||||
|
||||
b.en = 'b'
|
||||
b.en = "b"
|
||||
assert a != b
|
||||
|
||||
@staticmethod
|
||||
def test_translate():
|
||||
"""Tests whether the :see:LocalizedValue
|
||||
class's __str__ works properly."""
|
||||
"""Tests whether the :see:LocalizedValue class's __str__ works
|
||||
properly."""
|
||||
|
||||
keys = get_init_values()
|
||||
localized_value = LocalizedValue(keys)
|
||||
@@ -117,15 +112,12 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_translate_fallback():
|
||||
"""Tests whether the :see:LocalizedValue
|
||||
class's translate()'s fallback functionality
|
||||
works properly."""
|
||||
"""Tests whether the :see:LocalizedValue class's translate()'s fallback
|
||||
functionality works properly."""
|
||||
|
||||
test_value = 'myvalue'
|
||||
test_value = "myvalue"
|
||||
|
||||
localized_value = LocalizedValue({
|
||||
settings.LANGUAGE_CODE: test_value
|
||||
})
|
||||
localized_value = LocalizedValue({settings.LANGUAGE_CODE: test_value})
|
||||
|
||||
other_language = settings.LANGUAGES[-1][0]
|
||||
|
||||
@@ -146,50 +138,44 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_translate_none():
|
||||
"""Tests whether the :see:LocalizedValue
|
||||
class's translate() method properly returns
|
||||
None when there is no value."""
|
||||
"""Tests whether the :see:LocalizedValue class's translate() method
|
||||
properly returns None when there is no value."""
|
||||
|
||||
# with no value, we always expect it to return None
|
||||
localized_value = LocalizedValue()
|
||||
assert localized_value.translate() is None
|
||||
assert str(localized_value) == ''
|
||||
assert str(localized_value) == ""
|
||||
|
||||
# with no value for the default language, the default
|
||||
# behavior is to return None, unless a custom fallback
|
||||
# chain is configured, which there is not for this test
|
||||
other_language = settings.LANGUAGES[-1][0]
|
||||
localized_value = LocalizedValue({
|
||||
other_language: 'hey'
|
||||
})
|
||||
localized_value = LocalizedValue({other_language: "hey"})
|
||||
|
||||
translation.activate(settings.LANGUAGE_CODE)
|
||||
assert localized_value.translate() is None
|
||||
assert str(localized_value) == ''
|
||||
assert str(localized_value) == ""
|
||||
|
||||
@staticmethod
|
||||
def test_translate_fallback_custom_fallback():
|
||||
"""Tests whether the :see:LocalizedValue class's
|
||||
translate()'s fallback functionality properly respects
|
||||
the LOCALIZED_FIELDS_FALLBACKS setting."""
|
||||
"""Tests whether the :see:LocalizedValue class's translate()'s fallback
|
||||
functionality properly respects the LOCALIZED_FIELDS_FALLBACKS
|
||||
setting."""
|
||||
|
||||
fallbacks = {
|
||||
'nl': ['ro']
|
||||
}
|
||||
fallbacks = {"nl": ["ro"]}
|
||||
|
||||
localized_value = LocalizedValue({
|
||||
settings.LANGUAGE_CODE: settings.LANGUAGE_CODE,
|
||||
'ro': 'ro'
|
||||
})
|
||||
localized_value = LocalizedValue(
|
||||
{settings.LANGUAGE_CODE: settings.LANGUAGE_CODE, "ro": "ro"}
|
||||
)
|
||||
|
||||
with override_settings(LOCALIZED_FIELDS_FALLBACKS=fallbacks):
|
||||
with translation.override('nl'):
|
||||
assert localized_value.translate() == 'ro'
|
||||
with translation.override("nl"):
|
||||
assert localized_value.translate() == "ro"
|
||||
|
||||
@staticmethod
|
||||
def test_deconstruct():
|
||||
"""Tests whether the :see:LocalizedValue
|
||||
class's :see:deconstruct function works properly."""
|
||||
"""Tests whether the :see:LocalizedValue class's :see:deconstruct
|
||||
function works properly."""
|
||||
|
||||
keys = get_init_values()
|
||||
value = LocalizedValue(keys)
|
||||
@@ -200,16 +186,16 @@ class LocalizedValueTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_construct_string():
|
||||
"""Tests whether the :see:LocalizedValue's constructor
|
||||
assumes the primary language when passing a single string."""
|
||||
"""Tests whether the :see:LocalizedValue's constructor assumes the
|
||||
primary language when passing a single string."""
|
||||
|
||||
value = LocalizedValue('beer')
|
||||
assert value.get(settings.LANGUAGE_CODE) == 'beer'
|
||||
value = LocalizedValue("beer")
|
||||
assert value.get(settings.LANGUAGE_CODE) == "beer"
|
||||
|
||||
@staticmethod
|
||||
def test_construct_expression():
|
||||
"""Tests whether passing expressions as values
|
||||
works properly and are not converted to string."""
|
||||
"""Tests whether passing expressions as values works properly and are
|
||||
not converted to string."""
|
||||
|
||||
value = LocalizedValue(dict(en=F('other')))
|
||||
value = LocalizedValue(dict(en=F("other")))
|
||||
assert isinstance(value.en, F)
|
||||
|
||||
Reference in New Issue
Block a user