Ticket #12749: 12749-tests.diff

File 12749-tests.diff, 2.6 KB (added by jkocherhans, 15 years ago)

Pull the code from nessita's patches into an extra test case for admin_inlines.

  • tests/regressiontests/admin_inlines/models.py

    diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
    index 303c06a..14f4339 100644
    a b class InnerInline(admin.StackedInline):  
    4848# Test bug #12561
    4949admin.site.register(Holder, inlines=[InnerInline])
    5050
     51
     52# Models for #12749
     53
     54class Person(models.Model):
     55    firstname = models.CharField(max_length=15)
     56
     57class OutfitItem(models.Model):
     58    name = models.CharField(max_length=15)
     59
     60class Fashionista(models.Model):
     61    person = models.OneToOneField(Person, primary_key=True)
     62    weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True)
     63
     64class ShoppingWeakness(models.Model):
     65    fashionista = models.ForeignKey(Fashionista)
     66    item = models.ForeignKey(OutfitItem)
     67
     68class InlineWeakness(admin.TabularInline):
     69    model = ShoppingWeakness
     70    extra = 1
     71
     72admin.site.register(Fashionista, inlines=[InlineWeakness])
     73
     74
    5175__test__ = {'API_TESTS': """
    5276
    5377# Regression test for #9362
  • tests/regressiontests/admin_inlines/tests.py

    diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py
    index 75a6658..a845f96 100644
    a b class TestInline(TestCase):  
    2828        actual = inner_formset.can_delete
    2929        self.assertEqual(expected, actual, 'can_delete must be equal')
    3030
     31
     32# Tests for #12749
     33
     34from models import Person, OutfitItem, Fashionista
     35
     36class AdminTest(TestCase):
     37    fixtures = ['admin-views-users.xml']
     38
     39    def setUp(self):
     40        result = self.client.login(username='super', password='secret')
     41        self.failUnlessEqual(result, True)
     42
     43    def tearDown(self):
     44        self.client.logout()
     45
     46    def test_inline_primary(self):
     47        person = Person.objects.create(firstname='Imelda')
     48        item = OutfitItem.objects.create(name='Shoes')
     49        # Imelda likes shoes, but can't cary her own bags.
     50        data = {
     51            'shoppingweakness_set-TOTAL_FORMS': 1,
     52            'shoppingweakness_set-INITIAL_FORMS': 0,
     53            'shoppingweakness_set-MAX_NUM_FORMS': 0,
     54            '_save': u'Save',
     55            'person': person.id,
     56            'max_weight': 0,
     57            'shoppingweakness_set-0-item': item.id,
     58        }
     59        response = self.client.post('/test_admin/admin/admin_inlines/fashionista/add/', data)
     60        self.assertEqual(response.status_code, 302)
     61        self.assertEqual(len(Fashionista.objects.filter(person__firstname='Imelda')), 1)
Back to Top