|
1
|
|
|
from django.conf import settings |
|
|
|
|
|
|
2
|
|
|
from django.core.exceptions import ValidationError |
|
|
|
|
|
|
3
|
|
|
from django.forms.widgets import FILE_INPUT_CONTRADICTION |
|
|
|
|
|
|
4
|
|
|
from django.test import TestCase |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
from localized_fields.forms import LocalizedFileFieldForm |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class LocalizedFileFieldFormTestCase(TestCase): |
|
|
|
|
|
|
10
|
|
|
"""Tests the workings of the :see:LocalizedFileFieldForm class.""" |
|
11
|
|
|
|
|
12
|
|
|
def test_clean(self): |
|
13
|
|
|
"""Tests whether the :see:clean function is working properly.""" |
|
14
|
|
|
|
|
15
|
|
|
formfield = LocalizedFileFieldForm(required=True) |
|
16
|
|
|
with self.assertRaises(ValidationError): |
|
|
|
|
|
|
17
|
|
|
formfield.clean([]) |
|
18
|
|
|
with self.assertRaises(ValidationError): |
|
|
|
|
|
|
19
|
|
|
formfield.clean([], {'en': None}) |
|
20
|
|
|
with self.assertRaises(ValidationError): |
|
|
|
|
|
|
21
|
|
|
formfield.clean("badvalue") |
|
22
|
|
|
with self.assertRaises(ValidationError): |
|
|
|
|
|
|
23
|
|
|
value = [FILE_INPUT_CONTRADICTION] * len(settings.LANGUAGES) |
|
24
|
|
|
formfield.clean(value) |
|
25
|
|
|
|
|
26
|
|
|
formfield = LocalizedFileFieldForm(required=False) |
|
27
|
|
|
formfield.clean([''] * len(settings.LANGUAGES)) |
|
28
|
|
|
formfield.clean(['', ''], ['', '']) |
|
29
|
|
|
|
|
30
|
|
|
def test_bound_data(self): |
|
|
|
|
|
|
31
|
|
|
"""Tests whether the :see:bound_data function is returns correctly |
|
|
|
|
|
|
32
|
|
|
value""" |
|
33
|
|
|
|
|
34
|
|
|
formfield = LocalizedFileFieldForm() |
|
35
|
|
|
assert formfield.bound_data([''], None) == [''] |
|
36
|
|
|
|
|
37
|
|
|
initial = dict([(lang, '') for lang, _ in settings.LANGUAGES]) |
|
38
|
|
|
value = [None] * len(settings.LANGUAGES) |
|
39
|
|
|
expected_value = [''] * len(settings.LANGUAGES) |
|
40
|
|
|
assert formfield.bound_data(value, initial) == expected_value |
|
41
|
|
|
|
|
42
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.