Author: russellm
Date: 2010-10-18 10:53:08 -0500 (Mon, 18 Oct 2010)
New Revision: 14256

Modified:
   django/trunk/tests/regressiontests/generic_views/edit.py
Log:
Corrected some Postgres test failures introduced by r14254.

Modified: django/trunk/tests/regressiontests/generic_views/edit.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/edit.py    2010-10-18 
15:51:18 UTC (rev 14255)
+++ django/trunk/tests/regressiontests/generic_views/edit.py    2010-10-18 
15:53:08 UTC (rev 14256)
@@ -1,4 +1,5 @@
 from django.core.exceptions import ImproperlyConfigured
+from django.core.urlresolvers import reverse
 from django import forms
 from django.test import TestCase
 from django.utils.unittest import expectedFailure
@@ -57,7 +58,8 @@
         res = self.client.post('/edit/authors/create/special/',
                             {'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
         self.assertEqual(res.status_code, 302)
-        self.assertRedirects(res, 'http://testserver/detail/author/1/')
+        obj = Author.objects.get(slug='randall-munroe')
+        self.assertRedirects(res, reverse('author_detail', kwargs={'pk': 
obj.pk}))
         self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall 
Munroe>'])
 
     def test_create_without_redirect(self):
@@ -82,15 +84,15 @@
             name='Randall Munroe',
             slug='randall-munroe',
         )
-        res = self.client.get('/edit/author/1/update/')
+        res = self.client.get('/edit/author/%d/update/' % a.pk)
         self.assertEqual(res.status_code, 200)
         self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
-        self.assertEqual(res.context['object'], Author.objects.get(pk=1))
-        self.assertEqual(res.context['author'], Author.objects.get(pk=1))
+        self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
+        self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
         self.assertTemplateUsed(res, 'generic_views/author_form.html')
 
         # Modification with both POST and PUT (browser compatible)
-        res = self.client.post('/edit/author/1/update/',
+        res = self.client.post('/edit/author/%d/update/' % a.pk,
                         {'name': 'Randall Munroe (xkcd)', 'slug': 
'randall-munroe'})
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/list/authors/')
@@ -102,11 +104,11 @@
             name='Randall Munroe',
             slug='randall-munroe',
         )
-        res = self.client.get('/edit/author/1/update/')
+        res = self.client.get('/edit/author/%d/update/' % a.pk)
         self.assertEqual(res.status_code, 200)
         self.assertTemplateUsed(res, 'generic_views/author_form.html')
 
-        res = self.client.put('/edit/author/1/update/',
+        res = self.client.put('/edit/author/%d/update/' % a.pk,
                         {'name': 'Randall Munroe (author of xkcd)', 'slug': 
'randall-munroe'})
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/list/authors/')
@@ -117,7 +119,7 @@
             name='Randall Munroe',
             slug='randall-munroe',
         )
-        res = self.client.post('/edit/author/1/update/',
+        res = self.client.post('/edit/author/%d/update/' % a.pk,
                         {'name': 'A' * 101, 'slug': 'randall-munroe'})
         self.assertEqual(res.status_code, 200)
         self.assertTemplateUsed(res, 'generic_views/author_form.html')
@@ -126,10 +128,10 @@
 
     def test_update_with_object_url(self):
         a = Artist.objects.create(name='Rene Magritte')
-        res = self.client.post('/edit/artists/1/update/',
+        res = self.client.post('/edit/artists/%d/update/' % a.pk,
                         {'name': 'Rene Magritte'})
         self.assertEqual(res.status_code, 302)
-        self.assertRedirects(res, 'http://testserver/detail/artist/1/')
+        self.assertRedirects(res, 'http://testserver/detail/artist/%d/' % a.pk)
         self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene 
Magritte>'])
 
     def test_update_with_redirect(self):
@@ -137,7 +139,7 @@
             name='Randall Munroe',
             slug='randall-munroe',
         )
-        res = self.client.post('/edit/author/1/update/redirect/',
+        res = self.client.post('/edit/author/%d/update/redirect/' % a.pk,
                         {'name': 'Randall Munroe (author of xkcd)', 'slug': 
'randall-munroe'})
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/edit/authors/create/')
@@ -148,18 +150,18 @@
             name='Randall Munroe',
             slug='randall-munroe',
         )
-        res = self.client.get('/edit/author/1/update/special/')
+        res = self.client.get('/edit/author/%d/update/special/' % a.pk)
         self.assertEqual(res.status_code, 200)
         self.assertTrue(isinstance(res.context['form'], views.AuthorForm))
-        self.assertEqual(res.context['object'], Author.objects.get(pk=1))
-        self.assertEqual(res.context['thingy'], Author.objects.get(pk=1))
+        self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
+        self.assertEqual(res.context['thingy'], Author.objects.get(pk=a.pk))
         self.assertFalse('author' in res.context)
         self.assertTemplateUsed(res, 'generic_views/form.html')
 
-        res = self.client.post('/edit/author/1/update/special/',
+        res = self.client.post('/edit/author/%d/update/special/' % a.pk,
                         {'name': 'Randall Munroe (author of xkcd)', 'slug': 
'randall-munroe'})
         self.assertEqual(res.status_code, 302)
-        self.assertRedirects(res, 'http://testserver/detail/author/1/')
+        self.assertRedirects(res, 'http://testserver/detail/author/%d/' % a.pk)
         self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall 
Munroe (author of xkcd)>'])
 
     def test_update_without_redirect(self):
@@ -168,7 +170,7 @@
                 name='Randall Munroe',
                 slug='randall-munroe',
             )
-            res = self.client.post('/edit/author/1/update/naive/',
+            res = self.client.post('/edit/author/%d/update/naive/' % a.pk,
                             {'name': 'Randall Munroe (author of xkcd)', 
'slug': 'randall-munroe'})
             self.fail('Should raise exception -- No redirect URL provided, and 
no get_absolute_url provided')
         except ImproperlyConfigured:
@@ -178,44 +180,44 @@
     urls = 'regressiontests.generic_views.urls'
 
     def test_delete_by_post(self):
-        Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
-        res = self.client.get('/edit/author/1/delete/')
+        a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
+        res = self.client.get('/edit/author/%d/delete/' % a.pk)
         self.assertEqual(res.status_code, 200)
-        self.assertEqual(res.context['object'], Author.objects.get(pk=1))
-        self.assertEqual(res.context['author'], Author.objects.get(pk=1))
+        self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
+        self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
         self.assertTemplateUsed(res, 
'generic_views/author_confirm_delete.html')
 
         # Deletion with POST
-        res = self.client.post('/edit/author/1/delete/')
+        res = self.client.post('/edit/author/%d/delete/' % a.pk)
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/list/authors/')
         self.assertQuerysetEqual(Author.objects.all(), [])
 
     def test_delete_by_delete(self):
         # Deletion with browser compatible DELETE method
-        Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
-        res = self.client.delete('/edit/author/1/delete/')
+        a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
+        res = self.client.delete('/edit/author/%d/delete/' % a.pk)
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/list/authors/')
         self.assertQuerysetEqual(Author.objects.all(), [])
 
     def test_delete_with_redirect(self):
-        Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
-        res = self.client.post('/edit/author/1/delete/redirect/')
+        a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
+        res = self.client.post('/edit/author/%d/delete/redirect/' % a.pk)
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/edit/authors/create/')
         self.assertQuerysetEqual(Author.objects.all(), [])
 
     def test_delete_with_special_properties(self):
-        Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
-        res = self.client.get('/edit/author/1/delete/special/')
+        a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
+        res = self.client.get('/edit/author/%d/delete/special/' % a.pk)
         self.assertEqual(res.status_code, 200)
-        self.assertEqual(res.context['object'], Author.objects.get(pk=1))
-        self.assertEqual(res.context['thingy'], Author.objects.get(pk=1))
+        self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
+        self.assertEqual(res.context['thingy'], Author.objects.get(pk=a.pk))
         self.assertFalse('author' in res.context)
         self.assertTemplateUsed(res, 'generic_views/confirm_delete.html')
 
-        res = self.client.post('/edit/author/1/delete/special/')
+        res = self.client.post('/edit/author/%d/delete/special/' % a.pk)
         self.assertEqual(res.status_code, 302)
         self.assertRedirects(res, 'http://testserver/list/authors/')
         self.assertQuerysetEqual(Author.objects.all(), [])
@@ -226,7 +228,7 @@
                 name='Randall Munroe',
                 slug='randall-munroe',
             )
-            res = self.client.post('/edit/author/1/delete/naive/')
+            res = self.client.post('/edit/author/%d/delete/naive/' % a.pk)
             self.fail('Should raise exception -- No redirect URL provided, and 
no get_absolute_url provided')
         except ImproperlyConfigured:
             pass

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to