def test_moving_objects_to_plone_site(self): """ This test makes sure that objects can be move to the Plone Site. """ self.grant('Manager') type_to_modified = self.layer['portal'].portal_types.get('Plone Site') type_to_modified.allowed_content_types = ('Document',) source = create(Builder('folder').titled('Source')) doc = create(Builder('document').within(source)) target = create(Builder('folder').titled('Target')) clipboard = source.manage_cutObjects(doc.getId()) target.manage_pasteObjects(clipboard) self.assertEquals( [{'action': 'added', 'path': '/plone/source'}, {'action': 'added', 'path': '/plone/source/document'}, {'action': 'added', 'path': '/plone/target'}, {'action': 'moved', 'path': '/plone/target/document', 'old_parent_path': '/plone/source', 'old_parent_uuid': 'testmovingobjectstoplonesi000001', 'new_parent_path': '/plone/target', 'new_parent_uuid': 'testmovingobjectstoplonesi000003'}], get_soup_activities(('path', 'action', 'old_parent_path', 'old_parent_uuid', 'new_parent_path', 'new_parent_uuid')))
def test_moving_objects(self): self.grant('Manager') source = create(Builder('folder').titled('Source')) target = create(Builder('folder').titled('Target')) doc = create(Builder('document').within(source)) clipboard = source.manage_cutObjects(doc.getId()) target.manage_pasteObjects(clipboard) self.assertEquals( [{'action': 'added', 'path': '/plone/source'}, {'action': 'added', 'path': '/plone/target'}, {'action': 'added', 'path': '/plone/source/document'}, {'action': 'moved', 'path': '/plone/target/document', 'old_parent_path': '/plone/source', 'old_parent_uuid': 'testmovingobjects000000000000001', 'new_parent_path': '/plone/target', 'new_parent_uuid': 'testmovingobjects000000000000002'}], get_soup_activities(('path', 'action', 'old_parent_path', 'old_parent_uuid', 'new_parent_path', 'new_parent_uuid')))
def test_existing_objects_are_indexed_when_installing(self): with freeze(datetime(2010, 1, 1)): folder = create(Builder('folder')) with freeze(datetime(2010, 1, 2)): create(Builder('document')) with freeze(datetime(2010, 1, 3)): create(Builder('document').within(folder)) with freeze(datetime(2010, 1, 4)): folder.notifyModified() get_activity_soup().clear() applyProfile(self.portal, 'ftw.activity:default') self.maxDiff = None self.assertEquals( [{'path': '/plone/folder', 'action': 'added', 'date': DateTime('2010/01/01')}, {'path': '/plone/document', 'action': 'added', 'date': DateTime('2010/01/02')}, {'path': '/plone/folder/document', 'action': 'added', 'date': DateTime('2010/01/03')}, {'path': '/plone/folder', 'action': 'changed', 'date': DateTime('2010/01/04')}], get_soup_activities(('path', 'action', 'date')))
def test_activity_created_when_file_downloaded(self, browser): self.grant('Contributor') file_ = create(Builder('file').with_dummy_content()) browser.login().open(file_, view='@@download') self.assertIn( {'path': '/plone/file', 'action': 'file:downloaded'}, get_soup_activities(('path', 'action')))
def test_activity_for_creating_is_added(self): self.grant('Manager') create(Builder('document')) create(Builder('dx type')) self.assertEquals( [{'path': '/plone/document', 'action': 'added'}, {'path': '/plone/dxtype', 'action': 'added'}], get_soup_activities())
def test_roles_changed_event(self, browser): self.grant('Manager') folder = create(Builder('folder').providing(IParticipationSupport)) hugo = create(Builder('user').named(u'Hugo', u'B\xf6ss') .with_roles('Manager', on=folder)) create(Builder('user').named(u'J\xf6hn', u'Doe') .with_roles('Editor', on=folder)) browser.login(hugo).open(folder, view='participants') browser.click_on('change') # Only Editor and Contributor are selectable browser.fill({'Roles': ['Contributor']}).submit() self.maxDiff = None self.assertEquals( [ {'action': 'added', 'actor': 'test_user_1_', 'path': '/plone/folder'}, {'action': 'participation:role_changed', 'actor': 'hugo.boss', 'path': '/plone/folder', 'roles:userid': 'john.doe', 'roles:old': ('Editor',), 'roles:removed': ('Editor',), 'roles:new': ('Contributor',), 'roles:added': ('Contributor',), }, ], get_soup_activities(('path', 'action', 'actor', 'roles:userid', 'roles:old', 'roles:removed', 'roles:new', 'roles:added'))) browser.open(folder, view='@@activity') newest_event = activity.events()[0] self.assertEquals( {'url': 'http://nohost/plone/folder', 'byline': u'Role changed now by B\xf6ss Hugo', 'title': ''}, newest_event.infos()) self.assertEquals( u'B\xf6ss Hugo has changed the role of Doe J\xf6hn' u' from Can edit to Can add.', newest_event.body_text)
def test_view_permission_is_required(self): self.layer['portal'].manage_permission('View', ['Reader', 'Manager']) folder = create(Builder('folder')) create(Builder('page').titled('Not visible').within(folder)) user = create(Builder('user') .with_roles('Reader', 'Contributor', on=folder)) create(Builder('page').titled('Visible').within(folder)) login(self.layer['portal'], user.getId()) self.assertEquals( [{'path': '/plone/folder/visible'}], get_soup_activities(('path',)))
def test_activity_for_changing_is_added(self): self.grant('Manager') notify(ObjectEditedEvent(create(Builder('document')))) notify(ObjectModifiedEvent(create(Builder('dx type')))) self.assertEquals( [{'path': '/plone/document', 'action': 'added'}, {'path': '/plone/document', 'action': 'changed'}, {'path': '/plone/dxtype', 'action': 'added'}, {'path': '/plone/dxtype', 'action': 'changed'}], get_soup_activities())
def test_invitation_retracted_event(self, browser): self.grant('Manager') folder = create(Builder('folder').providing(IParticipationSupport)) inviter = create(Builder('user').named(u'J\xf6hn', u'Doe')) invitation = Invitation(target=folder, email='*****@*****.**', inviter=inviter.getId(), roles=['Reader']) transaction.commit() browser.login(inviter).open(view='invitations') browser.fill({'sent_invitations:list': invitation.iid}) browser.click_on('Retract') self.maxDiff = None self.assertEquals( [ {'action': 'added', 'actor': 'test_user_1_', 'path': '/plone/folder'}, {'action': 'participation:invitation_retracted', 'actor': 'john.doe', 'path': '/plone/folder', 'invitation:inviter': 'john.doe', 'invitation:email': '*****@*****.**', 'invitation:roles': ('Reader',), }, ], get_soup_activities(('path', 'action', 'actor', 'invitation:inviter', 'invitation:email', 'invitation:roles',))) browser.open(folder, view='@@activity') newest_event = activity.events()[0] self.assertEquals( {'url': 'http://nohost/plone/folder', 'byline': u'Invitation retracted now by Doe J\xf6hn', 'title': ''}, newest_event.infos()) self.assertEquals( u'Doe J\xf6hn has retracted the invitation for [email protected].', newest_event.body_text)
def test_activity_for_object_copied_is_added(self): self.grant('Manager') folder = create(Builder('folder')) doc = create(Builder('document').within(folder)) clipboard = folder.manage_copyObjects(doc.getId()) folder.manage_pasteObjects(clipboard) self.assertEquals( [{'path': '/plone/folder', 'action': 'added'}, {'path': '/plone/folder/document', 'action': 'added'}, {'path': '/plone/folder/copy_of_document', 'action': 'added'}], get_soup_activities(('path', 'action')))
def test_activity_for_deleting_is_added(self): self.grant('Manager') doc = create(Builder('document')) aq_parent(aq_inner(doc)).manage_delObjects([doc.getId()]) doc = create(Builder('dx type')) aq_parent(aq_inner(doc)).manage_delObjects([doc.getId()]) self.assertEquals( [{'path': '/plone/document', 'action': 'added'}, {'path': '/plone/document', 'action': 'deleted'}, {'path': '/plone/dxtype', 'action': 'added'}, {'path': '/plone/dxtype', 'action': 'deleted'}], get_soup_activities())
def test_notification_sent_mail(self, browser): john = create(Builder('user').named('John', 'Doe')) hugo = create(Builder('user').named('Hugo', 'Boss')) file_ = create(Builder('file')) comment = u'Hall\xf6chen, schaut mal, das ist ne interssante Datei.' self.request['to_list'] = [john.getId()] self.request['cc_list'] = [hugo.getId()] notify(NotificationEvent(file_, comment)) self.maxDiff = None self.assertEquals( [ {'action': 'added', 'actor': 'test_user_1_', 'path': '/plone/file'}, {'action': 'notification:email_sent', 'actor': 'test_user_1_', 'path': '/plone/file', 'notification:comment': comment, 'notification:to_userids': ('john.doe', ), 'notification:cc_userids': ('hugo.boss', ), }, ], get_soup_activities(('path', 'action', 'actor', 'notification:comment', 'notification:to_userids', 'notification:cc_userids'))) transaction.commit() browser.open(file_, view='@@activity') newest_event = activity.events()[0] self.assertEquals( {'url': 'http://nohost/plone/file/view', 'byline': 'Notification sent now by test_user_1_', 'title': ''}, newest_event.infos()) self.assertEquals( u'TO: Doe John' u' CC: Boss Hugo' u' Comment: ' + comment, newest_event.body_text)
def test_adding_a_comment(self, browser): """ This test makes sure that an activity is added when a comment is created. """ self.grant('Manager') self.enable_discussion_for_document() browser.login().visit(create(Builder('document'))) browser.fill({'Comment': 'Hello World'}).submit() transaction.begin() self.assertEquals( [{'path': '/plone/document', 'action': 'added'}, {'path': '/plone/document', 'action': 'comment:added', 'comment_text': 'Hello World'}], get_soup_activities(('path', 'action', 'comment_text')))
def test_invitation_created_activity(self, browser): self.grant('Manager') user = create(Builder('user').named(u'J\xf6hn', u'Doe') .with_roles('Manager')) folder = create(Builder('folder').providing(IParticipationSupport)) browser.login(user).open(folder, view='invite_participants') browser.fill({'E-Mail Addresses': '*****@*****.**', 'Roles': ['Contributor'], 'Comment': u'Hi th\xf6re'}) browser.find('Invite').click() self.maxDiff = None self.assertEquals( [ {'action': 'added', 'actor': 'test_user_1_', 'path': '/plone/folder'}, {'action': 'participation:invitation_created', 'actor': 'john.doe', 'path': '/plone/folder', 'invitation:inviter': u'john.doe', 'invitation:email': u'*****@*****.**', 'invitation:roles': (u'Contributor',), 'invitation:comment': u'Hi th\xf6re', }, ], get_soup_activities(('path', 'action', 'actor', 'invitation:inviter', 'invitation:email', 'invitation:roles', 'invitation:comment'))) browser.open(folder, view='@@activity') newest_event = activity.events()[0] self.assertEquals( {'url': 'http://nohost/plone/folder', 'byline': u'Invitation created now by Doe J\xf6hn', 'title': ''}, newest_event.infos()) self.assertEquals( u'Doe J\xf6hn has invited [email protected] as Can add.', newest_event.body_text)
def test_invitation_accepted_event(self, browser): self.grant('Manager') folder = create(Builder('folder').providing(IParticipationSupport)) inviter = create(Builder('user').named(u'J\xf6hn', u'Doe')) user = create(Builder('user').named(u'Hugo', u'B\xf6ss')) Invitation(target=folder, email=user.getProperty('email'), inviter=inviter.getId(), roles=['Reader']) transaction.commit() browser.login(user).open(view='invitations') browser.click_on("Yes, I'd like to participate") self.maxDiff = None self.assertEquals( [ {'action': 'added', 'actor': 'test_user_1_', 'path': '/plone/folder'}, {'action': 'participation:invitation_accepted', 'actor': 'hugo.boss', 'path': '/plone/folder', 'invitation:inviter': 'john.doe', 'invitation:email': '*****@*****.**', 'invitation:roles': ('Reader',), }, ], get_soup_activities(('path', 'action', 'actor', 'invitation:inviter', 'invitation:email', 'invitation:roles',))) browser.open(folder, view='@@activity') newest_event = activity.events()[0] self.assertEquals( {'url': 'http://nohost/plone/folder', 'byline': u'Invitation accepted now by B\xf6ss Hugo', 'title': ''}, newest_event.infos())
def test_adding_and_removing_a_comment_reply(self, browser): """ This test makes sure that an activity is added when a comment reply is created / removed. This requires JavaScript, therfore we cannot test it with our testbrowser. """ self.grant('Manager') self.enable_discussion_for_document() conversation = IConversation(create(Builder('document'))) comment = createObject('plone.Comment') comment.text = 'Comment' comment_id = conversation.addComment(comment) reply = createObject('plone.Comment') reply.text = 'Reply' reply.in_reply_to = comment_id reply_id = conversation.addComment(reply) del conversation[reply_id] self.maxDiff = None self.assertEquals( [{'path': '/plone/document', 'action': 'added'}, {'path': '/plone/document', 'action': 'comment:added', 'comment_text': 'Comment', 'comment_id': comment_id}, {'path': '/plone/document', 'action': 'comment:added', 'comment_text': 'Reply', 'comment_id': reply_id, 'comment_in_reply_to': comment_id}, {'path': '/plone/document', 'action': 'comment:removed', 'comment_text': 'Reply', 'comment_id': reply_id, 'comment_in_reply_to': comment_id}], get_soup_activities(('path', 'action', 'comment_text', 'comment_id', 'comment_in_reply_to')))
def test_renaming_object_creates_no_record(self): # Renaming means changing the ID / URL of a content, # but not changing it's title. # Since this is normally not important for the common user, # we don't create records in this case. # There is no profound reason though. self.grant('Manager') folder = create(Builder('folder')) create(Builder('document').titled(u'Foo').within(folder)) folder.manage_renameObject('foo', 'bar') self.assertEquals( [{'path': '/plone/folder', 'action': 'added'}, {'path': '/plone/folder/foo', 'action': 'added'}], get_soup_activities(('path', 'action')))
def test_local_role_removed(self, browser): self.grant('Manager') folder = create(Builder('folder').providing(IParticipationSupport)) hugo = create(Builder('user').named(u'Hugo', u'B\xf6ss') .with_roles('Manager', on=folder)) user = create(Builder('user').named(u'J\xf6hn', u'Doe') .with_roles('Editor', on=folder)) browser.login(hugo).open(folder, view='participants') browser.fill({'userids:list': [user.getId()]}) \ .find('Delete Participants').click() self.maxDiff = None self.assertEquals( [ {'action': 'added', 'actor': 'test_user_1_', 'path': '/plone/folder'}, {'action': 'participation:role_removed', 'actor': 'hugo.boss', 'path': '/plone/folder', 'roles:userid': 'john.doe', }, ], get_soup_activities(('path', 'action', 'actor', 'roles:userid'))) browser.open(folder, view='@@activity') newest_event = activity.events()[0] self.assertEquals( {'url': 'http://nohost/plone/folder', 'byline': u'Participant removed now by B\xf6ss Hugo', 'title': ''}, newest_event.infos()) self.assertEquals( u'B\xf6ss Hugo has removed the participant Doe J\xf6hn.', newest_event.body_text)
def test_activity_for_workflow_transition_is_added(self): self.grant('Manager') wftool = getToolByName(self.layer['portal'], 'portal_workflow') wftool.setChainForPortalTypes(['Document'], 'simple_publication_workflow') doc = create(Builder('document').titled(u'The Document')) wftool.doActionFor(doc, 'publish') self.assertEquals( [{'path': '/plone/the-document', 'action': 'added'}, {'path': '/plone/the-document', 'action': 'transition', 'transition': 'publish', 'workflow': 'simple_publication_workflow', 'old_state': 'private', 'new_state': 'published'}], get_soup_activities(('path', 'action', 'transition', 'workflow', 'old_state', 'new_state')))