From 20d9e68c06f9c70aa182fd76529929acbde67ac2 Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Mon, 24 Oct 2016 12:35:23 +0300 Subject: [PATCH] Bumped coverage to 100% --- tests/test_localized_auto_slug_field.py | 13 +++++++++++++ tests/test_localized_bleach_field.py | 17 +++++++++++++++++ tests/test_localized_field.py | 12 ++++++++++++ tests/test_localized_field_widget.py | 11 +++++++++++ 4 files changed, 53 insertions(+) diff --git a/tests/test_localized_auto_slug_field.py b/tests/test_localized_auto_slug_field.py index 5162e1b..ddd033c 100644 --- a/tests/test_localized_auto_slug_field.py +++ b/tests/test_localized_auto_slug_field.py @@ -1,8 +1,10 @@ +from django import forms from django.conf import settings from django.test import TestCase from django.utils.text import slugify from localized_fields.fields import LocalizedAutoSlugField +from localized_fields.forms import LocalizedFieldForm from .fake_model import get_fake_model @@ -69,3 +71,14 @@ class LocalizedAutoSlugFieldTestCase(TestCase): assert 'populate_from' in kwargs 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) diff --git a/tests/test_localized_bleach_field.py b/tests/test_localized_bleach_field.py index 50c7426..c6a5617 100644 --- a/tests/test_localized_bleach_field.py +++ b/tests/test_localized_bleach_field.py @@ -41,6 +41,19 @@ class LocalizedBleachFieldTestCase(TestCase): bleached_value = field.pre_save(model, False) 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 def _get_test_model(value): """Gets a test model and a artifically @@ -78,6 +91,10 @@ class LocalizedBleachFieldTestCase(TestCase): """ 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( non_bleached_value.get(lang_code), get_bleach_default_options() diff --git a/tests/test_localized_field.py b/tests/test_localized_field.py index a1c972d..9be52ec 100644 --- a/tests/test_localized_field.py +++ b/tests/test_localized_field.py @@ -130,6 +130,18 @@ class LocalizedValueTestCase(TestCase): # there's no actual 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): """Tests the :see:LocalizedField class.""" diff --git a/tests/test_localized_field_widget.py b/tests/test_localized_field_widget.py index 839e53d..5169a1a 100644 --- a/tests/test_localized_field_widget.py +++ b/tests/test_localized_field_widget.py @@ -31,3 +31,14 @@ class LocalizedFieldWidgetTestCase(TestCase): for (lang_code, _), value in zip(settings.LANGUAGES, decompressed_values): 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