mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-24 19:32:53 +03:00
Add test for falling back to default value during an update
This commit is contained in:
parent
893fe0f5ab
commit
39495da918
@ -4,6 +4,7 @@ from django.conf import settings
|
||||
from django.db import connection
|
||||
from django.utils import translation
|
||||
|
||||
from localized_fields.value import LocalizedIntegerValue
|
||||
from localized_fields.fields import LocalizedIntegerField
|
||||
|
||||
from .fake_model import get_fake_model
|
||||
@ -174,3 +175,18 @@ class LocalizedIntegerFieldTestCase(TestCase):
|
||||
assert obj.score.get(lang_code) == 75
|
||||
else:
|
||||
assert obj.score.get(lang_code) is None
|
||||
|
||||
def test_default_value_update(self):
|
||||
"""Tests whether a default is properly set
|
||||
when specified during updates."""
|
||||
|
||||
model = get_fake_model({
|
||||
'score': LocalizedIntegerField(default={settings.LANGUAGE_CODE: 75}, null=True)
|
||||
})
|
||||
|
||||
obj = model.objects.create(score=LocalizedIntegerValue({settings.LANGUAGE_CODE: 35}))
|
||||
assert obj.score.get(settings.LANGUAGE_CODE) == 35
|
||||
|
||||
model.objects.update(score=LocalizedIntegerValue({settings.LANGUAGE_CODE: None}))
|
||||
obj.refresh_from_db()
|
||||
assert obj.score.get(settings.LANGUAGE_CODE) == 75
|
||||
|
Loading…
x
Reference in New Issue
Block a user