Ticket #12749: 12749-tests.diff
File 12749-tests.diff, 2.6 KB (added by , 15 years ago) |
---|
-
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): 48 48 # Test bug #12561 49 49 admin.site.register(Holder, inlines=[InnerInline]) 50 50 51 52 # Models for #12749 53 54 class Person(models.Model): 55 firstname = models.CharField(max_length=15) 56 57 class OutfitItem(models.Model): 58 name = models.CharField(max_length=15) 59 60 class Fashionista(models.Model): 61 person = models.OneToOneField(Person, primary_key=True) 62 weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True) 63 64 class ShoppingWeakness(models.Model): 65 fashionista = models.ForeignKey(Fashionista) 66 item = models.ForeignKey(OutfitItem) 67 68 class InlineWeakness(admin.TabularInline): 69 model = ShoppingWeakness 70 extra = 1 71 72 admin.site.register(Fashionista, inlines=[InlineWeakness]) 73 74 51 75 __test__ = {'API_TESTS': """ 52 76 53 77 # 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): 28 28 actual = inner_formset.can_delete 29 29 self.assertEqual(expected, actual, 'can_delete must be equal') 30 30 31 32 # Tests for #12749 33 34 from models import Person, OutfitItem, Fashionista 35 36 class 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)