From 094525326ffc4cbc7aff38239c67f7e739f1dd18 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Fri, 12 Feb 2016 07:55:10 +0100 Subject: [PATCH] Add admin test for publish view --- tests/test_models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index fcce681..ab8977d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -34,6 +34,8 @@ class AdminTest(BaseTest): admin.autodiscover() def test_admin_post_views(self): + self.get_pages() + post_admin = admin.site._registry[Post] request = self.get_page_request('/', self.user, r'/en/blog/', edit=False) @@ -50,6 +52,28 @@ class AdminTest(BaseTest): self.assertContains(response, '') self.assertContains(response, '' % self.app_config_1.pk) + # Test for publish view + post.publish = False + post.save() + response = post_admin.publish_post(request, str(post.pk)) + # Redirects to current post + self.assertEqual(response.status_code, 302) + self.assertEqual(response['Location'], post.get_absolute_url()) + post = self.reload_model(post) + # post is publshed + self.assertTrue(post.publish) + + # Non-existing post is redirected to posts list + response = post_admin.publish_post(request, str('1000000')) + self.assertEqual(response.status_code, 302) + self.assertEqual(response['Location'], reverse('djangocms_blog:posts-latest')) + + # unless a referer is set + request.META['HTTP_REFERER'] = '/' + response = post_admin.publish_post(request, str('1000000')) + self.assertEqual(response.status_code, 302) + self.assertEqual(response['Location'], '/') + def test_admin_blogconfig_views(self): post_admin = admin.site._registry[BlogConfig] request = self.get_page_request('/', self.user, r'/en/blog/', edit=False)