Ticket #12561: patch-12561-1.diff

File patch-12561-1.diff, 5.2 KB (added by nessita, 5 years ago)

Improved the tests. Added default values on parent class for can_delete and can_order. Ran the whole test suite, all green.

  • django/contrib/admin/options.py

     
    11821182    template = None
    11831183    verbose_name = None
    11841184    verbose_name_plural = None
     1185    can_delete = False
     1186    can_order = False
    11851187
    11861188    def __init__(self, parent_model, admin_site):
    11871189        self.admin_site = admin_site
     
    12271229            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    12281230            "extra": self.extra,
    12291231            "max_num": self.max_num,
     1232            "can_delete": self.can_delete,
     1233            "can_order": self.can_order,
    12301234        }
    12311235        defaults.update(kwargs)
    12321236        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • tests/regressiontests/modeladmin/models.py

     
    291291...     form = AdminConcertForm
    292292...     model = Concert
    293293...     fk_name = 'main_band'
     294...     can_delete = True
    294295
    295296>>> class BandAdmin(ModelAdmin):
    296297...     inlines = [
  • tests/regressiontests/admin_inlines/tests.py

     
     1# coding: utf-8
     2
     3from django.test import TestCase
     4
     5# local test models
     6from models import Holder, Inner, InnerInline
     7
     8class TestInline(TestCase):
     9    fixtures = ['admin-views-users.xml']
     10
     11    def setUp(self):
     12        holder = Holder(dummy=13)
     13        holder.save()
     14        Inner(dummy=42, holder=holder).save()
     15        self.change_url = '/test_admin/admin/admin_inlines/holder/%i/' % holder.id
     16
     17        result = self.client.login(username='super', password='secret')
     18        self.failUnlessEqual(result, True)
     19
     20    def tearDown(self):
     21        self.client.logout()
     22
     23    def test_can_delete(self):
     24        """
     25        can_delete should be passed to inlineformset factory.
     26        """
     27        response = self.client.get(self.change_url)
     28        inner_formset = response.context[-1]['inline_admin_formsets'][0].formset
     29        expected = InnerInline.can_delete
     30        actual = inner_formset.can_delete
     31        self.assertEqual(expected, actual, 'can_delete must be equal')
     32
     33    def test_can_order(self):
     34        """
     35        can_order should be passed to inlineformset factory.
     36        """
     37        response = self.client.get(self.change_url)
     38        inner_formset = response.context[-1]['inline_admin_formsets'][0].formset
     39        expected = InnerInline.can_order
     40        actual = inner_formset.can_order
     41        self.assertEqual(expected, actual, 'can_order must be equal')
  • tests/regressiontests/admin_inlines/fixtures/admin-views-users.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<django-objects version="1.0">
     3    <object pk="100" model="auth.user">
     4        <field type="CharField" name="username">super</field>
     5        <field type="CharField" name="first_name">Super</field>
     6        <field type="CharField" name="last_name">User</field>
     7        <field type="CharField" name="email">super@example.com</field>
     8        <field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field>
     9        <field type="BooleanField" name="is_staff">True</field>
     10        <field type="BooleanField" name="is_active">True</field>
     11        <field type="BooleanField" name="is_superuser">True</field>
     12        <field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field>
     13        <field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field>
     14        <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
     15        <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
     16    </object>
     17</django-objects>
  • tests/regressiontests/admin_inlines/models.py

     
    33
    44"""
    55from django.db import models
     6from django.contrib import admin
    67from django.contrib.contenttypes.models import ContentType
    78from django.contrib.contenttypes import generic
    89
     
    2930    def __unicode__(self):
    3031        return u'I am %s, a child of %s' % (self.name, self.parent)
    3132
     33
     34class Holder(models.Model):
     35    dummy = models.IntegerField()
     36
     37
     38class Inner(models.Model):
     39    dummy = models.IntegerField()
     40    holder = models.ForeignKey(Holder)
     41
     42
     43class InnerInline(admin.StackedInline):
     44    model = Inner
     45    can_delete = False
     46    can_order = True
     47
     48
     49# Test bug #12561
     50admin.site.register(Holder, inlines=[InnerInline])
     51
    3252__test__ = {'API_TESTS': """
    3353
    3454# Regression test for #9362
Back to Top