|
|
@@ -5,7 +5,11 @@ from django.core.exceptions import NON_FIELD_ERRORS
|
|
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
|
|
from django.core.validators import MaxLengthValidator
|
|
|
from django.forms.models import ALL_FIELDS
|
|
|
-from django.test import TestCase
|
|
|
+from django.test import TestCase, tag
|
|
|
+from django.utils import translation
|
|
|
+from django.utils.functional import Promise
|
|
|
+from django.utils.html import escape
|
|
|
+from django.utils.translation import gettext
|
|
|
|
|
|
from circuits.forms import CircuitGroupAssignmentForm, CircuitTerminationForm
|
|
|
from core.forms import DataSourceForm
|
|
|
@@ -17,6 +21,8 @@ from dcim.forms import (
|
|
|
InterfaceImportForm,
|
|
|
ModuleTypeForm,
|
|
|
RackForm,
|
|
|
+ SiteFilterForm,
|
|
|
+ SiteForm,
|
|
|
)
|
|
|
from dcim.models import Device, DeviceRole, DeviceType, Interface, Manufacturer, Site
|
|
|
from extras.forms import CustomFieldForm, EventRuleForm
|
|
|
@@ -574,3 +580,40 @@ class MetaShadowingTestCase(TestCase):
|
|
|
def test_localized_fields_all_sentinel_expands_to_declared(self):
|
|
|
# The ALL_FIELDS sentinel must expand to the declared fields, not char-split into letters.
|
|
|
self.assertEqual(self._configured_field_names(ALL_FIELDS, {'name', 'status'}), {'name', 'status'})
|
|
|
+
|
|
|
+
|
|
|
+class FormMixinLabelTranslationTestCase(TestCase):
|
|
|
+ """
|
|
|
+ Mixin labels are set at import, so eager gettext keeps them in DEFAULT_LANGUAGE (#23702).
|
|
|
+ """
|
|
|
+
|
|
|
+ def assertLabelsTranslated(self, form, expected):
|
|
|
+ # Compare against gettext() so catalog updates don't break the test
|
|
|
+ for name, msgid in expected.items():
|
|
|
+ with self.subTest(field=name):
|
|
|
+ label = form.fields[name].label
|
|
|
+ self.assertIsInstance(label, Promise)
|
|
|
+ self.assertEqual(str(label), gettext(msgid))
|
|
|
+
|
|
|
+ @tag('regression') # Ref: #23702
|
|
|
+ def test_model_form_mixin_labels(self):
|
|
|
+ # SiteForm inherits OwnerMixin and TagsMixin
|
|
|
+ with translation.override('nl'):
|
|
|
+ self.assertLabelsTranslated(SiteForm(), {
|
|
|
+ 'owner_group': 'Owner group',
|
|
|
+ 'owner': 'Owner',
|
|
|
+ 'tags': 'Tags',
|
|
|
+ })
|
|
|
+
|
|
|
+ @tag('regression') # Ref: #23702
|
|
|
+ def test_filter_form_mixin_labels(self):
|
|
|
+ # SiteFilterForm inherits OwnerFilterMixin and SavedFiltersMixin
|
|
|
+ with translation.override('nl'):
|
|
|
+ form = SiteFilterForm()
|
|
|
+ self.assertLabelsTranslated(form, {
|
|
|
+ 'owner_group_id': 'Owner Group',
|
|
|
+ 'owner_id': 'Owner',
|
|
|
+ 'filter_id': 'Saved Filter',
|
|
|
+ })
|
|
|
+ # Set in __init__, so it also passes with eager gettext. It pins that a lazy value renders in widget attrs.
|
|
|
+ self.assertIn(f'aria-label="{escape(gettext("Saved filter"))}"', str(form['filter_id']))
|