mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-10-29 18:18:57 +03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user