summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_views/tests.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-05-13 18:41:39 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-05-13 18:41:39 +0000
commit11d08bca2bf99de7e7aefec7986a206ea5039724 (patch)
tree1671a1525a3a105e5287f84bd19f5d13c3ec7195 /tests/regressiontests/admin_views/tests.py
parent68033811eecd1f1b06b39d0a335042e1ff9036a6 (diff)
[1.0.X] Fixed #10448: correcting errors on "save as new" now correctly create a new object instead of modifying the old one. Thanks, bastih. Backport of [10713] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10764 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/admin_views/tests.py')
-rw-r--r--tests/regressiontests/admin_views/tests.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 70ae64c290..5e9cc7a1d6 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -14,7 +14,7 @@ from django.utils.html import escape
# local test models
from models import (Article, BarAccount, CustomArticle, EmptyModel,
FooAccount, Gallery, ModelWithStringPrimaryKey,
- Persona, Picture, Section,
+ Person, Persona, Picture, Section,
Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit)
try:
@@ -229,6 +229,34 @@ class AdminViewBasicTest(TestCase):
"Changelist filter isn't showing options contained inside a model field 'choices' option named group."
)
+class SaveAsTests(TestCase):
+ fixtures = ['admin-views-users.xml','admin-views-person.xml']
+
+ def setUp(self):
+ self.client.login(username='super', password='secret')
+
+ def tearDown(self):
+ self.client.logout()
+
+ def test_save_as_duplication(self):
+ """Ensure save as actually creates a new person"""
+ post_data = {'_saveasnew':'', 'name':'John M', 'gender':1}
+ response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
+ self.assertEqual(len(Person.objects.filter(name='John M')), 1)
+ self.assertEqual(len(Person.objects.filter(id=1)), 1)
+
+ def test_save_as_display(self):
+ """
+ Ensure that 'save as' is displayed when activated and after submitting
+ invalid data aside save_as_new will not show us a form to overwrite the
+ initial model.
+ """
+ response = self.client.get('/test_admin/admin/admin_views/person/1/')
+ self.assert_(response.context[-1]['save_as'])
+ post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'}
+ response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
+ self.assertEqual(response.context[-1]['form_url'], '../add/')
+
def get_perm(Model, perm):
"""Return the permission object, for the Model"""
ct = ContentType.objects.get_for_model(Model)