| Total Complexity | 12 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
| 1 | from django.conf import settings |
||
| 7 | class LocalizedFieldFormTestCase(TestCase): |
||
| 8 | """Tests the workings of the :see:LocalizedFieldForm class.""" |
||
| 9 | |||
| 10 | @staticmethod |
||
| 11 | def test_init(): |
||
| 12 | """Tests whether the constructor correctly |
||
| 13 | creates a field for every language.""" |
||
| 14 | |||
| 15 | form = LocalizedFieldForm() |
||
| 16 | |||
| 17 | for (lang_code, _), field in zip(settings.LANGUAGES, form.fields): |
||
| 18 | assert field.label == lang_code |
||
| 19 | |||
| 20 | if lang_code == settings.LANGUAGE_CODE: |
||
| 21 | assert field.required |
||
| 22 | else: |
||
| 23 | assert not field.required |
||
| 24 | |||
| 25 | form = LocalizedFieldForm(required=False) |
||
| 26 | |||
| 27 | for (lang_code, _), field in zip(settings.LANGUAGES, form.fields): |
||
| 28 | assert not field.required |
||
| 29 | |||
| 30 | @staticmethod |
||
| 31 | def test_compress(): |
||
| 32 | """Tests whether the :see:compress function |
||
| 33 | is working properly.""" |
||
| 34 | |||
| 35 | input_value = [lang_name for _, lang_name in settings.LANGUAGES] |
||
| 36 | output_value = LocalizedFieldForm().compress(input_value) |
||
| 37 | |||
| 38 | for lang_code, lang_name in settings.LANGUAGES: |
||
| 39 | assert output_value.get(lang_code) == lang_name |
||
| 40 |