Corrected some Postgres test failures introduced by r14254.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14256 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b514957850
commit
2a9551a415
|
@ -1,4 +1,5 @@
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils.unittest import expectedFailure
|
from django.utils.unittest import expectedFailure
|
||||||
|
@ -57,7 +58,8 @@ class CreateViewTests(TestCase):
|
||||||
res = self.client.post('/edit/authors/create/special/',
|
res = self.client.post('/edit/authors/create/special/',
|
||||||
{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
||||||
self.assertEqual(res.status_code, 302)
|
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>'])
|
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
|
||||||
|
|
||||||
def test_create_without_redirect(self):
|
def test_create_without_redirect(self):
|
||||||
|
@ -82,15 +84,15 @@ class UpdateViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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.assertEqual(res.status_code, 200)
|
||||||
self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
|
self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
|
||||||
self.assertEqual(res.context['object'], 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=1))
|
self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
|
||||||
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
||||||
|
|
||||||
# Modification with both POST and PUT (browser compatible)
|
# 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'})
|
{'name': 'Randall Munroe (xkcd)', 'slug': 'randall-munroe'})
|
||||||
self.assertEqual(res.status_code, 302)
|
self.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/list/authors/')
|
self.assertRedirects(res, 'http://testserver/list/authors/')
|
||||||
|
@ -102,11 +104,11 @@ class UpdateViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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.assertEqual(res.status_code, 200)
|
||||||
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
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'})
|
{'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
|
||||||
self.assertEqual(res.status_code, 302)
|
self.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/list/authors/')
|
self.assertRedirects(res, 'http://testserver/list/authors/')
|
||||||
|
@ -117,7 +119,7 @@ class UpdateViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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'})
|
{'name': 'A' * 101, 'slug': 'randall-munroe'})
|
||||||
self.assertEqual(res.status_code, 200)
|
self.assertEqual(res.status_code, 200)
|
||||||
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
||||||
|
@ -126,10 +128,10 @@ class UpdateViewTests(TestCase):
|
||||||
|
|
||||||
def test_update_with_object_url(self):
|
def test_update_with_object_url(self):
|
||||||
a = Artist.objects.create(name='Rene Magritte')
|
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'})
|
{'name': 'Rene Magritte'})
|
||||||
self.assertEqual(res.status_code, 302)
|
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>'])
|
self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>'])
|
||||||
|
|
||||||
def test_update_with_redirect(self):
|
def test_update_with_redirect(self):
|
||||||
|
@ -137,7 +139,7 @@ class UpdateViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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'})
|
{'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
|
||||||
self.assertEqual(res.status_code, 302)
|
self.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/edit/authors/create/')
|
self.assertRedirects(res, 'http://testserver/edit/authors/create/')
|
||||||
|
@ -148,18 +150,18 @@ class UpdateViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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.assertEqual(res.status_code, 200)
|
||||||
self.assertTrue(isinstance(res.context['form'], views.AuthorForm))
|
self.assertTrue(isinstance(res.context['form'], views.AuthorForm))
|
||||||
self.assertEqual(res.context['object'], 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=1))
|
self.assertEqual(res.context['thingy'], Author.objects.get(pk=a.pk))
|
||||||
self.assertFalse('author' in res.context)
|
self.assertFalse('author' in res.context)
|
||||||
self.assertTemplateUsed(res, 'generic_views/form.html')
|
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'})
|
{'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
|
||||||
self.assertEqual(res.status_code, 302)
|
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)>'])
|
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
|
||||||
|
|
||||||
def test_update_without_redirect(self):
|
def test_update_without_redirect(self):
|
||||||
|
@ -168,7 +170,7 @@ class UpdateViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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'})
|
{'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
|
||||||
self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided')
|
self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided')
|
||||||
except ImproperlyConfigured:
|
except ImproperlyConfigured:
|
||||||
|
@ -178,44 +180,44 @@ class DeleteViewTests(TestCase):
|
||||||
urls = 'regressiontests.generic_views.urls'
|
urls = 'regressiontests.generic_views.urls'
|
||||||
|
|
||||||
def test_delete_by_post(self):
|
def test_delete_by_post(self):
|
||||||
Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
||||||
res = self.client.get('/edit/author/1/delete/')
|
res = self.client.get('/edit/author/%d/delete/' % a.pk)
|
||||||
self.assertEqual(res.status_code, 200)
|
self.assertEqual(res.status_code, 200)
|
||||||
self.assertEqual(res.context['object'], 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=1))
|
self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
|
||||||
self.assertTemplateUsed(res, 'generic_views/author_confirm_delete.html')
|
self.assertTemplateUsed(res, 'generic_views/author_confirm_delete.html')
|
||||||
|
|
||||||
# Deletion with POST
|
# 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.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/list/authors/')
|
self.assertRedirects(res, 'http://testserver/list/authors/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), [])
|
self.assertQuerysetEqual(Author.objects.all(), [])
|
||||||
|
|
||||||
def test_delete_by_delete(self):
|
def test_delete_by_delete(self):
|
||||||
# Deletion with browser compatible DELETE method
|
# Deletion with browser compatible DELETE method
|
||||||
Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
||||||
res = self.client.delete('/edit/author/1/delete/')
|
res = self.client.delete('/edit/author/%d/delete/' % a.pk)
|
||||||
self.assertEqual(res.status_code, 302)
|
self.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/list/authors/')
|
self.assertRedirects(res, 'http://testserver/list/authors/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), [])
|
self.assertQuerysetEqual(Author.objects.all(), [])
|
||||||
|
|
||||||
def test_delete_with_redirect(self):
|
def test_delete_with_redirect(self):
|
||||||
Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
||||||
res = self.client.post('/edit/author/1/delete/redirect/')
|
res = self.client.post('/edit/author/%d/delete/redirect/' % a.pk)
|
||||||
self.assertEqual(res.status_code, 302)
|
self.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/edit/authors/create/')
|
self.assertRedirects(res, 'http://testserver/edit/authors/create/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), [])
|
self.assertQuerysetEqual(Author.objects.all(), [])
|
||||||
|
|
||||||
def test_delete_with_special_properties(self):
|
def test_delete_with_special_properties(self):
|
||||||
Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
||||||
res = self.client.get('/edit/author/1/delete/special/')
|
res = self.client.get('/edit/author/%d/delete/special/' % a.pk)
|
||||||
self.assertEqual(res.status_code, 200)
|
self.assertEqual(res.status_code, 200)
|
||||||
self.assertEqual(res.context['object'], 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=1))
|
self.assertEqual(res.context['thingy'], Author.objects.get(pk=a.pk))
|
||||||
self.assertFalse('author' in res.context)
|
self.assertFalse('author' in res.context)
|
||||||
self.assertTemplateUsed(res, 'generic_views/confirm_delete.html')
|
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.assertEqual(res.status_code, 302)
|
||||||
self.assertRedirects(res, 'http://testserver/list/authors/')
|
self.assertRedirects(res, 'http://testserver/list/authors/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), [])
|
self.assertQuerysetEqual(Author.objects.all(), [])
|
||||||
|
@ -226,7 +228,7 @@ class DeleteViewTests(TestCase):
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
slug='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')
|
self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided')
|
||||||
except ImproperlyConfigured:
|
except ImproperlyConfigured:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue