1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #16744 -- Class based view should have the view object in the context

Updated the most recent patch from @claudep to apply again and updated
the documentation location.
This commit is contained in:
Marc Tamlyn
2012-08-18 14:46:17 +01:00
committed by Andrew Godwin
parent 547b181046
commit 58683e9c82
8 changed files with 35 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse
from django import forms
from django.test import TestCase
from django.utils.unittest import expectedFailure
from django.views.generic.base import View
from django.views.generic.edit import FormMixin
from . import views
@@ -31,6 +32,7 @@ class CreateViewTests(TestCase):
res = self.client.get('/edit/authors/create/')
self.assertEqual(res.status_code, 200)
self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
self.assertTrue(isinstance(res.context['view'], View))
self.assertFalse('object' in res.context)
self.assertFalse('author' in res.context)
self.assertTemplateUsed(res, 'generic_views/author_form.html')
@@ -101,6 +103,7 @@ class CreateViewTests(TestCase):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/accounts/login/?next=/edit/authors/create/restricted/')
class UpdateViewTests(TestCase):
urls = 'regressiontests.generic_views.urls'
@@ -226,6 +229,7 @@ class UpdateViewTests(TestCase):
res = self.client.get('/edit/author/update/')
self.assertEqual(res.status_code, 200)
self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
self.assertTrue(isinstance(res.context['view'], View))
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')
@@ -237,6 +241,7 @@ class UpdateViewTests(TestCase):
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>'])
class DeleteViewTests(TestCase):
urls = 'regressiontests.generic_views.urls'