| 259 | | TESTS = [TestInstallation, TestConfiglet] |
|---|
| | 255 | class TestModeration(PloneTestCase.FunctionalTestCase): |
|---|
| | 256 | def afterSetUp(self): |
|---|
| | 257 | self.qi = self.portal.portal_quickinstaller |
|---|
| | 258 | self.qi.installProduct(PRODUCT) |
|---|
| | 259 | # VERY IMPORTANT to guarantee product skin's content visibility |
|---|
| | 260 | self._refreshSkinData() |
|---|
| | 261 | |
|---|
| | 262 | #self.portal.changeSkin('Plone Default') |
|---|
| | 263 | |
|---|
| | 264 | self.loginAsPortalOwner() |
|---|
| | 265 | |
|---|
| | 266 | '''Preparation for functional testing''' |
|---|
| | 267 | # add members |
|---|
| | 268 | self.membership = self.portal.portal_membership |
|---|
| | 269 | self.membership.addMember('admin', 'secret_admin', ['Manager'], []) |
|---|
| | 270 | self.membership.addMember('owner', 'secret_owner', ['Owner'], []) |
|---|
| | 271 | self.membership.addMember('member', 'secret_member', ['Member'], []) |
|---|
| | 272 | self.membership.addMember('reviewer', 'secret_reviewer', ['Reviewer'], []) |
|---|
| | 273 | # add members for discussion manager group |
|---|
| | 274 | self.membership.addMember('dm_admin', 'secret_dm_admin', ['Manager'], []) |
|---|
| | 275 | self.membership.addMember('dm_owner', 'secret_dm_owner', ['Owner'], []) |
|---|
| | 276 | self.membership.addMember('dm_member', 'secret_dm_member', ['Member'], []) |
|---|
| | 277 | self.membership.addMember('dm_reviewer', 'secret_dm_reviewer', ['Reviewer'], []) |
|---|
| | 278 | |
|---|
| | 279 | # add Discussion Manager group |
|---|
| | 280 | portal_groups = self.portal.portal_groups |
|---|
| | 281 | portal_groups.addGroup('DiscussionManagers', roles=['DiscussionManager']) |
|---|
| | 282 | dm_group = portal_groups.getGroupById(id='DiscussionManagers') |
|---|
| | 283 | dm_group.addMember('dm_admin') |
|---|
| | 284 | dm_group.addMember('dm_owner') |
|---|
| | 285 | dm_group.addMember('dm_member') |
|---|
| | 286 | dm_group.addMember('dm_reviewer') |
|---|
| | 287 | |
|---|
| | 288 | # Allow discussion for Document |
|---|
| | 289 | portal_types = getToolByName(self.portal, 'portal_types', None) |
|---|
| | 290 | doc_fti = portal_types.getTypeInfo('Document') |
|---|
| | 291 | doc_fti._updateProperty('allow_discussion', 1) |
|---|
| | 292 | |
|---|
| | 293 | # Enable Anonymous commenting and Moderation |
|---|
| | 294 | #self.request = self.app.REQUEST |
|---|
| | 295 | |
|---|
| | 296 | #self.request.form['Enable_Anonymous_Commenting'] = 'True' |
|---|
| | 297 | #self.request.form['Enable_Moderation'] = 'True' |
|---|
| | 298 | #self.portal.prefs_comments_setup() |
|---|
| | 299 | |
|---|
| | 300 | # Add testing document to portal |
|---|
| | 301 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
|---|
| | 302 | self.my_doc = self.portal['my_doc'] |
|---|
| | 303 | self.my_doc.edit(text_format='plain', text='hello world') |
|---|
| | 304 | # Create talkback for document and Add comment to my_doc |
|---|
| | 305 | self.discussion = self.portal.portal_discussion |
|---|
| | 306 | self.discussion.getDiscussionFor(self.my_doc) |
|---|
| | 307 | self.my_doc.discussion_reply('Reply 1','text of reply') |
|---|
| | 308 | |
|---|
| | 309 | |
|---|
| | 310 | def testView(self): |
|---|
| | 311 | #### NOT Published #### |
|---|
| | 312 | # Check moderating discussion |
|---|
| | 313 | # for: members of 'DiscussionMnagers' group MUST ALLOW viewing |
|---|
| | 314 | # for: NOT members of 'DiscussionMnagers' group MUST REFUSE viewing |
|---|
| | 315 | for u in ['dm_admin', 'dm_reviewer','dm_owner','dm_member']: |
|---|
| | 316 | self.logout() |
|---|
| | 317 | self.login(u) |
|---|
| | 318 | replies = self.discussion.getDiscussionFor(self.my_doc).getReplies() |
|---|
| | 319 | self.assert_(replies, "Viewing of NOT published discussion item forbiden for %s user with DiscussionManager role" % u) |
|---|
| | 320 | for u in ['admin','reviewer','owner','member','anonym']: |
|---|
| | 321 | self.logout() |
|---|
| | 322 | if not u=='anonym': |
|---|
| | 323 | self.login(u) |
|---|
| | 324 | replies = self.discussion.getDiscussionFor(self.my_doc).getReplies() |
|---|
| | 325 | self.assert_(not replies, "Viewing of NOT published discussion item allow for %s user without DiscussionManager role" % u) |
|---|
| | 326 | |
|---|
| | 327 | #### Published #### |
|---|
| | 328 | # for all members and anonymous MUST ALLOW viewing |
|---|
| | 329 | self.login('dm_admin') |
|---|
| | 330 | di = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0] |
|---|
| | 331 | di.discussion_publish_comment() |
|---|
| | 332 | for u in ['dm_admin', 'dm_reviewer','dm_owner','dm_member',\ |
|---|
| | 333 | 'admin', 'reviewer','owner','member','anonym']: |
|---|
| | 334 | self.logout() |
|---|
| | 335 | if not u=='anonym': |
|---|
| | 336 | self.login(u) |
|---|
| | 337 | replies = self.discussion.getDiscussionFor(self.my_doc).getReplies() |
|---|
| | 338 | self.assert_(replies, "Viewing of PUBLISHED discussion item forbiden for %s user" % u) |
|---|
| | 339 | |
|---|
| | 340 | |
|---|
| | 341 | def testPublishing(self): |
|---|
| | 342 | # Add testing documents and reply for it to portal |
|---|
| | 343 | doc_ids = ['doc_dm_admin','doc_dm_reviewer','doc_dm_owner','doc_dm_member',\ |
|---|
| | 344 | 'doc_admin', 'doc_reviewer','doc_owner','doc_member','doc_anonym'] |
|---|
| | 345 | for doc in doc_ids: |
|---|
| | 346 | my_doc = self.portal.invokeFactory('Document', id=doc) |
|---|
| | 347 | doc_obj = getattr(self.portal, doc) |
|---|
| | 348 | doc_obj.edit(text_format='plain', text='hello world from %s' % doc) |
|---|
| | 349 | # Create talkback for document and Add comment to my_doc |
|---|
| | 350 | self.discussion.getDiscussionFor(doc_obj) |
|---|
| | 351 | doc_obj.discussion_reply('A Reply for %s' % doc,'text of reply for %s' % doc) |
|---|
| | 352 | |
|---|
| | 353 | # Prepare pattern for publish button presence checking |
|---|
| | 354 | pattern = re.compile('.*<input\\s*class="standalone"\\s*type="submit"\\s*value="Publish This Discussion"\\s*/>',\ |
|---|
| | 355 | re.S|re.M) |
|---|
| | 356 | # FOR user without DiscussionManager role |
|---|
| | 357 | # publish button MUST BE ABSENT in document view form |
|---|
| | 358 | for u in ['admin', 'reviewer','owner','member','anonym']: |
|---|
| | 359 | self.logout() |
|---|
| | 360 | auth = u |
|---|
| | 361 | if not u=='anonym': |
|---|
| | 362 | self.login(u) |
|---|
| | 363 | auth = '%s:secret_%s' % (u,u) |
|---|
| | 364 | doc_id = "doc_%s" % u |
|---|
| | 365 | html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) |
|---|
| | 366 | m = pattern.match(html) |
|---|
| | 367 | self.assert_(not m, "Publish button present for %s user without DiscussionManager role" % u) |
|---|
| | 368 | |
|---|
| | 369 | # Check users with DiscussionManager role |
|---|
| | 370 | for u in ['dm_admin', 'dm_reviewer','dm_owner','dm_member']: |
|---|
| | 371 | self.logout() |
|---|
| | 372 | self.login(u) |
|---|
| | 373 | auth = '%s:secret_%s' % (u,u) |
|---|
| | 374 | doc_id = "doc_%s" % u |
|---|
| | 375 | # 1. Must PRESENT publish button |
|---|
| | 376 | html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) |
|---|
| | 377 | m = pattern.match(html) |
|---|
| | 378 | self.assert_(m, "It is absent Publish button for %s user with DiscussionManager role" % u) |
|---|
| | 379 | # 2. Must perform real publishing |
|---|
| | 380 | doc_obj = getattr(self.portal, doc_id) |
|---|
| | 381 | getReplies = self.discussion.getDiscussionFor(doc_obj).getReplies |
|---|
| | 382 | # Check whether anonymous get no reply |
|---|
| | 383 | self.logout() |
|---|
| | 384 | replies = getReplies() |
|---|
| | 385 | self.assert_(not replies, "Anonymous view not published discussion") |
|---|
| | 386 | # Login with actual (tested) user with DiscussionManager role and publish discussion |
|---|
| | 387 | self.login(u) |
|---|
| | 388 | replies = getReplies() |
|---|
| | 389 | self.assert_(replies, "User %s with DiscussionManager role not view not published discussion" % u) |
|---|
| | 390 | replies[0].discussion_publish_comment() |
|---|
| | 391 | # Check whether Anonym view published reply |
|---|
| | 392 | self.logout() |
|---|
| | 393 | replies = getReplies() |
|---|
| | 394 | self.assert_(replies, "User %s with DiscussionManager role not publish discussion" % u) |
|---|
| | 395 | |
|---|
| | 396 | |
|---|
| | 397 | #def testDeleting(self): |
|---|
| | 398 | |
|---|
| | 399 | |
|---|
| | 400 | TESTS = [TestInstallation, TestConfiglet, TestModeration] |
|---|