Ticket #29929: 0001-Tests-that-demonstrate-breakage.patch

File 0001-Tests-that-demonstrate-breakage.patch, 4.1 KB (added by Thom Wiggers, 6 years ago)

The attached file demonstrates the issue in the Django test suite.

  • tests/admin_views/admin.py

    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 (  
    3535    MainPrepopulated, ModelWithStringPrimaryKey, NotReferenced, OldSubscriber,
    3636    OtherStory, Paper, Parent, ParentWithDependentChildren, ParentWithUUIDPK,
    3737    Person, Persona, Picture, Pizza, Plot, PlotDetails, PlotProxy,
    38     PluggableSearchPerson, Podcast, Post, PrePopulatedPost,
     38    PluggableSearchPerson, Podcast, Post, PrePopulatedPost, PrepopulatedModel,
    3939    PrePopulatedPostLargeSlug, PrePopulatedSubPost, Promo, Question,
    4040    ReadablePizza, ReadOnlyPizza, Recipe, Recommendation, Recommender,
    4141    ReferencedByGenRel, ReferencedByInline, ReferencedByParent,
    class GetFormsetsArgumentCheckingAdmin(admin.ModelAdmin):  
    949949            raise Exception("'obj' passed to get_formsets_with_inlines was None during change_view")
    950950        return super().get_formsets_with_inlines(request, obj)
    951951
     952# Admin for #29929
     953class PrepopulatedReadOnlyAdmin(admin.ModelAdmin):
     954    prepopulated_fields = {'to_be_prepopulated': ('input_value',)}
     955
     956    def has_change_permission(self, *args, **kwargs):
     957        return False
    952958
    953959site = admin.AdminSite(name="admin")
    954960site.site_url = '/my-site-url/'
    site.register(GenRelReference)  
    10211027site.register(ParentWithUUIDPK)
    10221028site.register(RelatedPrepopulated, search_fields=['name'])
    10231029site.register(RelatedWithUUIDPKModel)
     1030site.register(PrepopulatedModel, PrepopulatedReadOnlyAdmin)
    10241031
    10251032# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    10261033# That way we cover all four cases:
  • tests/admin_views/models.py

    diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py
    index 59228876c5..0d98cb962d 100644
    a b class Author(models.Model):  
    979979class Authorship(models.Model):
    980980    book = models.ForeignKey(Book, models.CASCADE)
    981981    author = models.ForeignKey(Author, models.CASCADE)
     982
     983
     984# Model for 29929
     985class PrepopulatedModel(models.Model):
     986    input_value = models.TextField()
     987    to_be_prepopulated = models.TextField()
  • tests/admin_views/tests.py

    diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
    index 908f78bf9b..6c72cdeb2d 100644
    a b from .models import (  
    4646    MainPrepopulated, Media, ModelWithStringPrimaryKey, OtherStory, Paper,
    4747    Parent, ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona,
    4848    Picture, Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post,
    49     PrePopulatedPost, Promo, Question, ReadablePizza, ReadOnlyPizza,
     49    PrePopulatedPost, PrepopulatedModel, Promo, Question, ReadablePizza, ReadOnlyPizza,
    5050    Recommendation, Recommender, RelatedPrepopulated, RelatedWithUUIDPKModel,
    5151    Report, Restaurant, RowLevelChangePermissionModel, SecretHideout, Section,
    5252    ShortMessage, Simple, State, Story, SuperSecretHideout, SuperVillain,
    class AdminViewBasicTest(AdminViewBasicTestCase):  
    972972        self.assertContains(response, '<th scope="col"  class="column-value">')
    973973        self.assertNotContains(response, '<th scope="col"  class="sortable column')
    974974
     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
    975984
    976985@override_settings(TEMPLATES=[{
    977986    'BACKEND': 'django.template.backends.django.DjangoTemplates',
Back to Top