1 | # |
---|
2 | # Test configuration form working |
---|
3 | # |
---|
4 | |
---|
5 | import os, sys, string |
---|
6 | |
---|
7 | if __name__ == '__main__': |
---|
8 | execfile(os.path.join(sys.path[0], 'framework.py')) |
---|
9 | |
---|
10 | from Products.PloneTestCase import PloneTestCase |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | try: |
---|
13 | from Products.CMFCore.permissions import ManagePortal, ReplyToItem |
---|
14 | except ImportError: |
---|
15 | from Products.CMFCore.CMFCorePermissions import ManagePortal,ReplyToItem |
---|
16 | from Products.MailHost.MailHost import MailBase |
---|
17 | |
---|
18 | import re |
---|
19 | |
---|
20 | from Products.qPloneComments.utils import getMsg |
---|
21 | from testQPloneCommentsModeration import USERS, COMMON_USERS_IDS, DM_USERS_IDS |
---|
22 | from helperNotify import * |
---|
23 | from common import * |
---|
24 | |
---|
25 | PRODUCT = 'qPloneComments' |
---|
26 | PROPERTY_SHEET = "qPloneComments" |
---|
27 | |
---|
28 | PloneTestCase.installProduct(PRODUCT) |
---|
29 | PloneTestCase.setupPloneSite() |
---|
30 | |
---|
31 | USERS = {# Common Members |
---|
32 | 'admin':{'passw': 'secret_admin', 'roles': ['Manager']}, |
---|
33 | 'owner':{'passw': 'secret_creator', 'roles': ['Member']}, |
---|
34 | 'replier1':{'passw': 'secret_member', 'roles': ['Member']}, |
---|
35 | 'replier2':{'passw': 'secret_member', 'roles': ['Member']}, |
---|
36 | # Members for discussion manager group |
---|
37 | 'dm_admin':{'passw': 'secret_dm_admin', 'roles': ['Manager']}, |
---|
38 | } |
---|
39 | DM_USERS_IDS = [u for u in USERS.keys() if u.startswith('dm_')] |
---|
40 | |
---|
41 | REXP_TO = re.compile("To:\s*(.*?)$",re.M) |
---|
42 | REXP_SUBJ = re.compile("Subject:\s*(.*?)$",re.M) |
---|
43 | |
---|
44 | class TestNotificationRecipients(PloneTestCase.FunctionalTestCase): |
---|
45 | """ Test is notifications sends to right recipients. """ |
---|
46 | |
---|
47 | def prepareRequest4Reply(self, member_id): |
---|
48 | self.login(member_id) |
---|
49 | self.request = self.app.REQUEST |
---|
50 | self.request.form['Creator'] = self.membership.getAuthenticatedMember().getUserName() |
---|
51 | self.request.form['subject'] = "Reply of '%s'" % self.request.form['Creator'] |
---|
52 | self.request.form['body_text'] = "text of reply" |
---|
53 | |
---|
54 | |
---|
55 | def afterSetUp(self): |
---|
56 | self.loginAsPortalOwner() |
---|
57 | |
---|
58 | self.qi = self.portal.portal_quickinstaller |
---|
59 | self.qi.installProduct(PRODUCT) |
---|
60 | # VERY IMPORTANT to guarantee product skin's content visibility |
---|
61 | self._refreshSkinData() |
---|
62 | |
---|
63 | '''Preparation for functional testing''' |
---|
64 | self.membership = getToolByName(self.portal, 'portal_membership', None) |
---|
65 | self.discussion = getToolByName(self.portal, 'portal_discussion', None) |
---|
66 | # Allow discussion for Document |
---|
67 | portal_types = getToolByName(self.portal, 'portal_types', None) |
---|
68 | doc_fti = portal_types.getTypeInfo('Document') |
---|
69 | doc_fti._updateProperty('allow_discussion', 1) |
---|
70 | |
---|
71 | # Make sure Documents are visible by default |
---|
72 | # XXX only do this for plone 3 |
---|
73 | self.portal.portal_workflow.setChainForPortalTypes(('Document',), 'plone_workflow') |
---|
74 | |
---|
75 | portal_properties = getToolByName(self.portal, 'portal_properties', None) |
---|
76 | self.prefs = portal_properties[PROPERTY_SHEET] |
---|
77 | |
---|
78 | # Add users and add members to DiscussionManager group |
---|
79 | addMembers(self.portal, USERS) |
---|
80 | add2Group(self.portal, 'DiscussionManager', DM_USERS_IDS) |
---|
81 | self.createMemberarea('owner') |
---|
82 | |
---|
83 | ## Prepare mail sending - enter an e-mail adress, and allow all possible notifications |
---|
84 | setProperties(self.prefs, 'enable_moderation', 'enable_approve_notification', |
---|
85 | 'enable_approve_user_notification','enable_reply_user_notification', |
---|
86 | 'enable_published_notification', 'enable_rejected_user_notification') |
---|
87 | self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com') |
---|
88 | |
---|
89 | ## Add testing document to portal |
---|
90 | self.login('owner') |
---|
91 | self.portal.Members['owner'].invokeFactory('Document', id='my_doc', title="Test document") |
---|
92 | self.my_doc = self.portal.Members['owner']['my_doc'] |
---|
93 | self.my_doc.edit(text_format='plain', text='hello world') |
---|
94 | |
---|
95 | ## Create talkback for document and Prepare REQUEST |
---|
96 | self.discussion.getDiscussionFor(self.my_doc) |
---|
97 | |
---|
98 | prepareMailSendTest() |
---|
99 | |
---|
100 | def checkToANDSubj(self, mails, to, subj): |
---|
101 | messages = [m for m in mails if REXP_TO.search(m) and REXP_TO.search(m).group(1)==to] |
---|
102 | self.assert_(len(messages) > 0, "No message sent to '%s' recipient" % to) |
---|
103 | self.assert_([1 for m in messages if REXP_SUBJ.search(m) and REXP_SUBJ.search(m).group(1)==subj],\ |
---|
104 | "There is no message for '%s' recipient with '%s' subject" % (to,subj)) |
---|
105 | |
---|
106 | def test_Reply(self): |
---|
107 | cleanOutputDir() |
---|
108 | self.prepareRequest4Reply('replier1') |
---|
109 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
110 | |
---|
111 | mails = getMails() |
---|
112 | self.assertEqual(len(mails), 1) |
---|
113 | self.checkToANDSubj(mails, to="discussion.manager@test.com", subj="New comment awaits moderation") |
---|
114 | |
---|
115 | |
---|
116 | def test_PublishReply(self): |
---|
117 | self.prepareRequest4Reply('replier1') |
---|
118 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
119 | self.login('dm_admin') |
---|
120 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
121 | cleanOutputDir() |
---|
122 | |
---|
123 | reply.discussion_publish_comment() |
---|
124 | mails = getMails() |
---|
125 | self.assertEqual(len(mails), 2) |
---|
126 | self.checkToANDSubj(mails, to="owner@test.com", subj="New comment added") |
---|
127 | self.checkToANDSubj(mails, to="replier1@test.com", subj="Your comment on 'Test document' is now published") |
---|
128 | |
---|
129 | def test_Publish2ndReply(self): |
---|
130 | self.prepareRequest4Reply('replier1') |
---|
131 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
132 | self.login('dm_admin') |
---|
133 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
134 | reply.discussion_publish_comment() |
---|
135 | self.prepareRequest4Reply('replier2') |
---|
136 | reply.discussion_reply('A Reply for reply for my_doc' ,'text of reply on reply for my_doc') |
---|
137 | self.login('dm_admin') |
---|
138 | reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] |
---|
139 | cleanOutputDir() |
---|
140 | |
---|
141 | reply2.discussion_publish_comment() |
---|
142 | mails = getMails() |
---|
143 | self.assertEqual(len(mails), 3) |
---|
144 | self.checkToANDSubj(mails, to="owner@test.com", subj="New comment added") |
---|
145 | self.checkToANDSubj(mails, to="replier1@test.com", subj="Someone replied to your comment on 'Test document'") |
---|
146 | self.checkToANDSubj(mails, to="replier2@test.com", subj="Your comment on 'Test document' is now published") |
---|
147 | |
---|
148 | def test_DeleteReply(self): |
---|
149 | self.prepareRequest4Reply('replier1') |
---|
150 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
151 | self.login('dm_admin') |
---|
152 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
153 | cleanOutputDir() |
---|
154 | |
---|
155 | reply.deleteDiscussion() |
---|
156 | mails = getMails() |
---|
157 | self.assertEqual(len(mails), 1) |
---|
158 | self.checkToANDSubj(mails, to="replier1@test.com", subj="Your comment on 'Test document' was not approved.") |
---|
159 | |
---|
160 | |
---|
161 | TESTS = [TestNotificationRecipients] |
---|
162 | |
---|
163 | def test_suite(): |
---|
164 | from unittest import TestSuite, makeSuite |
---|
165 | suite = TestSuite() |
---|
166 | for t in TESTS: |
---|
167 | suite.addTest(makeSuite(t)) |
---|
168 | return suite |
---|
169 | |
---|
170 | if __name__ == '__main__': |
---|
171 | framework() |
---|
172 | |
---|