added test for LocalizedFileField and LocalizedFileFieldForm

This commit is contained in:
seroy
2017-04-24 20:30:44 +03:00
parent a352388243
commit db93b93046
2 changed files with 192 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.forms.widgets import FILE_INPUT_CONTRADICTION
from django.test import TestCase
from localized_fields.forms import LocalizedFileFieldForm
class LocalizedFileFieldFormTestCase(TestCase):
"""Tests the workings of the :see:LocalizedFileFieldForm class."""
def test_clean(self):
"""Tests whether the :see:clean function is working properly."""
formfield = LocalizedFileFieldForm(required=True)
with self.assertRaises(ValidationError):
formfield.clean([])
with self.assertRaises(ValidationError):
formfield.clean([], {'en': None})
with self.assertRaises(ValidationError):
formfield.clean("badvalue")
with self.assertRaises(ValidationError):
value = [FILE_INPUT_CONTRADICTION] * len(settings.LANGUAGES)
formfield.clean(value)
formfield = LocalizedFileFieldForm(required=False)
formfield.clean([''] * len(settings.LANGUAGES))
formfield.clean(['', ''], ['', ''])
def test_bound_data(self):
"""Tests whether the :see:bound_data function is returns correctly
value"""
formfield = LocalizedFileFieldForm()
assert formfield.bound_data([''], None) == ['']
initial = dict([(lang, '') for lang, _ in settings.LANGUAGES])
value = [None] * len(settings.LANGUAGES)
expected_value = [''] * len(settings.LANGUAGES)
assert formfield.bound_data(value, initial) == expected_value