diff options
author | Siburg <jelle.sjoerdsma@gmail.com> | 2021-09-08 11:19:35 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-08 11:32:06 +0200 |
commit | 1bd6a7a0acc11e249fca11c017505ad39f15ebf6 (patch) | |
tree | dc99dfcd4d38e929cb429a15d340d9f91243bb33 /tests/admin_inlines | |
parent | 4a43335d300da942602fbf216cd0a53b60827ab4 (diff) | |
download | django-1bd6a7a0acc11e249fca11c017505ad39f15ebf6.tar.gz |
Refs #32219 -- Added admin model inline tests for verbose names.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/admin_inlines')
-rw-r--r-- | tests/admin_inlines/models.py | 16 | ||||
-rw-r--r-- | tests/admin_inlines/tests.py | 120 |
2 files changed, 131 insertions, 5 deletions
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</a>' @@ -963,6 +964,115 @@ class TestReadOnlyChangeViewInlinePermissions(TestCase): @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, '<h2>Non-verbose childs</h2>') + self.assertContains(response, 'Add another Profile') + self.assertNotContains(response, '<h2>Profiles</h2>') + # Model with verbose name. + self.assertContains(response, '<h2>Childs with verbose name</h2>') + self.assertContains(response, 'Add another Model with verbose name only') + self.assertNotContains(response, '<h2>Model with verbose name onlys</h2>') + # Model with verbose name plural. + self.assertContains(response, '<h2>Childs with verbose name plural</h2>') + self.assertContains(response, 'Add another Profile') + self.assertNotContains(response, '<h2>Model with verbose name plural only</h2>') + # Model with both verbose names. + self.assertContains(response, '<h2>Childs with both verbose names</h2>') + self.assertContains(response, 'Add another Model with both - name') + self.assertNotContains(response, '<h2>Model with both - plural name</h2>') + + 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, '<h2>Non-verbose childs - plural name</h2>') + self.assertContains(response, 'Add another Non-verbose childs - name') + self.assertNotContains(response, '<h2>Profiles</h2>') + # Model with verbose name. + self.assertContains(response, '<h2>Childs with verbose name - plural name</h2>') + self.assertContains(response, 'Add another Childs with verbose name - name') + self.assertNotContains(response, '<h2>Model with verbose name onlys</h2>') + # Model with verbose name plural. + self.assertContains( + response, + '<h2>Childs with verbose name plural - plural name</h2>', + ) + self.assertContains( + response, + 'Add another Childs with verbose name plural - name', + ) + self.assertNotContains(response, '<h2>Model with verbose name plural only</h2>') + # Model with both verbose names. + self.assertContains(response, '<h2>Childs with both - plural name</h2>') + self.assertContains(response, 'Add another Childs with both - name') + self.assertNotContains(response, '<h2>Model with both - plural name</h2>') + self.assertNotContains(response, 'Add another Model with both - name') + + +@override_settings(ROOT_URLCONF='admin_inlines.urls') class SeleniumTests(AdminSeleniumTestCase): available_apps = ['admin_inlines'] + AdminSeleniumTestCase.available_apps |