diff --git a/tests/admin_inlines/models.py b/tests/admin_inlines/models.py index a0a9093a5b..900eb34fca 100644 --- a/tests/admin_inlines/models.py +++ b/tests/admin_inlines/models.py @@ -337,3 +337,19 @@ class Profile(models.Model): collection = models.ForeignKey(ProfileCollection, models.SET_NULL, blank=True, null=True) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) + + +class VerboseNameProfile(Profile): + class Meta: + verbose_name = 'Model with verbose name only' + + +class VerboseNamePluralProfile(Profile): + class Meta: + verbose_name_plural = 'Model with verbose name plural only' + + +class BothVerboseNameProfile(Profile): + class Meta: + verbose_name = 'Model with both - name' + verbose_name_plural = 'Model with both - plural name' diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py index 74b10d80b3..261c4f0148 100644 --- a/tests/admin_inlines/tests.py +++ b/tests/admin_inlines/tests.py @@ -8,11 +8,12 @@ from django.urls import reverse from .admin import InnerInline, site as admin_site from .models import ( - Author, BinaryTree, Book, Chapter, Child, ChildModel1, ChildModel2, - Fashionista, FootNote, Holder, Holder2, Holder3, Holder4, Inner, Inner2, - Inner3, Inner4Stacked, Inner4Tabular, Novel, OutfitItem, Parent, - ParentModelWithCustomPk, Person, Poll, Profile, ProfileCollection, - Question, Sighting, SomeChildModel, SomeParentModel, Teacher, + Author, BinaryTree, Book, BothVerboseNameProfile, Chapter, Child, + ChildModel1, ChildModel2, Fashionista, FootNote, Holder, Holder2, Holder3, + Holder4, Inner, Inner2, Inner3, Inner4Stacked, Inner4Tabular, Novel, + OutfitItem, Parent, ParentModelWithCustomPk, Person, Poll, Profile, + ProfileCollection, Question, Sighting, SomeChildModel, SomeParentModel, + Teacher, VerboseNamePluralProfile, VerboseNameProfile, ) INLINE_CHANGELINK_HTML = 'class="inlinechangelink">Change' @@ -962,6 +963,115 @@ class TestReadOnlyChangeViewInlinePermissions(TestCase): self.assertNotContains(response, 'id="id_question_set-0-text"') +@override_settings(ROOT_URLCONF='admin_inlines.urls') +class TestVerboseNameInlineForms(TestDataMixin, TestCase): + factory = RequestFactory() + + def test_verbose_name_plural_inline(self): + class NonVerboseProfileInline(TabularInline): + model = Profile + verbose_name_plural = 'Non-verbose childs' + + class VerboseNameProfileInline(TabularInline): + model = VerboseNameProfile + verbose_name_plural = 'Childs with verbose name' + + class VerboseNamePluralProfileInline(TabularInline): + model = VerboseNamePluralProfile + verbose_name_plural = 'Childs with verbose name plural' + + class BothVerboseNameProfileInline(TabularInline): + model = BothVerboseNameProfile + verbose_name_plural = 'Childs with both verbose names' + + modeladmin = ModelAdmin(ProfileCollection, admin_site) + modeladmin.inlines = [ + NonVerboseProfileInline, + VerboseNameProfileInline, + VerboseNamePluralProfileInline, + BothVerboseNameProfileInline, + ] + obj = ProfileCollection.objects.create() + url = reverse('admin:admin_inlines_profilecollection_change', args=(obj.pk,)) + request = self.factory.get(url) + request.user = self.superuser + response = modeladmin.changeform_view(request) + # Non-verbose model. + self.assertContains(response, '

Non-verbose childs

') + self.assertContains(response, 'Add another Profile') + self.assertNotContains(response, '

Profiles

') + # Model with verbose name. + self.assertContains(response, '

Childs with verbose name

') + self.assertContains(response, 'Add another Model with verbose name only') + self.assertNotContains(response, '

Model with verbose name onlys

') + # Model with verbose name plural. + self.assertContains(response, '

Childs with verbose name plural

') + self.assertContains(response, 'Add another Profile') + self.assertNotContains(response, '

Model with verbose name plural only

') + # Model with both verbose names. + self.assertContains(response, '

Childs with both verbose names

') + self.assertContains(response, 'Add another Model with both - name') + self.assertNotContains(response, '

Model with both - plural name

') + + def test_both_verbose_names_inline(self): + class NonVerboseProfileInline(TabularInline): + model = Profile + verbose_name = 'Non-verbose childs - name' + verbose_name_plural = 'Non-verbose childs - plural name' + + class VerboseNameProfileInline(TabularInline): + model = VerboseNameProfile + verbose_name = 'Childs with verbose name - name' + verbose_name_plural = 'Childs with verbose name - plural name' + + class VerboseNamePluralProfileInline(TabularInline): + model = VerboseNamePluralProfile + verbose_name = 'Childs with verbose name plural - name' + verbose_name_plural = 'Childs with verbose name plural - plural name' + + class BothVerboseNameProfileInline(TabularInline): + model = BothVerboseNameProfile + verbose_name = 'Childs with both - name' + verbose_name_plural = 'Childs with both - plural name' + + modeladmin = ModelAdmin(ProfileCollection, admin_site) + modeladmin.inlines = [ + NonVerboseProfileInline, + VerboseNameProfileInline, + VerboseNamePluralProfileInline, + BothVerboseNameProfileInline, + ] + obj = ProfileCollection.objects.create() + url = reverse('admin:admin_inlines_profilecollection_change', args=(obj.pk,)) + request = self.factory.get(url) + request.user = self.superuser + response = modeladmin.changeform_view(request) + self.assertNotContains(response, 'Add another Profile') + # Non-verbose model. + self.assertContains(response, '

Non-verbose childs - plural name

') + self.assertContains(response, 'Add another Non-verbose childs - name') + self.assertNotContains(response, '

Profiles

') + # Model with verbose name. + self.assertContains(response, '

Childs with verbose name - plural name

') + self.assertContains(response, 'Add another Childs with verbose name - name') + self.assertNotContains(response, '

Model with verbose name onlys

') + # Model with verbose name plural. + self.assertContains( + response, + '

Childs with verbose name plural - plural name

', + ) + self.assertContains( + response, + 'Add another Childs with verbose name plural - name', + ) + self.assertNotContains(response, '

Model with verbose name plural only

') + # Model with both verbose names. + self.assertContains(response, '

Childs with both - plural name

') + self.assertContains(response, 'Add another Childs with both - name') + self.assertNotContains(response, '

Model with both - plural name

') + self.assertNotContains(response, 'Add another Model with both - name') + + @override_settings(ROOT_URLCONF='admin_inlines.urls') class SeleniumTests(AdminSeleniumTestCase):