diff --git a/tests/regressiontests/generic_views/edit.py b/tests/regressiontests/generic_views/edit.py
index 0f1eb3c..19ea598 100644
a
|
b
|
class ModelFormMixinTests(TestCase):
|
34 | 34 | form_class = views.AuthorGetQuerySetFormView().get_form_class() |
35 | 35 | self.assertEqual(form_class._meta.model, Author) |
36 | 36 | |
| 37 | |
| 38 | class SuccessMessageMixinTest(TestCase): |
| 39 | def test_nonSmessage(self): |
| 40 | self.assertRaise(ImproperlyConfigured, |
| 41 | views.NonMessageSuccessMessageMixin().create_success_message, |
| 42 | verbase_name='NonMessage' |
| 43 | ) |
| 44 | def test_invalid_message(self): |
| 45 | self.assertRaise(TypeError, |
| 46 | views.InvalidMessageSuccessMessageMixin().create_success_message, |
| 47 | verbase_name='NonMessage' |
| 48 | ) |
| 49 | |
| 50 | |
37 | 51 | class CreateViewTests(TestCase): |
38 | 52 | urls = 'regressiontests.generic_views.urls' |
39 | 53 | |
… |
… |
class CreateViewTests(TestCase):
|
51 | 65 | self.assertEqual(res.status_code, 302) |
52 | 66 | self.assertRedirects(res, 'http://testserver/list/authors/') |
53 | 67 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) |
| 68 | self.assertTrue('The author was created successfully.' in res.cookies['messages'].value) |
54 | 69 | |
55 | 70 | def test_create_invalid(self): |
56 | 71 | res = self.client.post('/edit/authors/create/', |
… |
… |
class CreateViewTests(TestCase):
|
59 | 74 | self.assertTemplateUsed(res, 'generic_views/author_form.html') |
60 | 75 | self.assertEqual(len(res.context['form'].errors), 1) |
61 | 76 | self.assertEqual(Author.objects.count(), 0) |
| 77 | self.assertFalse(res.cookies.get('messages', False)) |
62 | 78 | |
63 | 79 | def test_create_with_object_url(self): |
64 | 80 | res = self.client.post('/edit/artists/create/', |
… |
… |
class CreateViewTests(TestCase):
|
67 | 83 | artist = Artist.objects.get(name='Rene Magritte') |
68 | 84 | self.assertRedirects(res, 'http://testserver/detail/artist/%d/' % artist.pk) |
69 | 85 | self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>']) |
| 86 | self.assertTrue('The professional artist was created successfully.' in res.cookies['messages'].value) |
70 | 87 | |
71 | 88 | def test_create_with_redirect(self): |
72 | 89 | res = self.client.post('/edit/authors/create/redirect/', |
… |
… |
class CreateViewTests(TestCase):
|
74 | 91 | self.assertEqual(res.status_code, 302) |
75 | 92 | self.assertRedirects(res, 'http://testserver/edit/authors/create/') |
76 | 93 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) |
| 94 | self.assertTrue('The author was created successfully.' in res.cookies['messages'].value) |
77 | 95 | |
78 | 96 | def test_create_with_interpolated_redirect(self): |
79 | 97 | res = self.client.post('/edit/authors/create/interpolate_redirect/', |
… |
… |
class CreateViewTests(TestCase):
|
82 | 100 | self.assertEqual(res.status_code, 302) |
83 | 101 | pk = Author.objects.all()[0].pk |
84 | 102 | self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % pk) |
| 103 | self.assertTrue('The author was created successfully.' in res.cookies['messages'].value) |
85 | 104 | |
86 | 105 | def test_create_with_special_properties(self): |
87 | 106 | res = self.client.get('/edit/authors/create/special/') |
… |
… |
class CreateViewTests(TestCase):
|
97 | 116 | obj = Author.objects.get(slug='randall-munroe') |
98 | 117 | self.assertRedirects(res, reverse('author_detail', kwargs={'pk': obj.pk})) |
99 | 118 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) |
| 119 | self.assertTrue('The author was created successfully.' in res.cookies['messages'].value) |
100 | 120 | |
101 | 121 | def test_create_without_redirect(self): |
102 | 122 | try: |
… |
… |
class CreateViewTests(TestCase):
|
111 | 131 | {'name': 'Randall Munroe', 'slug': 'randall-munroe'}) |
112 | 132 | self.assertEqual(res.status_code, 302) |
113 | 133 | self.assertRedirects(res, 'http://testserver/accounts/login/?next=/edit/authors/create/restricted/') |
| 134 | self.assertFalse(res.cookies.get('messages', False)) |
114 | 135 | |
115 | 136 | |
116 | 137 | class UpdateViewTests(TestCase): |
… |
… |
class UpdateViewTests(TestCase):
|
134 | 155 | self.assertEqual(res.status_code, 302) |
135 | 156 | self.assertRedirects(res, 'http://testserver/list/authors/') |
136 | 157 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>']) |
| 158 | self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value) |
137 | 159 | |
138 | 160 | @expectedFailure |
139 | 161 | def test_update_put(self): |
… |
… |
class UpdateViewTests(TestCase):
|
154 | 176 | self.assertEqual(res.status_code, 302) |
155 | 177 | self.assertRedirects(res, 'http://testserver/list/authors/') |
156 | 178 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) |
| 179 | self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value) |
157 | 180 | |
158 | 181 | def test_update_invalid(self): |
159 | 182 | a = Author.objects.create( |
… |
… |
class UpdateViewTests(TestCase):
|
166 | 189 | self.assertTemplateUsed(res, 'generic_views/author_form.html') |
167 | 190 | self.assertEqual(len(res.context['form'].errors), 1) |
168 | 191 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) |
| 192 | self.assertFalse(res.cookies.get('messages', False)) |
169 | 193 | |
170 | 194 | def test_update_with_object_url(self): |
171 | 195 | a = Artist.objects.create(name='Rene Magritte') |
… |
… |
class UpdateViewTests(TestCase):
|
174 | 198 | self.assertEqual(res.status_code, 302) |
175 | 199 | self.assertRedirects(res, 'http://testserver/detail/artist/%d/' % a.pk) |
176 | 200 | self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>']) |
| 201 | self.assertTrue('The professional artist was updated successfully.' in res.cookies['messages'].value) |
177 | 202 | |
178 | 203 | def test_update_with_redirect(self): |
179 | 204 | a = Author.objects.create( |
… |
… |
class UpdateViewTests(TestCase):
|
197 | 222 | self.assertEqual(res.status_code, 302) |
198 | 223 | pk = Author.objects.all()[0].pk |
199 | 224 | self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % pk) |
| 225 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) |
200 | 226 | |
201 | 227 | def test_update_with_special_properties(self): |
202 | 228 | a = Author.objects.create( |
… |
… |
class UpdateViewTests(TestCase):
|
216 | 242 | self.assertEqual(res.status_code, 302) |
217 | 243 | self.assertRedirects(res, 'http://testserver/detail/author/%d/' % a.pk) |
218 | 244 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) |
| 245 | self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value) |
219 | 246 | |
220 | 247 | def test_update_without_redirect(self): |
221 | 248 | try: |
… |
… |
class UpdateViewTests(TestCase):
|
226 | 253 | res = self.client.post('/edit/author/%d/update/naive/' % a.pk, |
227 | 254 | {'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'}) |
228 | 255 | self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided') |
| 256 | self.assertFalse(res.cookies.get('messages', False)) |
229 | 257 | except ImproperlyConfigured: |
230 | 258 | pass |
231 | 259 | |
… |
… |
class UpdateViewTests(TestCase):
|
249 | 277 | self.assertEqual(res.status_code, 302) |
250 | 278 | self.assertRedirects(res, 'http://testserver/list/authors/') |
251 | 279 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>']) |
| 280 | self.assertTrue('The author was updated successfully.' in res.cookies['messages'].value) |
252 | 281 | |
253 | 282 | |
254 | 283 | class DeleteViewTests(TestCase): |
… |
… |
class DeleteViewTests(TestCase):
|
267 | 296 | self.assertEqual(res.status_code, 302) |
268 | 297 | self.assertRedirects(res, 'http://testserver/list/authors/') |
269 | 298 | self.assertQuerysetEqual(Author.objects.all(), []) |
| 299 | self.assertTrue('The author was deleted.' in res.cookies['messages'].value) |
270 | 300 | |
271 | 301 | def test_delete_by_delete(self): |
272 | 302 | # Deletion with browser compatible DELETE method |
… |
… |
class DeleteViewTests(TestCase):
|
275 | 305 | self.assertEqual(res.status_code, 302) |
276 | 306 | self.assertRedirects(res, 'http://testserver/list/authors/') |
277 | 307 | self.assertQuerysetEqual(Author.objects.all(), []) |
| 308 | self.assertTrue('The author was deleted.' in res.cookies['messages'].value) |
278 | 309 | |
279 | 310 | def test_delete_with_redirect(self): |
280 | 311 | a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) |
… |
… |
class DeleteViewTests(TestCase):
|
282 | 313 | self.assertEqual(res.status_code, 302) |
283 | 314 | self.assertRedirects(res, 'http://testserver/edit/authors/create/') |
284 | 315 | self.assertQuerysetEqual(Author.objects.all(), []) |
| 316 | self.assertTrue('The author was deleted.' in res.cookies['messages'].value) |
285 | 317 | |
286 | 318 | def test_delete_with_special_properties(self): |
287 | 319 | a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) |
… |
… |
class DeleteViewTests(TestCase):
|
296 | 328 | self.assertEqual(res.status_code, 302) |
297 | 329 | self.assertRedirects(res, 'http://testserver/list/authors/') |
298 | 330 | self.assertQuerysetEqual(Author.objects.all(), []) |
| 331 | self.assertTrue('The author was deleted.' in res.cookies['messages'].value) |
299 | 332 | |
300 | 333 | def test_delete_without_redirect(self): |
301 | 334 | try: |
… |
… |
class DeleteViewTests(TestCase):
|
305 | 338 | ) |
306 | 339 | res = self.client.post('/edit/author/%d/delete/naive/' % a.pk) |
307 | 340 | self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided') |
| 341 | self.assertFalse(res.cookies.get('messages'), False) |
308 | 342 | except ImproperlyConfigured: |
309 | 343 | pass |
310 | 344 | |
diff --git a/tests/regressiontests/generic_views/views.py b/tests/regressiontests/generic_views/views.py
index 71e78e8..96e2cdd 100644
a
|
b
|
class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
|
186 | 186 | def get_queryset(self): |
187 | 187 | return Author.objects.all() |
188 | 188 | |
| 189 | |
| 190 | class NonMessageSuccessMessageView(generic.edit.SuccessMessageMixin): |
| 191 | pass |
| 192 | |
| 193 | |
| 194 | class InvalidMessageSuccessMessageView(generic.edit.SuccessMessageMixin): |
| 195 | success_message = 0 |
| 196 | |
| 197 | |
189 | 198 | class BookDetailGetObjectCustomQueryset(BookDetail): |
190 | 199 | def get_object(self, queryset=None): |
191 | 200 | return super(BookDetailGetObjectCustomQueryset,self).get_object( |