-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest_forms.py
66 lines (55 loc) · 2.14 KB
/
test_forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from django.test import override_settings
from tests.test_case import TranslationTestCase
from translations.forms import generate_translation_form
from sample.models import Timezone, Continent, City
class GenerateTranslationFormTest(TranslationTestCase):
def test_field_choices_automatic(self):
form = generate_translation_form(City)
self.assertListEqual(
form.declared_fields['field'].choices,
[(None, '---------'), ('name', 'Name'), ('denonym', 'Denonym')]
)
def test_field_choices_empty(self):
form = generate_translation_form(Timezone)
self.assertListEqual(
form.declared_fields['field'].choices,
[(None, '---------')]
)
def test_field_choices_explicit(self):
form = generate_translation_form(Continent)
self.assertListEqual(
form.declared_fields['field'].choices,
[(None, '---------'), ('name', 'Name'), ('denonym', 'Denonym')]
)
@override_settings(LANGUAGE_CODE='en-us')
def test_nonexisting_accented_default_language_code(self):
form = generate_translation_form(Continent)
self.assertListEqual(
form.declared_fields['language'].choices,
[
(None, '---------'),
('en-gb', 'English (Great Britain)'),
('de', 'German'),
('tr', 'Turkish')
]
)
@override_settings(LANGUAGE_CODE='en-gb')
def test_existing_accented_default_language_code(self):
form = generate_translation_form(Continent)
self.assertListEqual(
form.declared_fields['language'].choices,
[
(None, '---------'),
('en', 'English'),
('de', 'German'),
('tr', 'Turkish')
]
)
@override_settings(LANGUAGE_CODE='xx')
def test_invalid_default_language_code(self):
with self.assertRaises(OSError) as error:
generate_translation_form(Continent)
self.assertEqual(
error.exception.args[0],
'No translation files found for default language xx.'
)