Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #17818 -- Added tests for messaging of edit generic views.

  • Loading branch information...
commit bf5a51a95dbfcbc5ff7f96e1f1b12050b461c830 1 parent 6eefb72
@hirokiky authored
View
34 tests/regressiontests/generic_views/edit.py
@@ -34,6 +34,20 @@ def test_get_form(self):
form_class = views.AuthorGetQuerySetFormView().get_form_class()
self.assertEqual(form_class._meta.model, Author)
+
+class SuccessMessageMixinTest(TestCase):
+ def test_nonSmessage(self):
+ self.assertRaise(ImproperlyConfigured,
+ views.NonMessageSuccessMessageMixin().create_success_message,
+ verbase_name='NonMessage'
+ )
+ def test_invalid_message(self):
+ self.assertRaise(TypeError,
+ views.InvalidMessageSuccessMessageMixin().create_success_message,
+ verbase_name='NonMessage'
+ )
+
+
class CreateViewTests(TestCase):
urls = 'regressiontests.generic_views.urls'
@@ -51,6 +65,7 @@ def test_create(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertTrue('The author was created successfully.' in res.cookies['messages'].value)
def test_create_invalid(self):
res = self.client.post('/edit/authors/create/',
@@ -59,6 +74,7 @@ def test_create_invalid(self):
self.assertTemplateUsed(res, 'generic_views/author_form.html')
self.assertEqual(len(res.context['form'].errors), 1)
self.assertEqual(Author.objects.count(), 0)
+ self.assertFalse(res.cookies.get('messages', False))
def test_create_with_object_url(self):
res = self.client.post('/edit/artists/create/',
@@ -67,6 +83,7 @@ def test_create_with_object_url(self):
artist = Artist.objects.get(name='Rene Magritte')
self.assertRedirects(res, 'http://testserver/detail/artist/%d/' % artist.pk)
self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>'])
+ self.assertTrue('The professional artist was created successfully.' in res.cookies['messages'].value)
def test_create_with_redirect(self):
res = self.client.post('/edit/authors/create/redirect/',
@@ -74,6 +91,7 @@ def test_create_with_redirect(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/edit/authors/create/')
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertTrue('The author was created successfully.' in res.cookies['messages'].value)
def test_create_with_interpolated_redirect(self):
res = self.client.post('/edit/authors/create/interpolate_redirect/',
@@ -82,6 +100,7 @@ def test_create_with_interpolated_redirect(self):
self.assertEqual(res.status_code, 302)
pk = Author.objects.all()[0].pk
self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % pk)
+ self.assertTrue('The author was created successfully.' in res.cookies['messages'].value)
def test_create_with_special_properties(self):
res = self.client.get('/edit/authors/create/special/')
@@ -97,6 +116,7 @@ def test_create_with_special_properties(self):
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.assertTrue('The author was created successfully.' in res.cookies['messages'].value)
def test_create_without_redirect(self):
try:
@@ -111,6 +131,7 @@ def test_create_restricted(self):
{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/accounts/login/?next=/edit/authors/create/restricted/')
+ self.assertFalse(res.cookies.get('messages', False))
class UpdateViewTests(TestCase):
@@ -134,6 +155,7 @@ def test_update_post(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>'])
+ self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value)
@expectedFailure
def test_update_put(self):
@@ -154,6 +176,7 @@ def test_update_put(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
+ self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value)
def test_update_invalid(self):
a = Author.objects.create(
@@ -166,6 +189,7 @@ def test_update_invalid(self):
self.assertTemplateUsed(res, 'generic_views/author_form.html')
self.assertEqual(len(res.context['form'].errors), 1)
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertFalse(res.cookies.get('messages', False))
def test_update_with_object_url(self):
a = Artist.objects.create(name='Rene Magritte')
@@ -174,6 +198,7 @@ def test_update_with_object_url(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/detail/artist/%d/' % a.pk)
self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>'])
+ self.assertTrue('The professional artist was updated successfully.' in res.cookies['messages'].value)
def test_update_with_redirect(self):
a = Author.objects.create(
@@ -197,6 +222,7 @@ def test_update_with_interpolated_redirect(self):
self.assertEqual(res.status_code, 302)
pk = Author.objects.all()[0].pk
self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % pk)
+ self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
def test_update_with_special_properties(self):
a = Author.objects.create(
@@ -216,6 +242,7 @@ def test_update_with_special_properties(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/detail/author/%d/' % a.pk)
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
+ self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value)
def test_update_without_redirect(self):
try:
@@ -226,6 +253,7 @@ def test_update_without_redirect(self):
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')
+ self.assertFalse(res.cookies.get('messages', False))
except ImproperlyConfigured:
pass
@@ -249,6 +277,7 @@ def test_update_get_object(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>'])
+ self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value)
class DeleteViewTests(TestCase):
@@ -267,6 +296,7 @@ def test_delete_by_post(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), [])
+ self.assertTrue('The author was deleted.' in res.cookies['messages'].value)
def test_delete_by_delete(self):
# Deletion with browser compatible DELETE method
@@ -275,6 +305,7 @@ def test_delete_by_delete(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), [])
+ self.assertTrue('The author was deleted.' in res.cookies['messages'].value)
def test_delete_with_redirect(self):
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
@@ -282,6 +313,7 @@ def test_delete_with_redirect(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/edit/authors/create/')
self.assertQuerysetEqual(Author.objects.all(), [])
+ self.assertTrue('The author was deleted.' in res.cookies['messages'].value)
def test_delete_with_special_properties(self):
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
@@ -296,6 +328,7 @@ def test_delete_with_special_properties(self):
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/list/authors/')
self.assertQuerysetEqual(Author.objects.all(), [])
+ self.assertTrue('The author was deleted.' in res.cookies['messages'].value)
def test_delete_without_redirect(self):
try:
@@ -305,6 +338,7 @@ def test_delete_without_redirect(self):
)
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.assertFalse(res.cookies.get('messages'), False)
except ImproperlyConfigured:
pass
View
9 tests/regressiontests/generic_views/views.py
@@ -186,6 +186,15 @@ class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
def get_queryset(self):
return Author.objects.all()
+
+class NonMessageSuccessMessageView(generic.edit.SuccessMessageMixin):
+ pass
+
+
+class InvalidMessageSuccessMessageView(generic.edit.SuccessMessageMixin):
+ success_message = 0
+
+
class BookDetailGetObjectCustomQueryset(BookDetail):
def get_object(self, queryset=None):
return super(BookDetailGetObjectCustomQueryset,self).get_object(
Please sign in to comment.
Something went wrong with that request. Please try again.