diff options
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/admin.py | 5 | ||||
| -rw-r--r-- | tests/admin_views/models.py | 8 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 31 |
3 files changed, 40 insertions, 4 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 4f39381783..6a11d5b9bb 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -41,8 +41,8 @@ from .models import ( ReferencedByGenRel, ReferencedByInline, ReferencedByParent, RelatedPrepopulated, RelatedWithUUIDPKModel, Report, Reservation, Restaurant, RowLevelChangePermissionModel, Section, ShortMessage, Simple, - Sketch, State, Story, StumpJoke, Subscriber, SuperVillain, Telegram, Thing, - Topping, UnchangeableObject, UndeletableObject, UnorderedObject, + Sketch, Song, State, Story, StumpJoke, Subscriber, SuperVillain, Telegram, + Thing, Topping, UnchangeableObject, UndeletableObject, UnorderedObject, UserMessenger, UserProxy, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour, ) @@ -1069,6 +1069,7 @@ site.register(ReadOnlyPizza, ReadOnlyPizzaAdmin) site.register(ReadablePizza) site.register(Topping, ToppingAdmin) site.register(Album, AlbumAdmin) +site.register(Song) site.register(Question, QuestionAdmin) site.register(Answer, AnswerAdmin, date_hierarchy='question__posted') site.register(Answer2, date_hierarchy='question__expires') diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py index a519f7395d..16dd58bcd3 100644 --- a/tests/admin_views/models.py +++ b/tests/admin_views/models.py @@ -604,6 +604,14 @@ class Album(models.Model): title = models.CharField(max_length=30) +class Song(models.Model): + name = models.CharField(max_length=20) + album = models.ForeignKey(Album, on_delete=models.RESTRICT) + + def __str__(self): + return self.name + + class Employee(Person): code = models.CharField(max_length=20) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 9709bcaf88..e833c44f95 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -38,7 +38,7 @@ from . import customadmin from .admin import CityAdmin, site, site2 from .models import ( Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField, - AdminOrderedModelMethod, Answer, Answer2, Article, BarAccount, Book, + AdminOrderedModelMethod, Album, Answer, Answer2, Article, BarAccount, Book, Bookmark, Category, Chapter, ChapterXtra1, ChapterXtra2, Character, Child, Choice, City, Collector, Color, ComplexSortedPerson, CoverLetter, CustomArticle, CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel, @@ -50,7 +50,7 @@ from .models import ( PrePopulatedPost, Promo, Question, ReadablePizza, ReadOnlyPizza, Recommendation, Recommender, RelatedPrepopulated, RelatedWithUUIDPKModel, Report, Restaurant, RowLevelChangePermissionModel, SecretHideout, Section, - ShortMessage, Simple, State, Story, SuperSecretHideout, SuperVillain, + ShortMessage, Simple, Song, State, Story, SuperSecretHideout, SuperVillain, Telegram, TitleTranslation, Topping, UnchangeableObject, UndeletableObject, UnorderedObject, UserProxy, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour, @@ -2603,6 +2603,33 @@ class AdminViewDeletedObjectsTest(TestCase): self.assertEqual(Question.objects.count(), 1) self.assertContains(response, "would require deleting the following protected related objects") + def test_restricted(self): + album = Album.objects.create(title='Amaryllis') + song = Song.objects.create(album=album, name='Unity') + response = self.client.get(reverse('admin:admin_views_album_delete', args=(album.pk,))) + self.assertContains( + response, + 'would require deleting the following protected related objects', + ) + self.assertContains( + response, + '<li>Song: <a href="%s">Unity</a></li>' + % reverse('admin:admin_views_song_change', args=(song.pk,)) + ) + + def test_post_delete_restricted(self): + album = Album.objects.create(title='Amaryllis') + Song.objects.create(album=album, name='Unity') + response = self.client.post( + reverse('admin:admin_views_album_delete', args=(album.pk,)), + {'post': 'yes'}, + ) + self.assertEqual(Album.objects.count(), 1) + self.assertContains( + response, + 'would require deleting the following protected related objects', + ) + def test_not_registered(self): should_contain = """<li>Secret hideout: underground bunker""" response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v1.pk,))) |
