Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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
@ikelly ikelly authored
View
57 tests/modeltests/model_formsets/tests.py
@@ -71,7 +71,7 @@ def test_change_form_deletion_when_invalid(self):
'form-TOTAL_FORMS': u'1',
'form-INITIAL_FORMS': u'1',
'form-MAX_NUM_FORMS': u'0',
- 'form-0-id': u'1',
+ 'form-0-id': unicode(poet.id),
'form-0-name': u'x' * 1000,
}
formset = PoetFormSet(data, queryset=Poet.objects.all())
@@ -251,9 +251,9 @@ def test_commit_false(self):
'form-TOTAL_FORMS': '2', # the number of forms rendered
'form-INITIAL_FORMS': '1', # the number of forms with initial data
'form-MAX_NUM_FORMS': '', # the max number of forms
- 'form-0-id': '1',
+ 'form-0-id': str(meeting.id),
'form-0-name': '2nd Tuesday of the Week Meeting',
- 'form-0-authors': [2, 1, 3, 4],
+ 'form-0-authors': [author2.id, author1.id, author3.id, author4.id],
'form-1-name': '',
'form-1-authors': '',
'form-1-DELETE': '',
@@ -458,7 +458,7 @@ def test_inline_formsets(self):
'book_set-TOTAL_FORMS': '3', # the number of forms rendered
'book_set-INITIAL_FORMS': '1', # the number of forms with initial data
'book_set-MAX_NUM_FORMS': '', # the max number of forms
- 'book_set-0-id': '1',
+ 'book_set-0-id': str(book1.id),
'book_set-0-title': 'Les Fleurs du Mal',
'book_set-1-title': 'Les Paradis Artificiels',
'book_set-2-title': '',
@@ -731,14 +731,15 @@ def test_custom_pk(self):
self.assertTrue(formset.is_valid())
saved = formset.save()
self.assertEqual(len(saved), 1)
- owner, = saved
- self.assertEqual(owner.name, 'Joe Perry')
- self.assertEqual(owner.place.name, 'Giordanos')
+ owner1, = saved
+ self.assertEqual(owner1.name, 'Joe Perry')
+ self.assertEqual(owner1.place.name, 'Giordanos')
formset = FormSet(instance=place)
self.assertEqual(len(formset.forms), 3)
self.assertEqual(formset.forms[0].as_p(),
- '<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>')
+ '<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>'
+ % owner1.auto_id)
self.assertEqual(formset.forms[1].as_p(),
'<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>')
self.assertEqual(formset.forms[2].as_p(),
@@ -748,7 +749,7 @@ def test_custom_pk(self):
'owner_set-TOTAL_FORMS': '3',
'owner_set-INITIAL_FORMS': '1',
'owner_set-MAX_NUM_FORMS': '',
- 'owner_set-0-auto_id': u'1',
+ 'owner_set-0-auto_id': unicode(owner1.auto_id),
'owner_set-0-name': u'Joe Perry',
'owner_set-1-auto_id': '',
'owner_set-1-name': u'Jack Berry',
@@ -759,9 +760,9 @@ def test_custom_pk(self):
self.assertTrue(formset.is_valid())
saved = formset.save()
self.assertEqual(len(saved), 1)
- owner, = saved
- self.assertEqual(owner.name, 'Jack Berry')
- self.assertEqual(owner.place.name, 'Giordanos')
+ owner2, = saved
+ self.assertEqual(owner2.name, 'Jack Berry')
+ self.assertEqual(owner2.place.name, 'Giordanos')
# Ensure a custom primary key that is a ForeignKey or OneToOneField get rendered for the user to choose.
@@ -770,19 +771,21 @@ def test_custom_pk(self):
self.assertEqual(formset.forms[0].as_p(),
'<p><label for="id_form-0-owner">Owner:</label> <select name="form-0-owner" id="id_form-0-owner">\n'
'<option value="" selected="selected">---------</option>\n'
- '<option value="1">Joe Perry at Giordanos</option>\n'
- '<option value="2">Jack Berry at Giordanos</option>\n'
+ '<option value="%d">Joe Perry at Giordanos</option>\n'
+ '<option value="%d">Jack Berry at Giordanos</option>\n'
'</select></p>\n'
- '<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>')
+ '<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>'
+ % (owner1.auto_id, owner2.auto_id))
- owner = Owner.objects.get(name=u'Joe Perry')
+ owner1 = Owner.objects.get(name=u'Joe Perry')
FormSet = inlineformset_factory(Owner, OwnerProfile, max_num=1, can_delete=False)
self.assertEqual(FormSet.max_num, 1)
- formset = FormSet(instance=owner)
+ formset = FormSet(instance=owner1)
self.assertEqual(len(formset.forms), 1)
self.assertEqual(formset.forms[0].as_p(),
- '<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>')
+ '<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>'
+ % owner1.auto_id)
data = {
'ownerprofile-TOTAL_FORMS': '1',
@@ -791,32 +794,33 @@ def test_custom_pk(self):
'ownerprofile-0-owner': '',
'ownerprofile-0-age': u'54',
}
- formset = FormSet(data, instance=owner)
+ formset = FormSet(data, instance=owner1)
self.assertTrue(formset.is_valid())
saved = formset.save()
self.assertEqual(len(saved), 1)
profile1, = saved
- self.assertEqual(profile1.owner, owner)
+ self.assertEqual(profile1.owner, owner1)
self.assertEqual(profile1.age, 54)
- formset = FormSet(instance=owner)
+ formset = FormSet(instance=owner1)
self.assertEqual(len(formset.forms), 1)
self.assertEqual(formset.forms[0].as_p(),
- '<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>')
+ '<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>'
+ % owner1.auto_id)
data = {
'ownerprofile-TOTAL_FORMS': '1',
'ownerprofile-INITIAL_FORMS': '1',
'ownerprofile-MAX_NUM_FORMS': '1',
- 'ownerprofile-0-owner': u'1',
+ 'ownerprofile-0-owner': unicode(owner1.auto_id),
'ownerprofile-0-age': u'55',
}
- formset = FormSet(data, instance=owner)
+ formset = FormSet(data, instance=owner1)
self.assertTrue(formset.is_valid())
saved = formset.save()
self.assertEqual(len(saved), 1)
profile1, = saved
- self.assertEqual(profile1.owner, owner)
+ self.assertEqual(profile1.owner, owner1)
self.assertEqual(profile1.age, 55)
def test_unique_true_enforces_max_num_one(self):
@@ -957,7 +961,8 @@ def test_callable_defaults(self):
result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result)
self.assertEqual(result,
'<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'
- '<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>')
+ '<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>'
+ % person.id)
# test for validation with callable defaults. Validations rely on hidden fields
View
132 tests/regressiontests/admin_views/tests.py
@@ -709,8 +709,8 @@ def testChangeView(self):
self.client.get('/test_admin/admin/logout/')
# Test redirection when using row-level change permissions. Refs #11513.
- RowLevelChangePermissionModel.objects.create(name="odd id")
- RowLevelChangePermissionModel.objects.create(name="even id")
+ RowLevelChangePermissionModel.objects.create(id=1, name="odd id")
+ RowLevelChangePermissionModel.objects.create(id=2, name="even id")
for login_dict in [self.super_login, self.changeuser_login, self.adduser_login, self.deleteuser_login]:
self.client.get('/test_admin/admin/')
self.client.post('/test_admin/admin/', login_dict)
@@ -766,12 +766,13 @@ def testCustomModelAdminTemplates(self):
})
self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/')
self.assertEqual(CustomArticle.objects.all().count(), 1)
+ article_pk = CustomArticle.objects.all()[0].pk
# Test custom delete, change, and object history templates
# Test custom change form template
- request = self.client.get('/test_admin/admin/admin_views/customarticle/1/')
+ request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/' % article_pk)
self.assertTemplateUsed(request, 'custom_admin/change_form.html')
- request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/')
+ request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/delete/' % article_pk)
self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html')
request = self.client.post('/test_admin/admin/admin_views/customarticle/', data={
'index': 0,
@@ -779,7 +780,7 @@ def testCustomModelAdminTemplates(self):
'_selected_action': ['1'],
})
self.assertTemplateUsed(request, 'custom_admin/delete_selected_confirmation.html')
- request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/')
+ request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/history/' % article_pk)
self.assertTemplateUsed(request, 'custom_admin/object_history.html')
self.client.get('/test_admin/admin/logout/')
@@ -1348,27 +1349,27 @@ def test_non_field_errors(self):
''' Ensure that non field errors are displayed for each of the
forms in the changelist's formset. Refs #13126.
'''
- FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai')
- FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india')
- FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza')
+ fd1 = FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai')
+ fd2 = FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india')
+ fd3 = FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza')
data = {
"form-TOTAL_FORMS": "3",
"form-INITIAL_FORMS": "3",
"form-MAX_NUM_FORMS": "0",
- "form-0-id": "1",
+ "form-0-id": str(fd1.id),
"form-0-reference": "123",
"form-0-driver": "bill",
"form-0-restaurant": "thai",
# Same data as above: Forbidden because of unique_together!
- "form-1-id": "2",
+ "form-1-id": str(fd2.id),
"form-1-reference": "456",
"form-1-driver": "bill",
"form-1-restaurant": "thai",
- "form-2-id": "3",
+ "form-2-id": str(fd3.id),
"form-2-reference": "789",
"form-2-driver": "bill",
"form-2-restaurant": "pizza",
@@ -1383,19 +1384,19 @@ def test_non_field_errors(self):
"form-INITIAL_FORMS": "3",
"form-MAX_NUM_FORMS": "0",
- "form-0-id": "1",
+ "form-0-id": str(fd1.id),
"form-0-reference": "123",
"form-0-driver": "bill",
"form-0-restaurant": "thai",
# Same data as above: Forbidden because of unique_together!
- "form-1-id": "2",
+ "form-1-id": str(fd2.id),
"form-1-reference": "456",
"form-1-driver": "bill",
"form-1-restaurant": "thai",
# Same data also.
- "form-2-id": "3",
+ "form-2-id": str(fd3.id),
"form-2-reference": "789",
"form-2-driver": "bill",
"form-2-restaurant": "thai",
@@ -1548,28 +1549,28 @@ def test_pk_hidden_fields(self):
separately (not in the table), and only once.
Refs #12475.
"""
- Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
- Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
+ story1 = Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
+ story2 = Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
response = self.client.get('/test_admin/admin/admin_views/story/')
self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
self.assertContains(response, 'id="id_form-1-id"', 1)
- 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>')
- self.assertContains(response, '<td>1</td>', 1)
- self.assertContains(response, '<td>2</td>', 1)
+ 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))
+ self.assertContains(response, '<td>%d</td>' % story1.id, 1)
+ self.assertContains(response, '<td>%d</td>' % story2.id, 1)
def test_pk_hidden_fields_with_list_display_links(self):
""" Similarly as test_pk_hidden_fields, but when the hidden pk fields are
referenced in list_display_links.
Refs #12475.
"""
- OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
- OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
+ story1 = OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
+ story2 = OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
response = self.client.get('/test_admin/admin/admin_views/otherstory/')
self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
self.assertContains(response, 'id="id_form-1-id"', 1)
- 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>')
- self.assertContains(response, '<th><a href="1/">1</a></th>', 1)
- self.assertContains(response, '<th><a href="2/">2</a></th>', 1)
+ 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))
+ self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1)
+ self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story2.id, story2.id), 1)
class AdminSearchTest(TestCase):
@@ -1643,9 +1644,13 @@ def testInline(self):
self.assertEqual(BarAccount.objects.all()[0].username, bar_user)
self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
+ persona_id = Persona.objects.all()[0].id
+ foo_id = FooAccount.objects.all()[0].id
+ bar_id = BarAccount.objects.all()[0].id
+
# test the edit case
- response = self.client.get('/test_admin/admin/admin_views/persona/1/')
+ response = self.client.get('/test_admin/admin/admin_views/persona/%d/' % persona_id)
names = name_re.findall(response.content)
# make sure we have no duplicate HTML names
self.assertEqual(len(names), len(set(names)))
@@ -1658,18 +1663,18 @@ def testInline(self):
"accounts-MAX_NUM_FORMS": u"0",
"accounts-0-username": "%s-1" % foo_user,
- "accounts-0-account_ptr": "1",
- "accounts-0-persona": "1",
+ "accounts-0-account_ptr": str(foo_id),
+ "accounts-0-persona": str(persona_id),
"accounts-2-TOTAL_FORMS": u"2",
"accounts-2-INITIAL_FORMS": u"1",
"accounts-2-MAX_NUM_FORMS": u"0",
"accounts-2-0-username": "%s-1" % bar_user,
- "accounts-2-0-account_ptr": "2",
- "accounts-2-0-persona": "1",
+ "accounts-2-0-account_ptr": str(bar_id),
+ "accounts-2-0-persona": str(persona_id),
}
- response = self.client.post('/test_admin/admin/admin_views/persona/1/', post_data)
+ response = self.client.post('/test_admin/admin/admin_views/persona/%d/' % persona_id, post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Persona.objects.count(), 1)
self.assertEqual(FooAccount.objects.count(), 1)
@@ -1946,10 +1951,10 @@ def setUp(self):
file1.write('a' * (2 ** 21))
filename = file1.name
file1.close()
- g = Gallery(name="Test Gallery")
- g.save()
- p = Picture(name="Test Picture", image=filename, gallery=g)
- p.save()
+ self.gallery = Gallery(name="Test Gallery")
+ self.gallery.save()
+ self.picture = Picture(name="Test Picture", image=filename, gallery=self.gallery)
+ self.picture.save()
def tearDown(self):
self.client.logout()
@@ -1963,16 +1968,16 @@ def test_inline_file_upload_edit_validation_error_post(self):
"pictures-TOTAL_FORMS": u"2",
"pictures-INITIAL_FORMS": u"1",
"pictures-MAX_NUM_FORMS": u"0",
- "pictures-0-id": u"1",
- "pictures-0-gallery": u"1",
+ "pictures-0-id": unicode(self.picture.id),
+ "pictures-0-gallery": unicode(self.gallery.id),
"pictures-0-name": "Test Picture",
"pictures-0-image": "",
"pictures-1-id": "",
- "pictures-1-gallery": "1",
+ "pictures-1-gallery": str(self.gallery.id),
"pictures-1-name": "Test Picture 2",
"pictures-1-image": "",
}
- response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
+ response = self.client.post('/test_admin/%s/admin_views/gallery/%d/' % (self.urlbit, self.gallery.id), post_data)
self.assertTrue(response._container[0].find("Currently:") > -1)
@@ -2077,29 +2082,31 @@ def test_simple_inline(self):
"A simple model can be saved as inlines"
# First add a new inline
self.post_data['widget_set-0-name'] = "Widget 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Widget.objects.count(), 1)
self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
+ widget_id = Widget.objects.all()[0].id
# Check that the PK link exists on the rendered form
- response = self.client.get('/test_admin/admin/admin_views/collector/1/')
+ response = self.client.get(collector_url)
self.assertContains(response, 'name="widget_set-0-id"')
# Now resave that inline
self.post_data['widget_set-INITIAL_FORMS'] = "1"
- self.post_data['widget_set-0-id'] = "1"
+ self.post_data['widget_set-0-id'] = str(widget_id)
self.post_data['widget_set-0-name'] = "Widget 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Widget.objects.count(), 1)
self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
# Now modify that inline
self.post_data['widget_set-INITIAL_FORMS'] = "1"
- self.post_data['widget_set-0-id'] = "1"
+ self.post_data['widget_set-0-id'] = str(widget_id)
self.post_data['widget_set-0-name'] = "Widget 1 Updated"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Widget.objects.count(), 1)
self.assertEqual(Widget.objects.all()[0].name, "Widget 1 Updated")
@@ -2108,29 +2115,30 @@ def test_explicit_autofield_inline(self):
"A model with an explicit autofield primary key can be saved as inlines. Regression for #8093"
# First add a new inline
self.post_data['grommet_set-0-name'] = "Grommet 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
# Check that the PK link exists on the rendered form
- response = self.client.get('/test_admin/admin/admin_views/collector/1/')
+ response = self.client.get(collector_url)
self.assertContains(response, 'name="grommet_set-0-code"')
# Now resave that inline
self.post_data['grommet_set-INITIAL_FORMS'] = "1"
- self.post_data['grommet_set-0-code'] = "1"
+ self.post_data['grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
self.post_data['grommet_set-0-name'] = "Grommet 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
# Now modify that inline
self.post_data['grommet_set-INITIAL_FORMS'] = "1"
- self.post_data['grommet_set-0-code'] = "1"
+ self.post_data['grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
self.post_data['grommet_set-0-name'] = "Grommet 1 Updated"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated")
@@ -2140,20 +2148,21 @@ def test_char_pk_inline(self):
# First add a new inline
self.post_data['doohickey_set-0-code'] = "DH1"
self.post_data['doohickey_set-0-name'] = "Doohickey 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
# Check that the PK link exists on the rendered form
- response = self.client.get('/test_admin/admin/admin_views/collector/1/')
+ response = self.client.get(collector_url)
self.assertContains(response, 'name="doohickey_set-0-code"')
# Now resave that inline
self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
self.post_data['doohickey_set-0-code'] = "DH1"
self.post_data['doohickey_set-0-name'] = "Doohickey 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
@@ -2162,7 +2171,7 @@ def test_char_pk_inline(self):
self.post_data['doohickey_set-INITIAL_FORMS'] = "1"
self.post_data['doohickey_set-0-code'] = "DH1"
self.post_data['doohickey_set-0-name'] = "Doohickey 1 Updated"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated")
@@ -2203,29 +2212,31 @@ def test_inherited_inline(self):
"An inherited model can be saved as inlines. Regression for #11042"
# First add a new inline
self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ collector_url = '/test_admin/admin/admin_views/collector/%d/' % self.collector.pk
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(FancyDoodad.objects.count(), 1)
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
+ doodad_pk = FancyDoodad.objects.all()[0].pk
# Check that the PK link exists on the rendered form
- response = self.client.get('/test_admin/admin/admin_views/collector/1/')
+ response = self.client.get(collector_url)
self.assertContains(response, 'name="fancydoodad_set-0-doodad_ptr"')
# Now resave that inline
self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1"
- self.post_data['fancydoodad_set-0-doodad_ptr'] = "1"
+ self.post_data['fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(FancyDoodad.objects.count(), 1)
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
# Now modify that inline
self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1"
- self.post_data['fancydoodad_set-0-doodad_ptr'] = "1"
+ self.post_data['fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1 Updated"
- response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
+ response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(FancyDoodad.objects.count(), 1)
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
@@ -2730,4 +2741,3 @@ def test_multiple_years(self):
self.assert_non_localized_year(response, 2000)
self.assert_non_localized_year(response, 2003)
self.assert_non_localized_year(response, 2005)
-
View
6 tests/regressiontests/inline_formsets/tests.py
@@ -59,13 +59,13 @@ def test_change_form_deletion_when_invalid(self):
"""
PoemFormSet = inlineformset_factory(Poet, Poem, can_delete=True)
poet = Poet.objects.create(name='test')
- poet.poem_set.create(name='test poem')
+ poem = poet.poem_set.create(name='test poem')
data = {
'poem_set-TOTAL_FORMS': u'1',
'poem_set-INITIAL_FORMS': u'1',
'poem_set-MAX_NUM_FORMS': u'0',
- 'poem_set-0-id': u'1',
- 'poem_set-0-poem': u'1',
+ 'poem_set-0-id': unicode(poem.id),
+ 'poem_set-0-poem': unicode(poem.id),
'poem_set-0-name': u'x' * 1000,
}
formset = PoemFormSet(data, instance=poet)
Please sign in to comment.
Something went wrong with that request. Please try again.