mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 11:42:54 +03:00
Bumped coverage to 100%
This commit is contained in:
parent
c081b0431d
commit
20d9e68c06
@ -1,8 +1,10 @@
|
|||||||
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
|
|
||||||
from localized_fields.fields import LocalizedAutoSlugField
|
from localized_fields.fields import LocalizedAutoSlugField
|
||||||
|
from localized_fields.forms import LocalizedFieldForm
|
||||||
|
|
||||||
from .fake_model import get_fake_model
|
from .fake_model import get_fake_model
|
||||||
|
|
||||||
@ -69,3 +71,14 @@ class LocalizedAutoSlugFieldTestCase(TestCase):
|
|||||||
|
|
||||||
assert 'populate_from' in kwargs
|
assert 'populate_from' in kwargs
|
||||||
assert kwargs['populate_from'] == field.populate_from
|
assert kwargs['populate_from'] == field.populate_from
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_formfield():
|
||||||
|
"""Tests whether the :see:formfield method
|
||||||
|
returns a valid form field that is hidden."""
|
||||||
|
|
||||||
|
field = LocalizedAutoSlugField(populate_from='title')
|
||||||
|
form_field = field.formfield()
|
||||||
|
|
||||||
|
assert isinstance(form_field, LocalizedFieldForm)
|
||||||
|
assert isinstance(form_field.widget, forms.HiddenInput)
|
||||||
|
@ -41,6 +41,19 @@ class LocalizedBleachFieldTestCase(TestCase):
|
|||||||
bleached_value = field.pre_save(model, False)
|
bleached_value = field.pre_save(model, False)
|
||||||
assert not bleached_value
|
assert not bleached_value
|
||||||
|
|
||||||
|
def test_pre_save_none_values(self):
|
||||||
|
"""Tests whether the :see:pre_save function
|
||||||
|
works properly when one of the languages has
|
||||||
|
no text and is None."""
|
||||||
|
|
||||||
|
value = self._get_test_value()
|
||||||
|
value.set(settings.LANGUAGE_CODE, None)
|
||||||
|
|
||||||
|
model, field = self._get_test_model(value)
|
||||||
|
|
||||||
|
bleached_value = field.pre_save(model, False)
|
||||||
|
self._validate(value, bleached_value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_test_model(value):
|
def _get_test_model(value):
|
||||||
"""Gets a test model and a artifically
|
"""Gets a test model and a artifically
|
||||||
@ -78,6 +91,10 @@ class LocalizedBleachFieldTestCase(TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
for lang_code, _ in settings.LANGUAGES:
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
|
if not non_bleached_value.get(lang_code):
|
||||||
|
assert not bleached_value.get(lang_code)
|
||||||
|
continue
|
||||||
|
|
||||||
expected_value = bleach.clean(
|
expected_value = bleach.clean(
|
||||||
non_bleached_value.get(lang_code),
|
non_bleached_value.get(lang_code),
|
||||||
get_bleach_default_options()
|
get_bleach_default_options()
|
||||||
|
@ -130,6 +130,18 @@ class LocalizedValueTestCase(TestCase):
|
|||||||
# there's no actual value
|
# there's no actual value
|
||||||
assert localized_value.get(other_language) != test_value
|
assert localized_value.get(other_language) != test_value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_deconstruct():
|
||||||
|
"""Tests whether the :see:LocalizedValue
|
||||||
|
class's :see:deconstruct function works properly."""
|
||||||
|
|
||||||
|
keys = get_init_values()
|
||||||
|
value = LocalizedValue(keys)
|
||||||
|
|
||||||
|
path, args, kwargs = value.deconstruct()
|
||||||
|
|
||||||
|
assert args[0] == keys
|
||||||
|
|
||||||
|
|
||||||
class LocalizedFieldTestCase(TestCase):
|
class LocalizedFieldTestCase(TestCase):
|
||||||
"""Tests the :see:LocalizedField class."""
|
"""Tests the :see:LocalizedField class."""
|
||||||
|
@ -31,3 +31,14 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
|||||||
|
|
||||||
for (lang_code, _), value in zip(settings.LANGUAGES, decompressed_values):
|
for (lang_code, _), value in zip(settings.LANGUAGES, decompressed_values):
|
||||||
assert localized_value.get(lang_code) == value
|
assert localized_value.get(lang_code) == value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_decompress_none():
|
||||||
|
"""Tests whether the :see:LocalizedFieldWidget correctly
|
||||||
|
handles :see:None."""
|
||||||
|
|
||||||
|
widget = LocalizedFieldWidget()
|
||||||
|
decompressed_values = widget.decompress(None)
|
||||||
|
|
||||||
|
for _, value in zip(settings.LANGUAGES, decompressed_values):
|
||||||
|
assert not value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user