added test for str parameter to_python method

This commit is contained in:
seroy 2017-04-13 11:41:24 +03:00
parent 366dceaddc
commit fc80462ce7

View File

@ -1,3 +1,4 @@
import json
from django.conf import settings from django.conf import settings
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from django.test import TestCase from django.test import TestCase
@ -232,6 +233,20 @@ class LocalizedFieldTestCase(TestCase):
for lang_code, _ in settings.LANGUAGES: for lang_code, _ in settings.LANGUAGES:
assert localized_value.get(lang_code) is None assert localized_value.get(lang_code) is None
@staticmethod
def test_to_python_str():
"""Tests whether the :see:to_python function produces
the expected :see:LocalizedValue when it is
passed serialized string value."""
serialized_str = json.dumps(get_init_values())
localized_value = LocalizedField().to_python(serialized_str)
assert isinstance(localized_value, LocalizedValue)
for language, value in get_init_values().items():
assert localized_value.get(language) == value
assert getattr(localized_value, language) == value
@staticmethod @staticmethod
def test_get_prep_value(): def test_get_prep_value():
""""Tests whether the :see:get_prep_value function """"Tests whether the :see:get_prep_value function