diff options
| author | Brian Rosner <brosner@gmail.com> | 2008-08-09 20:52:40 +0000 |
|---|---|---|
| committer | Brian Rosner <brosner@gmail.com> | 2008-08-09 20:52:40 +0000 |
| commit | 65be56816fc173f823566728ab78b72d061bb466 (patch) | |
| tree | be3f07253971dfb13db3eb037041aa8246ece2fb /tests | |
| parent | 50e6928c5bcf03b7f18f26d3d9af50295a7bc46f (diff) | |
Fixed #5780 -- Adjusted the ModelAdmin API to allow the created/updated objects
to be passed to the formsets prior to validation.
This is a backward incompatible change for anyone overridding save_add or
save_change. They have been removed in favor of more granular methods
introduced in [8266] and the new response_add and response_change nethods.
save_model has been renamed to save_form due to its slightly changed behavior.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8273 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/admin_views/models.py | 5 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 95 |
2 files changed, 85 insertions, 15 deletions
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index a8fc9467ba..98f99a6d00 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -20,6 +20,9 @@ class Article(models.Model): def __unicode__(self): return self.title +class ArticleInline(admin.TabularInline): + model = Article + class ArticleAdmin(admin.ModelAdmin): list_display = ('content', 'date') list_filter = ('date',) @@ -61,5 +64,5 @@ class ModelWithStringPrimaryKey(models.Model): admin.site.register(Article, ArticleAdmin) admin.site.register(CustomArticle, CustomArticleAdmin) -admin.site.register(Section) +admin.site.register(Section, inlines=[ArticleInline]) admin.site.register(ModelWithStringPrimaryKey) diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index cc91494bba..2bdce7c07d 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -11,10 +11,90 @@ from django.utils.html import escape # local test models from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey +class AdminViewBasicTest(TestCase): + fixtures = ['admin-views-users.xml'] + + def setUp(self): + self.client.login(username='super', password='secret') + + def tearDown(self): + self.client.logout() + + def testTrailingSlashRequired(self): + """ + If you leave off the trailing slash, app should redirect and add it. + """ + request = self.client.get('/test_admin/admin/admin_views/article/add') + self.assertRedirects(request, + '/test_admin/admin/admin_views/article/add/' + ) + + def testBasicAddGet(self): + """ + A smoke test to ensure GET on the add_view works. + """ + response = self.client.get('/test_admin/admin/admin_views/section/add/') + self.failUnlessEqual(response.status_code, 200) + + def testBasicEditGet(self): + """ + A smoke test to ensureGET on the change_view works. + """ + response = self.client.get('/test_admin/admin/admin_views/section/1/') + self.failUnlessEqual(response.status_code, 200) + + def testBasicAddPost(self): + """ + A smoke test to ensure POST on add_view works. + """ + post_data = { + "name": u"Another Section", + # inline data + "article_set-TOTAL_FORMS": u"3", + "article_set-INITIAL_FORMS": u"0", + } + response = self.client.post('/test_admin/admin/admin_views/section/add/', post_data) + self.failUnlessEqual(response.status_code, 302) # redirect somewhere + + def testBasicEditPost(self): + """ + A smoke test to ensure POST on edit_view works. + """ + post_data = { + "name": u"Test section", + # inline data + "article_set-TOTAL_FORMS": u"4", + "article_set-INITIAL_FORMS": u"1", + "article_set-0-id": u"1", + # there is no title in database, give one here or formset + # will fail. + "article_set-0-title": u"Need a title.", + "article_set-0-content": u"<p>test content</p>", + "article_set-0-date_0": u"2008-03-18", + "article_set-0-date_1": u"11:54:58", + "article_set-1-id": u"", + "article_set-1-title": u"", + "article_set-1-content": u"", + "article_set-1-date_0": u"", + "article_set-1-date_1": u"", + "article_set-2-id": u"", + "article_set-2-title": u"", + "article_set-2-content": u"", + "article_set-2-date_0": u"", + "article_set-2-date_1": u"", + "article_set-3-id": u"", + "article_set-3-title": u"", + "article_set-3-content": u"", + "article_set-3-date_0": u"", + "article_set-3-date_1": u"", + } + response = self.client.post('/test_admin/admin/admin_views/section/1/', post_data) + self.failUnlessEqual(response.status_code, 302) # redirect somewhere + def get_perm(Model, perm): """Return the permission object, for the Model""" ct = ContentType.objects.get_for_model(Model) - return Permission.objects.get(content_type=ct,codename=perm) + return Permission.objects.get(content_type=ct, codename=perm) class AdminViewPermissionsTest(TestCase): """Tests for Admin Views Permissions.""" @@ -77,19 +157,6 @@ class AdminViewPermissionsTest(TestCase): 'username': 'joepublic', 'password': 'secret'} - def testTrailingSlashRequired(self): - """ - If you leave off the trailing slash, app should redirect and add it. - """ - self.client.post('/test_admin/admin/', self.super_login) - - request = self.client.get( - '/test_admin/admin/admin_views/article/add' - ) - self.assertRedirects(request, - '/test_admin/admin/admin_views/article/add/' - ) - def testLogin(self): """ Make sure only staff members can log in. |
