From 7c06f8f636b095a72f62b0a285b8f7c0ced1721b Mon Sep 17 00:00:00 2001
From: Thom Wiggers <thom@thomwiggers.nl>
Date: Thu, 8 Nov 2018 10:22:12 +0100
Subject: [PATCH] Tests that demonstrate breakage
---
tests/admin_views/admin.py | 9 ++++++++-
tests/admin_views/models.py | 6 ++++++
tests/admin_views/tests.py | 11 ++++++++++-
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index 04cc6c79e7..2905b56417 100644
a
|
b
|
from .models import (
|
35 | 35 | MainPrepopulated, ModelWithStringPrimaryKey, NotReferenced, OldSubscriber, |
36 | 36 | OtherStory, Paper, Parent, ParentWithDependentChildren, ParentWithUUIDPK, |
37 | 37 | Person, Persona, Picture, Pizza, Plot, PlotDetails, PlotProxy, |
38 | | PluggableSearchPerson, Podcast, Post, PrePopulatedPost, |
| 38 | PluggableSearchPerson, Podcast, Post, PrePopulatedPost, PrepopulatedModel, |
39 | 39 | PrePopulatedPostLargeSlug, PrePopulatedSubPost, Promo, Question, |
40 | 40 | ReadablePizza, ReadOnlyPizza, Recipe, Recommendation, Recommender, |
41 | 41 | ReferencedByGenRel, ReferencedByInline, ReferencedByParent, |
… |
… |
class GetFormsetsArgumentCheckingAdmin(admin.ModelAdmin):
|
949 | 949 | raise Exception("'obj' passed to get_formsets_with_inlines was None during change_view") |
950 | 950 | return super().get_formsets_with_inlines(request, obj) |
951 | 951 | |
| 952 | # Admin for #29929 |
| 953 | class PrepopulatedReadOnlyAdmin(admin.ModelAdmin): |
| 954 | prepopulated_fields = {'to_be_prepopulated': ('input_value',)} |
| 955 | |
| 956 | def has_change_permission(self, *args, **kwargs): |
| 957 | return False |
952 | 958 | |
953 | 959 | site = admin.AdminSite(name="admin") |
954 | 960 | site.site_url = '/my-site-url/' |
… |
… |
site.register(GenRelReference)
|
1021 | 1027 | site.register(ParentWithUUIDPK) |
1022 | 1028 | site.register(RelatedPrepopulated, search_fields=['name']) |
1023 | 1029 | site.register(RelatedWithUUIDPKModel) |
| 1030 | site.register(PrepopulatedModel, PrepopulatedReadOnlyAdmin) |
1024 | 1031 | |
1025 | 1032 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
1026 | 1033 | # That way we cover all four cases: |
diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py
index 59228876c5..0d98cb962d 100644
a
|
b
|
class Author(models.Model):
|
979 | 979 | class Authorship(models.Model): |
980 | 980 | book = models.ForeignKey(Book, models.CASCADE) |
981 | 981 | author = models.ForeignKey(Author, models.CASCADE) |
| 982 | |
| 983 | |
| 984 | # Model for 29929 |
| 985 | class PrepopulatedModel(models.Model): |
| 986 | input_value = models.TextField() |
| 987 | to_be_prepopulated = models.TextField() |
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 908f78bf9b..6c72cdeb2d 100644
a
|
b
|
from .models import (
|
46 | 46 | MainPrepopulated, Media, ModelWithStringPrimaryKey, OtherStory, Paper, |
47 | 47 | Parent, ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona, |
48 | 48 | Picture, Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post, |
49 | | PrePopulatedPost, Promo, Question, ReadablePizza, ReadOnlyPizza, |
| 49 | PrePopulatedPost, PrepopulatedModel, Promo, Question, ReadablePizza, ReadOnlyPizza, |
50 | 50 | Recommendation, Recommender, RelatedPrepopulated, RelatedWithUUIDPKModel, |
51 | 51 | Report, Restaurant, RowLevelChangePermissionModel, SecretHideout, Section, |
52 | 52 | ShortMessage, Simple, State, Story, SuperSecretHideout, SuperVillain, |
… |
… |
class AdminViewBasicTest(AdminViewBasicTestCase):
|
972 | 972 | self.assertContains(response, '<th scope="col" class="column-value">') |
973 | 973 | self.assertNotContains(response, '<th scope="col" class="sortable column') |
974 | 974 | |
| 975 | def test_prepopulatedfields_readonly(self): |
| 976 | """ |
| 977 | Check if prepopulated fields don't break change views when they're read only. |
| 978 | |
| 979 | See #29929 |
| 980 | """ |
| 981 | PrepopulatedModel.objects.create(pk=1, input_value='foo', to_be_prepopulated='foo') |
| 982 | self.client.get(reverse('admin:admin_views_prepopulatedmodel_change', args=(1,))) |
| 983 | |
975 | 984 | |
976 | 985 | @override_settings(TEMPLATES=[{ |
977 | 986 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |