Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed a number of tests that were failing in Oracle due to fa…

…lse assumptions about the primary keys of objects.

Backport of r15779 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15780 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1c08ca568fa83f89119d472e0b77bb088ea2f259 1 parent 05b197d
Ian Kelly authored March 09, 2011
57  tests/modeltests/model_formsets/tests.py
@@ -71,7 +71,7 @@ def test_change_form_deletion_when_invalid(self):
71 71
             'form-TOTAL_FORMS': u'1',
72 72
             'form-INITIAL_FORMS': u'1',
73 73
             'form-MAX_NUM_FORMS': u'0',
74  
-            'form-0-id': u'1',
  74
+            'form-0-id': unicode(poet.id),
75 75
             'form-0-name': u'x' * 1000,
76 76
         }
77 77
         formset = PoetFormSet(data, queryset=Poet.objects.all())
@@ -251,9 +251,9 @@ def test_commit_false(self):
251 251
             'form-TOTAL_FORMS': '2', # the number of forms rendered
252 252
             'form-INITIAL_FORMS': '1', # the number of forms with initial data
253 253
             'form-MAX_NUM_FORMS': '', # the max number of forms
254  
-            'form-0-id': '1',
  254
+            'form-0-id': str(meeting.id),
255 255
             'form-0-name': '2nd Tuesday of the Week Meeting',
256  
-            'form-0-authors': [2, 1, 3, 4],
  256
+            'form-0-authors': [author2.id, author1.id, author3.id, author4.id],
257 257
             'form-1-name': '',
258 258
             'form-1-authors': '',
259 259
             'form-1-DELETE': '',
@@ -458,7 +458,7 @@ def test_inline_formsets(self):
458 458
             'book_set-TOTAL_FORMS': '3', # the number of forms rendered
459 459
             'book_set-INITIAL_FORMS': '1', # the number of forms with initial data
460 460
             'book_set-MAX_NUM_FORMS': '', # the max number of forms
461  
-            'book_set-0-id': '1',
  461
+            'book_set-0-id': str(book1.id),
462 462
             'book_set-0-title': 'Les Fleurs du Mal',
463 463
             'book_set-1-title': 'Les Paradis Artificiels',
464 464
             'book_set-2-title': '',
@@ -731,14 +731,15 @@ def test_custom_pk(self):
731 731
         self.assertTrue(formset.is_valid())
732 732
         saved = formset.save()
733 733
         self.assertEqual(len(saved), 1)
734  
-        owner, = saved
735  
-        self.assertEqual(owner.name, 'Joe Perry')
736  
-        self.assertEqual(owner.place.name, 'Giordanos')
  734
+        owner1, = saved
  735
+        self.assertEqual(owner1.name, 'Joe Perry')
  736
+        self.assertEqual(owner1.place.name, 'Giordanos')
737 737
 
738 738
         formset = FormSet(instance=place)
739 739
         self.assertEqual(len(formset.forms), 3)
740 740
         self.assertEqual(formset.forms[0].as_p(),
741  
-            '<p><label for="id_owner_set-0-name">Name:</label> <input id="id_owner_set-0-name" type="text" name="owner_set-0-name" value="Joe Perry" maxlength="100" /><input type="hidden" name="owner_set-0-place" value="1" id="id_owner_set-0-place" /><input type="hidden" name="owner_set-0-auto_id" value="1" id="id_owner_set-0-auto_id" /></p>')
  741
+            '<p><label for="id_owner_set-0-name">Name:</label> <input id="id_owner_set-0-name" type="text" name="owner_set-0-name" value="Joe Perry" maxlength="100" /><input type="hidden" name="owner_set-0-place" value="1" id="id_owner_set-0-place" /><input type="hidden" name="owner_set-0-auto_id" value="%d" id="id_owner_set-0-auto_id" /></p>'
  742
+            % owner1.auto_id)
742 743
         self.assertEqual(formset.forms[1].as_p(),
743 744
             '<p><label for="id_owner_set-1-name">Name:</label> <input id="id_owner_set-1-name" type="text" name="owner_set-1-name" maxlength="100" /><input type="hidden" name="owner_set-1-place" value="1" id="id_owner_set-1-place" /><input type="hidden" name="owner_set-1-auto_id" id="id_owner_set-1-auto_id" /></p>')
744 745
         self.assertEqual(formset.forms[2].as_p(),
@@ -748,7 +749,7 @@ def test_custom_pk(self):
748 749
             'owner_set-TOTAL_FORMS': '3',
749 750
             'owner_set-INITIAL_FORMS': '1',
750 751
             'owner_set-MAX_NUM_FORMS': '',
751  
-            'owner_set-0-auto_id': u'1',
  752
+            'owner_set-0-auto_id': unicode(owner1.auto_id),
752 753
             'owner_set-0-name': u'Joe Perry',
753 754
             'owner_set-1-auto_id': '',
754 755
             'owner_set-1-name': u'Jack Berry',
@@ -759,9 +760,9 @@ def test_custom_pk(self):
759 760
         self.assertTrue(formset.is_valid())
760 761
         saved = formset.save()
761 762
         self.assertEqual(len(saved), 1)
762  
-        owner, = saved
763  
-        self.assertEqual(owner.name, 'Jack Berry')
764  
-        self.assertEqual(owner.place.name, 'Giordanos')
  763
+        owner2, = saved
  764
+        self.assertEqual(owner2.name, 'Jack Berry')
  765
+        self.assertEqual(owner2.place.name, 'Giordanos')
765 766
 
766 767
         # Ensure a custom primary key that is a ForeignKey or OneToOneField get rendered for the user to choose.
767 768
 
@@ -770,19 +771,21 @@ def test_custom_pk(self):
770 771
         self.assertEqual(formset.forms[0].as_p(),
771 772
             '<p><label for="id_form-0-owner">Owner:</label> <select name="form-0-owner" id="id_form-0-owner">\n'
772 773
             '<option value="" selected="selected">---------</option>\n'
773  
-            '<option value="1">Joe Perry at Giordanos</option>\n'
774  
-            '<option value="2">Jack Berry at Giordanos</option>\n'
  774
+            '<option value="%d">Joe Perry at Giordanos</option>\n'
  775
+            '<option value="%d">Jack Berry at Giordanos</option>\n'
775 776
             '</select></p>\n'
776  
-            '<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>')
  777
+            '<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>'
  778
+            % (owner1.auto_id, owner2.auto_id))
777 779
 
778  
-        owner = Owner.objects.get(name=u'Joe Perry')
  780
+        owner1 = Owner.objects.get(name=u'Joe Perry')
779 781
         FormSet = inlineformset_factory(Owner, OwnerProfile, max_num=1, can_delete=False)
780 782
         self.assertEqual(FormSet.max_num, 1)
781 783
 
782  
-        formset = FormSet(instance=owner)
  784
+        formset = FormSet(instance=owner1)
783 785
         self.assertEqual(len(formset.forms), 1)
784 786
         self.assertEqual(formset.forms[0].as_p(),
785  
-            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="1" id="id_ownerprofile-0-owner" /></p>')
  787
+            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
  788
+            % owner1.auto_id)
786 789
 
787 790
         data = {
788 791
             'ownerprofile-TOTAL_FORMS': '1',
@@ -791,32 +794,33 @@ def test_custom_pk(self):
791 794
             'ownerprofile-0-owner': '',
792 795
             'ownerprofile-0-age': u'54',
793 796
         }
794  
-        formset = FormSet(data, instance=owner)
  797
+        formset = FormSet(data, instance=owner1)
795 798
         self.assertTrue(formset.is_valid())
796 799
         saved = formset.save()
797 800
         self.assertEqual(len(saved), 1)
798 801
         profile1, = saved
799  
-        self.assertEqual(profile1.owner, owner)
  802
+        self.assertEqual(profile1.owner, owner1)
800 803
         self.assertEqual(profile1.age, 54)
801 804
 
802  
-        formset = FormSet(instance=owner)
  805
+        formset = FormSet(instance=owner1)
803 806
         self.assertEqual(len(formset.forms), 1)
804 807
         self.assertEqual(formset.forms[0].as_p(),
805  
-            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="1" id="id_ownerprofile-0-owner" /></p>')
  808
+            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
  809
+            % owner1.auto_id)
806 810
 
807 811
         data = {
808 812
             'ownerprofile-TOTAL_FORMS': '1',
809 813
             'ownerprofile-INITIAL_FORMS': '1',
810 814
             'ownerprofile-MAX_NUM_FORMS': '1',
811  
-            'ownerprofile-0-owner': u'1',
  815
+            'ownerprofile-0-owner': unicode(owner1.auto_id),
812 816
             'ownerprofile-0-age': u'55',
813 817
         }
814  
-        formset = FormSet(data, instance=owner)
  818
+        formset = FormSet(data, instance=owner1)
815 819
         self.assertTrue(formset.is_valid())
816 820
         saved = formset.save()
817 821
         self.assertEqual(len(saved), 1)
818 822
         profile1, = saved
819  
-        self.assertEqual(profile1.owner, owner)
  823
+        self.assertEqual(profile1.owner, owner1)
820 824
         self.assertEqual(profile1.age, 55)
821 825
 
822 826
     def test_unique_true_enforces_max_num_one(self):
@@ -957,7 +961,8 @@ def test_callable_defaults(self):
957 961
         result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result)
958 962
         self.assertEqual(result,
959 963
             '<p><label for="id_membership_set-0-date_joined">Date joined:</label> <input type="text" name="membership_set-0-date_joined" value="__DATETIME__" id="id_membership_set-0-date_joined" /><input type="hidden" name="initial-membership_set-0-date_joined" value="__DATETIME__" id="initial-membership_set-0-id_membership_set-0-date_joined" /></p>\n'
960  
-            '<p><label for="id_membership_set-0-karma">Karma:</label> <input type="text" name="membership_set-0-karma" id="id_membership_set-0-karma" /><input type="hidden" name="membership_set-0-person" value="1" id="id_membership_set-0-person" /><input type="hidden" name="membership_set-0-id" id="id_membership_set-0-id" /></p>')
  964
+            '<p><label for="id_membership_set-0-karma">Karma:</label> <input type="text" name="membership_set-0-karma" id="id_membership_set-0-karma" /><input type="hidden" name="membership_set-0-person" value="%d" id="id_membership_set-0-person" /><input type="hidden" name="membership_set-0-id" id="id_membership_set-0-id" /></p>'
  965
+            % person.id)
961 966
 
962 967
         # test for validation with callable defaults. Validations rely on hidden fields
963 968
 
132  tests/regressiontests/admin_views/tests.py
@@ -709,8 +709,8 @@ def testChangeView(self):
709 709
         self.client.get('/test_admin/admin/logout/')
710 710
 
711 711
         # Test redirection when using row-level change permissions. Refs #11513.
712  
-        RowLevelChangePermissionModel.objects.create(name="odd id")
713  
-        RowLevelChangePermissionModel.objects.create(name="even id")
  712
+        RowLevelChangePermissionModel.objects.create(id=1, name="odd id")
  713
+        RowLevelChangePermissionModel.objects.create(id=2, name="even id")
714 714
         for login_dict in [self.super_login, self.changeuser_login, self.adduser_login, self.deleteuser_login]:
715 715
             self.client.get('/test_admin/admin/')
716 716
             self.client.post('/test_admin/admin/', login_dict)
@@ -766,12 +766,13 @@ def testCustomModelAdminTemplates(self):
766 766
         })
767 767
         self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/')
768 768
         self.assertEqual(CustomArticle.objects.all().count(), 1)
  769
+        article_pk = CustomArticle.objects.all()[0].pk
769 770
 
770 771
         # Test custom delete, change, and object history templates
771 772
         # Test custom change form template
772  
-        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/')
  773
+        request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/' % article_pk)
773 774
         self.assertTemplateUsed(request, 'custom_admin/change_form.html')
774  
-        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/')
  775
+        request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/delete/' % article_pk)
775 776
         self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html')
776 777
         request = self.client.post('/test_admin/admin/admin_views/customarticle/', data={
777 778
                 'index': 0,
@@ -779,7 +780,7 @@ def testCustomModelAdminTemplates(self):
779 780
                 '_selected_action': ['1'],
780 781
             })
781 782
         self.assertTemplateUsed(request, 'custom_admin/delete_selected_confirmation.html')
782  
-        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/')
  783
+        request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/history/' % article_pk)
783 784
         self.assertTemplateUsed(request, 'custom_admin/object_history.html')
784 785
 
785 786
         self.client.get('/test_admin/admin/logout/')
@@ -1348,27 +1349,27 @@ def test_non_field_errors(self):
1348 1349
         ''' Ensure that non field errors are displayed for each of the
1349 1350
             forms in the changelist's formset. Refs #13126.
1350 1351
         '''
1351  
-        FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai')
1352  
-        FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india')
1353  
-        FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza')
  1352
+        fd1 = FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai')
  1353
+        fd2 = FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india')
  1354
+        fd3 = FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza')
1354 1355
 
1355 1356
         data = {
1356 1357
             "form-TOTAL_FORMS": "3",
1357 1358
             "form-INITIAL_FORMS": "3",
1358 1359
             "form-MAX_NUM_FORMS": "0",
1359 1360
 
1360  
-            "form-0-id": "1",
  1361
+            "form-0-id": str(fd1.id),
1361 1362
             "form-0-reference": "123",
1362 1363
             "form-0-driver": "bill",
1363 1364
             "form-0-restaurant": "thai",
1364 1365
 
1365 1366
             # Same data as above: Forbidden because of unique_together!
1366  
-            "form-1-id": "2",
  1367
+            "form-1-id": str(fd2.id),
1367 1368
             "form-1-reference": "456",
1368 1369
             "form-1-driver": "bill",
1369 1370
             "form-1-restaurant": "thai",
1370 1371
 
1371  
-            "form-2-id": "3",
  1372
+            "form-2-id": str(fd3.id),
1372 1373
             "form-2-reference": "789",
1373 1374
             "form-2-driver": "bill",
1374 1375
             "form-2-restaurant": "pizza",
@@ -1383,19 +1384,19 @@ def test_non_field_errors(self):
1383 1384
             "form-INITIAL_FORMS": "3",
1384 1385
             "form-MAX_NUM_FORMS": "0",
1385 1386
 
1386  
-            "form-0-id": "1",
  1387
+            "form-0-id": str(fd1.id),
1387 1388
             "form-0-reference": "123",
1388 1389
             "form-0-driver": "bill",
1389 1390
             "form-0-restaurant": "thai",
1390 1391
 
1391 1392
             # Same data as above: Forbidden because of unique_together!
1392  
-            "form-1-id": "2",
  1393
+            "form-1-id": str(fd2.id),
1393 1394
             "form-1-reference": "456",
1394 1395
             "form-1-driver": "bill",
1395 1396
             "form-1-restaurant": "thai",
1396 1397
 
1397 1398
             # Same data also.
1398  
-            "form-2-id": "3",
  1399
+            "form-2-id": str(fd3.id),
1399 1400
             "form-2-reference": "789",
1400 1401
             "form-2-driver": "bill",
1401 1402
             "form-2-restaurant": "thai",
@@ -1548,28 +1549,28 @@ def test_pk_hidden_fields(self):
1548 1549
             separately (not in the table), and only once.
1549 1550
             Refs #12475.
1550 1551
         """
1551  
-        Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
1552  
-        Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
  1552
+        story1 = Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
  1553
+        story2 = Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
1553 1554
         response = self.client.get('/test_admin/admin/admin_views/story/')
1554 1555
         self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
1555 1556
         self.assertContains(response, 'id="id_form-1-id"', 1)
1556  
-        self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="2" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="1" id="id_form-1-id" />\n</div>')
1557  
-        self.assertContains(response, '<td>1</td>', 1)
1558  
-        self.assertContains(response, '<td>2</td>', 1)
  1557
+        self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id))
  1558
+        self.assertContains(response, '<td>%d</td>' % story1.id, 1)
  1559
+        self.assertContains(response, '<td>%d</td>' % story2.id, 1)
1559 1560
 
1560 1561
     def test_pk_hidden_fields_with_list_display_links(self):
1561 1562
         """ Similarly as test_pk_hidden_fields, but when the hidden pk fields are
1562 1563
             referenced in list_display_links.
1563 1564
             Refs #12475.
1564 1565
         """
1565  
-        OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
1566  
-        OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
  1566
+        story1 = OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
  1567
+        story2 = OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
1567 1568
         response = self.client.get('/test_admin/admin/admin_views/otherstory/')
1568 1569
         self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
1569 1570
         self.assertContains(response, 'id="id_form-1-id"', 1)
1570  
-        self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="2" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="1" id="id_form-1-id" />\n</div>')
1571  
-        self.assertContains(response, '<th><a href="1/">1</a></th>', 1)
1572  
-        self.assertContains(response, '<th><a href="2/">2</a></th>', 1)
  1571
+        self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id))
  1572
+        self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1)
  1573
+        self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story2.id, story2.id), 1)
1573 1574
 
1574 1575
 
1575 1576
 class AdminSearchTest(TestCase):
@@ -1643,9 +1644,13 @@ def testInline(self):
1643 1644
         self.assertEqual(BarAccount.objects.all()[0].username, bar_user)
1644 1645
         self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
1645 1646
 
  1647
+        persona_id = Persona.objects.all()[0].id
  1648
+        foo_id = FooAccount.objects.all()[0].id
  1649
+        bar_id = BarAccount.objects.all()[0].id
  1650
+
1646 1651
         # test the edit case
1647 1652
 
1648  
-        response = self.client.get('/test_admin/admin/admin_views/persona/1/')
  1653
+        response = self.client.get('/test_admin/admin/admin_views/persona/%d/' % persona_id)
1649 1654
         names = name_re.findall(response.content)
1650 1655
         # make sure we have no duplicate HTML names
1651 1656
         self.assertEqual(len(names), len(set(names)))
@@ -1658,18 +1663,18 @@ def testInline(self):
1658 1663
             "accounts-MAX_NUM_FORMS": u"0",
1659 1664
 
1660 1665
             "accounts-0-username": "%s-1" % foo_user,
1661  
-            "accounts-0-account_ptr": "1",
1662  
-            "accounts-0-persona": "1",
  1666
+            "accounts-0-account_ptr": str(foo_id),
  1667
+            "accounts-0-persona": str(persona_id),
1663 1668
 
1664 1669
             "accounts-2-TOTAL_FORMS": u"2",
1665 1670
             "accounts-2-INITIAL_FORMS": u"1",
1666 1671
             "accounts-2-MAX_NUM_FORMS": u"0",
1667 1672
 
1668 1673
             "accounts-2-0-username": "%s-1" % bar_user,
1669  
-            "accounts-2-0-account_ptr": "2",
1670  
-            "accounts-2-0-persona": "1",
  1674
+            "accounts-2-0-account_ptr": str(bar_id),
  1675
+            "accounts-2-0-persona": str(persona_id),
1671 1676
         }
1672  
-        response = self.client.post('/test_admin/admin/admin_views/persona/1/', post_data)
  1677
+        response = self.client.post('/test_admin/admin/admin_views/persona/%d/' % persona_id, post_data)
1673 1678
         self.assertEqual(response.status_code, 302)
1674 1679
         self.assertEqual(Persona.objects.count(), 1)
1675 1680
         self.assertEqual(FooAccount.objects.count(), 1)
@@ -1946,10 +1951,10 @@ def setUp(self):
1946 1951
         file1.write('a' * (2 ** 21))
1947 1952
         filename = file1.name
1948 1953
         file1.close()
1949  
-        g = Gallery(name="Test Gallery")
1950  
-        g.save()
1951  
-        p = Picture(name="Test Picture", image=filename, gallery=g)
1952  
-        p.save()
  1954
+        self.gallery = Gallery(name="Test Gallery")
  1955
+        self.gallery.save()
  1956
+        self.picture = Picture(name="Test Picture", image=filename, gallery=self.gallery)
  1957
+        self.picture.save()
1953 1958
 
1954 1959
     def tearDown(self):
1955 1960
         self.client.logout()
@@ -1963,16 +1968,16 @@ def test_inline_file_upload_edit_validation_error_post(self):
1963 1968
             "pictures-TOTAL_FORMS": u"2",
1964 1969
             "pictures-INITIAL_FORMS": u"1",
1965 1970
             "pictures-MAX_NUM_FORMS": u"0",
1966  
-            "pictures-0-id": u"1",
1967  
-            "pictures-0-gallery": u"1",
  1971
+            "pictures-0-id": unicode(self.picture.id),
  1972
+            "pictures-0-gallery": unicode(self.gallery.id),
1968 1973
             "pictures-0-name": "Test Picture",
1969 1974
             "pictures-0-image": "",
1970 1975
             "pictures-1-id": "",
1971  
-            "pictures-1-gallery": "1",
  1976
+            "pictures-1-gallery": str(self.gallery.id),
1972 1977
             "pictures-1-name": "Test Picture 2",
1973 1978
             "pictures-1-image": "",
1974 1979
         }
1975  
-        response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
  1980
+        response = self.client.post('/test_admin/%s/admin_views/gallery/%d/' % (self.urlbit, self.gallery.id), post_data)
1976 1981
         self.assertTrue(response._container[0].find("Currently:") > -1)
1977 1982
 
1978 1983
 
@@ -2077,29 +2082,31 @@ def test_simple_inline(self):
2077 2082
         "A simple model can be saved as inlines"
2078 2083
         # First add a new inline
2079 2084
         self.post_data['widget_set-0-name'] = "Widget 1"
2080  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2085
+        collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
  2086
+        response = self.client.post(collector_url, self.post_data)
2081 2087
         self.assertEqual(response.status_code, 302)
2082 2088
         self.assertEqual(Widget.objects.count(), 1)
2083 2089
         self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
  2090
+        widget_id = Widget.objects.all()[0].id
2084 2091
 
2085 2092
         # Check that the PK link exists on the rendered form
2086  
-        response = self.client.get('/test_admin/admin/admin_views/collector/1/')
  2093
+        response = self.client.get(collector_url)
2087 2094
         self.assertContains(response, 'name="widget_set-0-id"')
2088 2095
 
2089 2096
         # Now resave that inline
2090 2097
         self.post_data['widget_set-INITIAL_FORMS'] = "1"
2091  
-        self.post_data['widget_set-0-id'] = "1"
  2098
+        self.post_data['widget_set-0-id'] = str(widget_id)
2092 2099
         self.post_data['widget_set-0-name'] = "Widget 1"
2093  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2100
+        response = self.client.post(collector_url, self.post_data)
2094 2101
         self.assertEqual(response.status_code, 302)
2095 2102
         self.assertEqual(Widget.objects.count(), 1)
2096 2103
         self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
2097 2104
 
2098 2105
         # Now modify that inline
2099 2106
         self.post_data['widget_set-INITIAL_FORMS'] = "1"
2100  
-        self.post_data['widget_set-0-id'] = "1"
  2107
+        self.post_data['widget_set-0-id'] = str(widget_id)
2101 2108
         self.post_data['widget_set-0-name'] = "Widget 1 Updated"
2102  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2109
+        response = self.client.post(collector_url, self.post_data)
2103 2110
         self.assertEqual(response.status_code, 302)
2104 2111
         self.assertEqual(Widget.objects.count(), 1)
2105 2112
         self.assertEqual(Widget.objects.all()[0].name, "Widget 1 Updated")
@@ -2108,29 +2115,30 @@ def test_explicit_autofield_inline(self):
2108 2115
         "A model with an explicit autofield primary key can be saved as inlines. Regression for #8093"
2109 2116
         # First add a new inline
2110 2117
         self.post_data['grommet_set-0-name'] = "Grommet 1"
2111  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2118
+        collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
  2119
+        response = self.client.post(collector_url, self.post_data)
2112 2120
         self.assertEqual(response.status_code, 302)
2113 2121
         self.assertEqual(Grommet.objects.count(), 1)
2114 2122
         self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
2115 2123
 
2116 2124
         # Check that the PK link exists on the rendered form
2117  
-        response = self.client.get('/test_admin/admin/admin_views/collector/1/')
  2125
+        response = self.client.get(collector_url)
2118 2126
         self.assertContains(response, 'name="grommet_set-0-code"')
2119 2127
 
2120 2128
         # Now resave that inline
2121 2129
         self.post_data['grommet_set-INITIAL_FORMS'] = "1"
2122  
-        self.post_data['grommet_set-0-code'] = "1"
  2130
+        self.post_data['grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
2123 2131
         self.post_data['grommet_set-0-name'] = "Grommet 1"
2124  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2132
+        response = self.client.post(collector_url, self.post_data)
2125 2133
         self.assertEqual(response.status_code, 302)
2126 2134
         self.assertEqual(Grommet.objects.count(), 1)
2127 2135
         self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
2128 2136
 
2129 2137
         # Now modify that inline
2130 2138
         self.post_data['grommet_set-INITIAL_FORMS'] = "1"
2131  
-        self.post_data['grommet_set-0-code'] = "1"
  2139
+        self.post_data['grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
2132 2140
         self.post_data['grommet_set-0-name'] = "Grommet 1 Updated"
2133  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2141
+        response = self.client.post(collector_url, self.post_data)
2134 2142
         self.assertEqual(response.status_code, 302)
2135 2143
         self.assertEqual(Grommet.objects.count(), 1)
2136 2144
         self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated")
@@ -2140,20 +2148,21 @@ def test_char_pk_inline(self):
2140 2148
         # First add a new inline
2141 2149
         self.post_data['doohickey_set-0-code'] = "DH1"
2142 2150
         self.post_data['doohickey_set-0-name'] = "Doohickey 1"
2143  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2151
+        collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
  2152
+        response = self.client.post(collector_url, self.post_data)
2144 2153
         self.assertEqual(response.status_code, 302)
2145 2154
         self.assertEqual(DooHickey.objects.count(), 1)
2146 2155
         self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
2147 2156
 
2148 2157
         # Check that the PK link exists on the rendered form
2149  
-        response = self.client.get('/test_admin/admin/admin_views/collector/1/')
  2158
+        response = self.client.get(collector_url)
2150 2159
         self.assertContains(response, 'name="doohickey_set-0-code"')
2151 2160
 
2152 2161
         # Now resave that inline
2153 2162
         self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
2154 2163
         self.post_data['doohickey_set-0-code'] = "DH1"
2155 2164
         self.post_data['doohickey_set-0-name'] = "Doohickey 1"
2156  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2165
+        response = self.client.post(collector_url, self.post_data)
2157 2166
         self.assertEqual(response.status_code, 302)
2158 2167
         self.assertEqual(DooHickey.objects.count(), 1)
2159 2168
         self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
@@ -2162,7 +2171,7 @@ def test_char_pk_inline(self):
2162 2171
         self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
2163 2172
         self.post_data['doohickey_set-0-code'] = "DH1"
2164 2173
         self.post_data['doohickey_set-0-name'] = "Doohickey 1 Updated"
2165  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2174
+        response = self.client.post(collector_url, self.post_data)
2166 2175
         self.assertEqual(response.status_code, 302)
2167 2176
         self.assertEqual(DooHickey.objects.count(), 1)
2168 2177
         self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated")
@@ -2203,29 +2212,31 @@ def test_inherited_inline(self):
2203 2212
         "An inherited model can be saved as inlines. Regression for #11042"
2204 2213
         # First add a new inline
2205 2214
         self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1"
2206  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2215
+        collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
  2216
+        response = self.client.post(collector_url, self.post_data)
2207 2217
         self.assertEqual(response.status_code, 302)
2208 2218
         self.assertEqual(FancyDoodad.objects.count(), 1)
2209 2219
         self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
  2220
+        doodad_pk = FancyDoodad.objects.all()[0].pk
2210 2221
 
2211 2222
         # Check that the PK link exists on the rendered form
2212  
-        response = self.client.get('/test_admin/admin/admin_views/collector/1/')
  2223
+        response = self.client.get(collector_url)
2213 2224
         self.assertContains(response, 'name="fancydoodad_set-0-doodad_ptr"')
2214 2225
 
2215 2226
         # Now resave that inline
2216 2227
         self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1"
2217  
-        self.post_data['fancydoodad_set-0-doodad_ptr'] = "1"
  2228
+        self.post_data['fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
2218 2229
         self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1"
2219  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2230
+        response = self.client.post(collector_url, self.post_data)
2220 2231
         self.assertEqual(response.status_code, 302)
2221 2232
         self.assertEqual(FancyDoodad.objects.count(), 1)
2222 2233
         self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
2223 2234
 
2224 2235
         # Now modify that inline
2225 2236
         self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1"
2226  
-        self.post_data['fancydoodad_set-0-doodad_ptr'] = "1"
  2237
+        self.post_data['fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
2227 2238
         self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1 Updated"
2228  
-        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
  2239
+        response = self.client.post(collector_url, self.post_data)
2229 2240
         self.assertEqual(response.status_code, 302)
2230 2241
         self.assertEqual(FancyDoodad.objects.count(), 1)
2231 2242
         self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
@@ -2730,4 +2741,3 @@ def test_multiple_years(self):
2730 2741
             self.assert_non_localized_year(response, 2000)
2731 2742
             self.assert_non_localized_year(response, 2003)
2732 2743
             self.assert_non_localized_year(response, 2005)
2733  
-
6  tests/regressiontests/inline_formsets/tests.py
@@ -59,13 +59,13 @@ def test_change_form_deletion_when_invalid(self):
59 59
         """
60 60
         PoemFormSet = inlineformset_factory(Poet, Poem, can_delete=True)
61 61
         poet = Poet.objects.create(name='test')
62  
-        poet.poem_set.create(name='test poem')
  62
+        poem = poet.poem_set.create(name='test poem')
63 63
         data = {
64 64
             'poem_set-TOTAL_FORMS': u'1',
65 65
             'poem_set-INITIAL_FORMS': u'1',
66 66
             'poem_set-MAX_NUM_FORMS': u'0',
67  
-            'poem_set-0-id': u'1',
68  
-            'poem_set-0-poem': u'1',
  67
+            'poem_set-0-id': unicode(poem.id),
  68
+            'poem_set-0-poem': unicode(poem.id),
69 69
             'poem_set-0-name': u'x' * 1000,
70 70
         }
71 71
         formset = PoemFormSet(data, instance=poet)

0 notes on commit 1c08ca5

Please sign in to comment.
Something went wrong with that request. Please try again.