|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | from __future__ import absolute_import
|
2 | 3 | from __future__ import unicode_literals
|
3 | 4 |
|
|
8 | 9 |
|
9 | 10 | from django import forms
|
10 | 11 | from django.test import TestCase, override_settings
|
| 12 | +from django.utils import translation |
| 13 | +from django.utils.translation import ugettext as _ |
11 | 14 |
|
12 | 15 | from django_filters import filters, widgets
|
13 | 16 | from django_filters.fields import (
|
@@ -1174,6 +1177,21 @@ def test_field_labels(self):
|
1174 | 1177 | ('-d', 'D (descending)'),
|
1175 | 1178 | ))
|
1176 | 1179 |
|
| 1180 | + def test_field_labels_descending(self): |
| 1181 | + f = OrderingFilter( |
| 1182 | + fields=['username'], |
| 1183 | + field_labels={ |
| 1184 | + 'username': 'BLABLA', |
| 1185 | + '-username': 'XYZXYZ', |
| 1186 | + } |
| 1187 | + ) |
| 1188 | + |
| 1189 | + self.assertEqual(f.field.choices, [ |
| 1190 | + ('', '---------'), |
| 1191 | + ('username', 'BLABLA'), |
| 1192 | + ('-username', 'XYZXYZ'), |
| 1193 | + ]) |
| 1194 | + |
1177 | 1195 | def test_normalize_fields(self):
|
1178 | 1196 | f = OrderingFilter.normalize_fields
|
1179 | 1197 | O = OrderedDict
|
@@ -1213,3 +1231,31 @@ def test_widget(self):
|
1213 | 1231 |
|
1214 | 1232 | self.assertIsInstance(widget, widgets.BaseCSVWidget)
|
1215 | 1233 | self.assertIsInstance(widget, forms.Select)
|
| 1234 | + |
| 1235 | + def test_translation_sanity(self): |
| 1236 | + with translation.override('pl'): |
| 1237 | + self.assertEqual(_('Username'), 'Nazwa użytkownika') |
| 1238 | + self.assertEqual(_('%s (descending)') % _('Username'), 'Nazwa użytkownika (malejąco)') |
| 1239 | + |
| 1240 | + def test_translation_default_label(self): |
| 1241 | + with translation.override('pl'): |
| 1242 | + f = OrderingFilter(fields=['username']) |
| 1243 | + |
| 1244 | + self.assertEqual(f.field.choices, [ |
| 1245 | + ('', '---------'), |
| 1246 | + ('username', 'Nazwa użytkownika'), |
| 1247 | + ('-username', 'Nazwa użytkownika (malejąco)'), |
| 1248 | + ]) |
| 1249 | + |
| 1250 | + def test_translation_override_label(self): |
| 1251 | + with translation.override('pl'): |
| 1252 | + f = OrderingFilter( |
| 1253 | + fields=['username'], |
| 1254 | + field_labels={'username': 'BLABLA'}, |
| 1255 | + ) |
| 1256 | + |
| 1257 | + self.assertEqual(f.field.choices, [ |
| 1258 | + ('', '---------'), |
| 1259 | + ('username', 'BLABLA'), |
| 1260 | + ('-username', 'BLABLA (malejąco)'), |
| 1261 | + ]) |
0 commit comments