1 | # |
---|
2 | # Test configuration form working |
---|
3 | # |
---|
4 | import re |
---|
5 | from helperNotify import * |
---|
6 | from email.Header import Header |
---|
7 | |
---|
8 | from Products.CMFCore.permissions import ManagePortal, ReplyToItem |
---|
9 | |
---|
10 | from quintagroup.plonecomments.utils import getMsg |
---|
11 | from base import getToolByName, FunctionalTestCase |
---|
12 | from config import * |
---|
13 | |
---|
14 | |
---|
15 | class TestNotification(FunctionalTestCase): |
---|
16 | |
---|
17 | def setApprovePublished(self, swithA=1,swithP=1): |
---|
18 | self.prefs._updateProperty('enable_approve_notification', swithA) |
---|
19 | self.prefs._updateProperty('enable_published_notification', swithP) |
---|
20 | |
---|
21 | def afterSetUp(self): |
---|
22 | self.loginAsPortalOwner() |
---|
23 | |
---|
24 | # VERY IMPORTANT to guarantee product skin's content visibility |
---|
25 | self._refreshSkinData() |
---|
26 | |
---|
27 | '''Preparation for functional testing''' |
---|
28 | self.discussion = getToolByName(self.portal, 'portal_discussion', None) |
---|
29 | # Allow discussion for Document |
---|
30 | portal_types = getToolByName(self.portal, 'portal_types', None) |
---|
31 | doc_fti = portal_types.getTypeInfo('Document') |
---|
32 | doc_fti._updateProperty('allow_discussion', 1) |
---|
33 | |
---|
34 | # Make sure Documents are visible by default |
---|
35 | # XXX only do this for plone 3 |
---|
36 | self.portal.portal_workflow.setChainForPortalTypes(('Document',), 'plone_workflow') |
---|
37 | |
---|
38 | portal_properties = getToolByName(self.portal, 'portal_properties', None) |
---|
39 | self.prefs = portal_properties[PROPERTY_SHEET] |
---|
40 | |
---|
41 | # Add Manager user - 'dm' and add him to Discussion Manager group |
---|
42 | self.portal.portal_membership.addMember('dm', 'secret' , ['Manager'], []) |
---|
43 | portal_groups = getToolByName(self.portal, 'portal_groups') |
---|
44 | dm_group = portal_groups.getGroupById('DiscussionManager') |
---|
45 | dm_group.addMember('dm') |
---|
46 | self.logout() |
---|
47 | self.login('dm') |
---|
48 | # For prepare mail sending - enter an e-mail adress |
---|
49 | self.portal.email_from_address = 'mail@plone.test' |
---|
50 | self.prefs._updateProperty('email_discussion_manager', 'discussion.manager@test.com') |
---|
51 | member = self.portal.portal_membership.getAuthenticatedMember() |
---|
52 | member.setMemberProperties({'email':'creator@test.com'}) |
---|
53 | |
---|
54 | # Add testing document to portal |
---|
55 | my_doc = self.portal.invokeFactory('Document', id='my_doc', title='Doc') |
---|
56 | self.my_doc = self.portal['my_doc'] |
---|
57 | self.my_doc.edit(text_format='plain', text='hello world') |
---|
58 | # Create talkback for document and Prepare REQUEST |
---|
59 | self.discussion.getDiscussionFor(self.my_doc) |
---|
60 | self.request = self.app.REQUEST |
---|
61 | self.request.form['Creator'] = self.portal.portal_membership.getAuthenticatedMember().getUserName() |
---|
62 | self.request.form['subject'] = "Reply 1" |
---|
63 | self.request.form['body_text'] = "text of reply" |
---|
64 | |
---|
65 | prepareMailSendTest() |
---|
66 | |
---|
67 | def test_bug_parent_reply(self): |
---|
68 | setProperties(self.prefs, 'enable_reply_user_notification') |
---|
69 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
70 | parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
71 | parent_reply.discussion_reply('reply', 'text') |
---|
72 | |
---|
73 | def test_bug_mistakable_names(self): |
---|
74 | setProperties(self.prefs, 'enable_reply_user_notification') |
---|
75 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
76 | parent_reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
77 | |
---|
78 | args={'mto': 'user_email@gmail.com', |
---|
79 | 'mfrom': 'admin_email@gmail.com', |
---|
80 | 'obj': parent_reply, |
---|
81 | 'organization_name': 'org_name', |
---|
82 | 'name': parent_reply.getOwnerTuple()[1]} |
---|
83 | |
---|
84 | msg = getMsg(self.portal, 'reply_notify_template', args) |
---|
85 | patt = re.compile('\\n([^,]*?),\\n\\n') |
---|
86 | m = patt.search(msg) |
---|
87 | if m: |
---|
88 | name = m.group(1) |
---|
89 | self.assertEqual(parent_reply.getOwnerTuple()[1], name) |
---|
90 | else: |
---|
91 | raise "No name" |
---|
92 | |
---|
93 | def test_notificafion_disabled(self): |
---|
94 | cleanOutputDir() |
---|
95 | setProperties(self.prefs) |
---|
96 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
97 | self.failIf(testMailExistance(), 'Mail was sended when all notification was disabled.') |
---|
98 | |
---|
99 | def test_published_comment_notification(self): |
---|
100 | cleanOutputDir() |
---|
101 | setProperties(self.prefs, 'enable_published_notification') |
---|
102 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
103 | self.failUnless(testMailExistance(), 'Mail was not sended when enable_published_notification.') |
---|
104 | |
---|
105 | def test_approve_comment_notification(self): |
---|
106 | cleanOutputDir() |
---|
107 | setProperties(self.prefs, 'enable_approve_notification') |
---|
108 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
109 | self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_notification.') |
---|
110 | |
---|
111 | def test_reply_comment_user_notification(self): |
---|
112 | cleanOutputDir() |
---|
113 | setProperties(self.prefs, 'enable_reply_user_notification') |
---|
114 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
115 | self.failIf(testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification.') |
---|
116 | |
---|
117 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
118 | reply.discussion_reply('A Reply for comment' ,'text of reply for comment') |
---|
119 | reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
120 | self.failUnless(testMailExistance(), 'Mail was not sended when enable_reply_user_notification.') |
---|
121 | |
---|
122 | def test_rejected_comment_notification(self): |
---|
123 | cleanOutputDir() |
---|
124 | setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation') |
---|
125 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
126 | self.failIf(testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled.') |
---|
127 | |
---|
128 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
129 | self.portal.REQUEST.set('ids', [reply.getId()]) |
---|
130 | self.portal.prefs_recent_comments_delete() |
---|
131 | self.failUnless(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification.') |
---|
132 | |
---|
133 | def test_approve_comment_user__notification(self): |
---|
134 | cleanOutputDir() |
---|
135 | setProperties(self.prefs, 'enable_approve_user_notification') |
---|
136 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
137 | self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_user_notification.') |
---|
138 | |
---|
139 | def test_bug_notification_on_single_reply_publish(self): |
---|
140 | """ Bug: no notification sent on publishing single comment. |
---|
141 | Must be 3 mails: for replier about replying on his commen; |
---|
142 | for replier about publishig his comment; |
---|
143 | for document creator about adding new comment. |
---|
144 | """ |
---|
145 | properties = ['enable_approve_user_notification', 'enable_reply_user_notification', |
---|
146 | 'enable_published_notification'] |
---|
147 | setProperties(self.prefs, *properties) |
---|
148 | #setProperties(self.prefs, 'enable_published_notification', ) |
---|
149 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
150 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
151 | reply.discussion_reply('A Reply for reply for my_doc' ,'text of reply on reply for my_doc') |
---|
152 | reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0] |
---|
153 | |
---|
154 | cleanOutputDir() |
---|
155 | reply2.discussion_publish_comment() |
---|
156 | mails = getMails() |
---|
157 | self.failUnless([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)], |
---|
158 | 'No notification for reply.' % properties) |
---|
159 | self.failUnless([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)], |
---|
160 | 'No notification for adding comment.' % properties) |
---|
161 | self.failUnless([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)], |
---|
162 | 'No notification for publishing comment.' % properties) |
---|
163 | |
---|
164 | def test_bug_notification_on_single_reply_delete(self): |
---|
165 | """ Bug: no notification sent on deleting single comment. |
---|
166 | Mail about rejecing comment should be sent to comentator. |
---|
167 | """ |
---|
168 | properties = ['enable_rejected_user_notification',] |
---|
169 | setProperties(self.prefs, *properties) |
---|
170 | #setProperties(self.prefs, 'enable_published_notification', ) |
---|
171 | self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc') |
---|
172 | reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
---|
173 | |
---|
174 | cleanOutputDir() |
---|
175 | reply.deleteDiscussion() |
---|
176 | mails = getMails() |
---|
177 | regexp = re.compile("Subject:\s*(.*?)$",re.M) |
---|
178 | subject = str(Header('Your comment on "Doc" was not approved', 'utf-8')) |
---|
179 | self.failUnless([1 for m in mails if regexp.search(m).group(1) == subject], |
---|
180 | 'No notification for rejecting comment.' % properties) |
---|
181 | |
---|
182 | |
---|
183 | def test_suite(): |
---|
184 | from unittest import TestSuite, makeSuite |
---|
185 | suite = TestSuite() |
---|
186 | suite.addTest(makeSuite(TestNotification)) |
---|
187 | return suite |
---|