Skip to content

Instantly share code, notes, and snippets.

@RoelWKramer
Created February 24, 2013 18:00
Show Gist options
  • Save RoelWKramer/5024841 to your computer and use it in GitHub Desktop.
Save RoelWKramer/5024841 to your computer and use it in GitHub Desktop.
admin_views/tests.py -> in class: AdminViewBasicTest
def testAfterAddMessageContainsChangeLink(self):
"""
Tests if the message after saving an object contains link to object.
"""
post_data = {
"name": "Another Section",
# inline data
"article_set-TOTAL_FORMS": "3",
"article_set-INITIAL_FORMS": "0",
"article_set-MAX_NUM_FORMS": "0",
}
response = self.client.post(
'/test_admin/%s/admin_views/section/add/' % self.urlbit,
post_data,
follow=True
)
section = Section.objects.all().latest('id')
section_url = reverse('admin:admin_views_section_change', args=(section.pk,))
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
'<li class="info">The section "<a href="%s">Section object</a>" was added successfully.</li>' % section_url,
html=True
)
def testAfterChangeMessageContainsChangeLink(self):
"""
Tests if the message after saving an object contains link to object.
"""
post_data = {
"name": "Updated Section",
# inline data
"article_set-TOTAL_FORMS": "3",
"article_set-INITIAL_FORMS": "0",
"article_set-MAX_NUM_FORMS": "0",
}
response = self.client.post(
'/test_admin/%s/admin_views/section/1/' % self.urlbit,
post_data,
follow=True
)
section = Section.objects.get(pk=1)
section_url = reverse('admin:admin_views_section_change', args=(section.pk,))
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
'<li class="info">The section "<a href="%s">Section object</a>" was changed successfully.</li>' % section_url,
html=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment