mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-10-29 18:18:57 +03:00
Allow raw dicts to be used in update statements
This commit is contained in:
47
tests/test_query_set.py
Normal file
47
tests/test_query_set.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.utils import translation
|
||||
|
||||
from localized_fields.fields import LocalizedField
|
||||
|
||||
from .fake_model import get_fake_model
|
||||
|
||||
|
||||
class LocalizedQuerySetTestCase(TestCase):
|
||||
"""Tests query sets with models containing :see:LocalizedField."""
|
||||
|
||||
Model = None
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Creates the test models in the database."""
|
||||
|
||||
super(LocalizedQuerySetTestCase, cls).setUpClass()
|
||||
|
||||
cls.Model = get_fake_model(
|
||||
{
|
||||
'title': LocalizedField(),
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def test_assign_raw_dict(cls):
|
||||
inst = cls.Model()
|
||||
inst.title = dict(en='Bread', ro='Paine')
|
||||
inst.save()
|
||||
|
||||
inst = cls.Model.objects.get(pk=inst.pk)
|
||||
assert inst.title.en == 'Bread'
|
||||
assert inst.title.ro == 'Paine'
|
||||
|
||||
@classmethod
|
||||
def test_assign_raw_dict_update(cls):
|
||||
inst = cls.Model.objects.create(
|
||||
title=dict(en='Bread', ro='Paine'))
|
||||
|
||||
cls.Model.objects.update(
|
||||
title=dict(en='Beer', ro='Bere'))
|
||||
|
||||
inst = cls.Model.objects.get(pk=inst.pk)
|
||||
assert inst.title.en == 'Beer'
|
||||
assert inst.title.ro == 'Bere'
|
||||
Reference in New Issue
Block a user