Add experimental features flag for LocalizedField

With the flag set, LocalizedField will return None if there is no
database value.
This commit is contained in:
Bogdan Hopulele
2017-03-23 17:32:26 +02:00
parent 5df44b0d62
commit 52145ca7d3
5 changed files with 35 additions and 7 deletions

View File

@@ -1,9 +1,9 @@
from django.conf import settings
from django.db.utils import IntegrityError
from django.test import TestCase
from django.utils import translation
from django.db.utils import IntegrityError
from localized_fields import LocalizedField, LocalizedValue, LocalizedFieldForm
from localized_fields import LocalizedField, LocalizedFieldForm, LocalizedValue
def get_init_values() -> dict:
@@ -179,7 +179,7 @@ class LocalizedFieldTestCase(TestCase):
@staticmethod
def test_from_db_value_none():
"""Tests whether the :see:from_db_valuei function
"""Tests whether the :see:from_db_value function
correctly handles None values."""
localized_value = LocalizedField.from_db_value(None)
@@ -187,6 +187,18 @@ class LocalizedFieldTestCase(TestCase):
for lang_code, _ in settings.LANGUAGES:
assert localized_value.get(lang_code) is None
@staticmethod
def test_from_db_value_none_return_none():
"""Tests whether the :see:from_db_value function
correctly handles None values when LOCALIZED_FIELDS_EXPERIMENTAL
is set to True."""
settings.LOCALIZED_FIELDS_EXPERIMENTAL = True
localized_value = LocalizedField.from_db_value(None)
settings.LOCALIZED_FIELDS_EXPERIMENTAL = False
assert localized_value is None
@staticmethod
def test_to_python():
"""Tests whether the :see:to_python function