| 1 | from Products.PloneTestCase import PloneTestCase |
|---|
| 2 | from Products.CMFCore.utils import getToolByName |
|---|
| 3 | from Products.qPloneComments.tests.testQPloneCommentsCommenting import TestCommBase |
|---|
| 4 | from zExceptions import Unauthorized |
|---|
| 5 | |
|---|
| 6 | PRODUCT = 'qPloneComments' |
|---|
| 7 | USERS = {# Common Members |
|---|
| 8 | 'admin':{'passw': 'secret_admin', 'roles': ['Manager']}, |
|---|
| 9 | 'owner':{'passw': 'secret_owner', 'roles': ['Owner']}, |
|---|
| 10 | 'member':{'passw': 'secret_member', 'roles': ['Member']}, |
|---|
| 11 | 'reviewer':{'passw': 'secret_reviewer', 'roles': ['Reviewer']}, |
|---|
| 12 | # Members for discussion manager group |
|---|
| 13 | 'dm_admin':{'passw': 'secret_dm_admin', 'roles': ['Manager']}, |
|---|
| 14 | 'dm_owner':{'passw': 'secret_dm_owner', 'roles': ['Owner']}, |
|---|
| 15 | 'dm_member':{'passw': 'secret_dm_member', 'roles': ['Member']}, |
|---|
| 16 | 'dm_reviewer':{'passw': 'secret_dm_reviewer', 'roles': ['Reviewer']}, |
|---|
| 17 | } |
|---|
| 18 | COMMON_USERS_IDS = [u for u in USERS.keys() if not u.startswith('dm_')] |
|---|
| 19 | COMMON_USERS_IDS.append('anonym') |
|---|
| 20 | DM_USERS_IDS = [u for u in USERS.keys() if u.startswith('dm_')] |
|---|
| 21 | |
|---|
| 22 | PloneTestCase.installProduct(PRODUCT) |
|---|
| 23 | PloneTestCase.setupPloneSite() |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | class TestReportAbuse(TestCommBase): |
|---|
| 27 | |
|---|
| 28 | def afterSetUp(self): |
|---|
| 29 | TestCommBase.afterSetUp(self) |
|---|
| 30 | self.testAnonymousReportAbuse() |
|---|
| 31 | self.testAuthenticatedReportAbuse() |
|---|
| 32 | |
|---|
| 33 | def testAnonymousReportAbuse(self): |
|---|
| 34 | self.login('dm_admin') |
|---|
| 35 | doc_obj = getattr(self.portal, "doc_anonym") |
|---|
| 36 | discussion = self.discussion.getDiscussionFor(doc_obj) |
|---|
| 37 | comment = discussion._container.values()[0] |
|---|
| 38 | self.logout() |
|---|
| 39 | # Add abuse report on document. |
|---|
| 40 | doc_obj.REQUEST.set('comment_id', comment.id) |
|---|
| 41 | try: |
|---|
| 42 | doc_obj.report_abuse("Anonymous Report Abuse") |
|---|
| 43 | except: |
|---|
| 44 | raise "Anonymous user CAN'T report abuse in turned ON *Anonymous report abuse mode*." |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | def testAuthenticatedReportAbuse(self): |
|---|
| 48 | not_anonym_users = [u for u in self.all_users_id if not u=='anonym'] |
|---|
| 49 | failed_users = [] |
|---|
| 50 | for u in not_anonym_users: |
|---|
| 51 | self.login('dm_admin') |
|---|
| 52 | doc_id = "doc_%s" % u |
|---|
| 53 | doc_obj = getattr(self.portal, doc_id) |
|---|
| 54 | discussion = self.discussion.getDiscussionFor(doc_obj) |
|---|
| 55 | comment = discussion._container.values()[0] |
|---|
| 56 | doc_obj.REQUEST.set('comment_id', comment.id) |
|---|
| 57 | self.login(u) |
|---|
| 58 | try: |
|---|
| 59 | doc_obj.report_abuse("Anonymous Report Abuse") |
|---|
| 60 | except: |
|---|
| 61 | failed_users.append(u) |
|---|
| 62 | |
|---|
| 63 | self.assert_(not failed_users, "%s - user(s) can not report abuse" % failed_users) |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | def test_suite(): |
|---|
| 67 | from unittest import TestSuite, makeSuite |
|---|
| 68 | suite = TestSuite() |
|---|
| 69 | suite.addTest(makeSuite(TestReportAbuse)) |
|---|
| 70 | return suite |
|---|
| 71 | |
|---|