diff options
| author | Markus Amalthea Magnuson <markus.magnuson@gmail.com> | 2016-04-03 16:50:01 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-20 11:31:44 -0400 |
| commit | 08cd6a0e56bac04e322388e7059072ad98db303c (patch) | |
| tree | 615d175fcf55f2d1ebe02a5895aacb1104b7ec03 /tests/admin_views | |
| parent | cb65e62c84dd8f6b412151e81cf665975143d397 (diff) | |
Fixed #16327 -- Redirected "Save as new" to change view instead of the changelist.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/admin.py | 1 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 25 |
2 files changed, 25 insertions, 1 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index f4dfb91bef..31f41515bb 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -1013,6 +1013,7 @@ site2.register( list_editable=['parent'], raw_id_fields=['parent'], ) +site2.register(Person, save_as_continue=False) site7 = admin.AdminSite(name="admin7") site7.register(Article, ArticleAdmin2) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 48ce1770fb..5c0d5ed51c 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1119,9 +1119,23 @@ class SaveAsTests(TestCase): def test_save_as_duplication(self): """Ensure save as actually creates a new person""" post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 1, 'age': 42} - self.client.post(reverse('admin:admin_views_person_change', args=(self.per1.pk,)), post_data) + response = self.client.post(reverse('admin:admin_views_person_change', args=(self.per1.pk,)), post_data) self.assertEqual(len(Person.objects.filter(name='John M')), 1) self.assertEqual(len(Person.objects.filter(id=self.per1.pk)), 1) + new_person = Person.objects.latest('id') + self.assertRedirects(response, reverse('admin:admin_views_person_change', args=(new_person.pk,))) + + def test_save_as_continue_false(self): + """ + Saving a new object using "Save as new" redirects to the changelist + instead of the change view when ModelAdmin.save_as_continue=False. + """ + post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 1, 'age': 42} + url = reverse('admin:admin_views_person_change', args=(self.per1.pk,), current_app=site2.name) + response = self.client.post(url, post_data) + self.assertEqual(len(Person.objects.filter(name='John M')), 1) + self.assertEqual(len(Person.objects.filter(id=self.per1.pk)), 1) + self.assertRedirects(response, reverse('admin:admin_views_person_changelist', current_app=site2.name)) def test_save_as_new_with_validation_errors(self): """ @@ -1689,6 +1703,15 @@ class AdminViewPermissionsTest(TestCase): self.assertEqual(post.status_code, 403) self.assertEqual(Article.objects.count(), article_count) + # User with both add and change permissions should be redirected to the + # change page for the newly created object. + article_count = Article.objects.count() + self.client.force_login(self.superuser) + post = self.client.post(article_change_url, change_dict_save_as_new) + self.assertEqual(Article.objects.count(), article_count + 1) + new_article = Article.objects.latest('id') + self.assertRedirects(post, reverse('admin:admin_views_article_change', args=(new_article.pk,))) + def test_delete_view(self): """Delete view should restrict access and actually delete items.""" delete_dict = {'post': 'yes'} |
