Skip to content

Commit

Permalink
Merge pull request #469 from praekelt/feature/issue-469-TUNE-309-fix-…
Browse files Browse the repository at this point in the history
…submit-for-moderation-bugs

TUNE-309-fix-submit-for-moderation-bugs
  • Loading branch information
Saeed Marzban authored Oct 23, 2017
2 parents 6f84d27 + 6cf521b commit 1465d54
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 1 deletion.
3 changes: 2 additions & 1 deletion molo/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def process_response(self, request, response):
class MultiSiteRedirectToHomepage(object):

def process_request(self, request):
if request.path.startswith('/admin/pages/'):
if request.path.startswith('/admin/pages/') and \
not request.path.startswith('/admin/pages/moderation/'):
current_site = Site.find_for_request(request)
func, args, kwargs = resolve(request.path)
if args:
Expand Down
137 changes: 137 additions & 0 deletions molo/core/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from os import environ
import re
import json
Expand Down Expand Up @@ -1873,3 +1874,139 @@ def test_wagtail_login_only_user_cannot_see_explorer(self):
self.assertEquals(response.status_code, 200)
soup = BeautifulSoup(response.content, 'html.parser')
self.assertFalse(soup.find('a', string='Explorer'))


class TestModerationActions(TestCase, MoloTestCaseMixin):

def setUp(self):
self.client = Client()
self.mk_main()
self.main = Main.objects.all().first()
self.english = SiteLanguageRelation.objects.create(
language_setting=Languages.for_site(self.main.get_site()),
locale='en',
is_active=True)
# Creates a section under the index page
self.english_section = self.mk_section(
self.section_index, title='English section')
self.yourmind = self.mk_section(
self.section_index, title='Your mind')

self.mk_main2()
self.main2 = Main.objects.all().last()
self.language_setting2 = Languages.objects.create(
site_id=self.main2.get_site().pk)
self.english2 = SiteLanguageRelation.objects.create(
language_setting=self.language_setting2,
locale='en',
is_active=True)
self.yourmind2 = self.mk_section(
self.section_index2, title='Your mind')

superuser = User.objects.create_superuser(
username='testuser', password='password', email='test@email.com')

self.article_site1 = ArticlePage(
title="Article 1 in site 1",
slug="article-1-in-site-1",
live=False,
)
self.yourmind.add_child(instance=self.article_site1)
self.article_site1.save_revision(
user=superuser, submitted_for_moderation=True)

self.article_site2 = ArticlePage(
title="Article 1 in site 2",
slug="article-1-in-site-2",
live=False,
)
self.yourmind2.add_child(instance=self.article_site2)
self.article_site2.save_revision(
user=superuser, submitted_for_moderation=True)

self.article2_site1 = ArticlePage(
title="Article 2 in site 1",
slug="article-2-in-site-1",
live=False,
)
self.yourmind.add_child(instance=self.article2_site1)
self.article2_site1.save_revision(
user=superuser, submitted_for_moderation=True)

self.article2_site2 = ArticlePage(
title="Article 2 in site 2",
slug="article-2-in-site-2",
live=False,
)
self.yourmind2.add_child(instance=self.article2_site2)
self.article2_site2.save_revision(
user=superuser, submitted_for_moderation=True)

def test_approve_moderation(self):
self.client.login(username='testuser', password='password')

self.assertFalse(self.article_site1.live)
self.assertTrue(
self.article_site1.revisions.first().submitted_for_moderation)
revision = self.article_site1.get_latest_revision()

response = self.client.post(reverse(
'wagtailadmin_pages:approve_moderation',
args=(revision.id,)))

self.assertRedirects(response, reverse('wagtailadmin_home'))
self.article_site1.refresh_from_db()
self.assertTrue(self.article_site1.live)
self.assertTrue(ArticlePage.objects.descendant_of(self.main).get(
slug=self.article_site1.slug))

self.assertFalse(self.article_site2.live)
self.assertTrue(
self.article_site2.revisions.first().submitted_for_moderation)
revision = self.article_site2.get_latest_revision()

response = self.client.post(reverse(
'wagtailadmin_pages:approve_moderation',
args=(revision.id,)))

self.assertRedirects(response, reverse('wagtailadmin_home'))
self.article_site2.refresh_from_db()
self.assertTrue(self.article_site2.live)
self.assertTrue(ArticlePage.objects.descendant_of(self.main2).get(
slug=self.article_site2.slug))

def test_reject_moderation(self):
self.client.login(username='testuser', password='password')
self.assertFalse(self.article2_site1.live)
self.assertTrue(
self.article2_site1.revisions.first().submitted_for_moderation)
revision = self.article2_site1.get_latest_revision()

response = self.client.post(reverse(
'wagtailadmin_pages:reject_moderation',
args=(revision.id, )))

self.assertRedirects(response, reverse('wagtailadmin_home'))
self.article2_site1.refresh_from_db()
self.assertFalse(self.article2_site1.live)
self.assertFalse(
self.article2_site1.revisions.first().submitted_for_moderation)
self.assertTrue(ArticlePage.objects.descendant_of(self.main).get(
slug=self.article2_site1.slug))

self.assertFalse(self.article2_site2.live)
self.assertTrue(
self.article2_site2.revisions.first().submitted_for_moderation)
revision = self.article2_site2.get_latest_revision()

response = self.client.post(reverse(
'wagtailadmin_pages:reject_moderation',
args=(revision.id, )))

self.assertRedirects(response, reverse('wagtailadmin_home'))
self.article2_site2.refresh_from_db()
self.assertFalse(self.article2_site2.live)
self.assertFalse(
self.article2_site2.revisions.first().submitted_for_moderation)
self.assertTrue(ArticlePage.objects.descendant_of(self.main2).get(
slug=self.article2_site2.slug))

0 comments on commit 1465d54

Please sign in to comment.