def test_add_nonorderable(self): """We add non-orderable content in the folder. It is not added to the order manager. """ manager = IOrderManager(self.root.folder) factory = self.root.folder.manage_addProduct['Silva'] with assertNotTriggersEvents('ContentOrderChangedEvent'): factory.manage_addMockupAsset('asset1', 'Asset 1') asset1 = self.root.folder._getOb('asset1') self.assertEqual(manager.get_position(asset1), -1) self.assertEqual(len(manager), 0) # If you add an item if will be correctly added. with assertNotTriggersEvents('ContentOrderChangedEvent'): factory.manage_addMockupVersionedContent('item1', 'Item 1') item1 = self.root.folder._getOb('item1') self.assertEqual(manager.get_position(item1), 0) self.assertEqual(len(manager), 1) # Asset still don't go through. with assertNotTriggersEvents('ContentOrderChangedEvent'): factory.manage_addMockupAsset('asset2', 'Asset 2') asset2 = self.root.folder._getOb('asset2') self.assertEqual(manager.get_position(asset2), -1) self.assertEqual(len(manager), 1)
def test_activation(self): service = queryUtility(IForestService) with assertTriggersEvents( 'ForestWillBeActivatedEvent', 'ForestActivatedEvent'): service.activate() self.assertTrue(service.is_active()) request = TestRequest(application=self.root) plugin = request.query_plugin(request.application, IVirtualHosting) self.assertTrue(verifyObject(IForestHosting, plugin)) # You cannot activate the service twice. with self.assertRaises(ValueError): with assertNotTriggersEvents(): service.activate() self.assertTrue(service.is_active()) with assertTriggersEvents( 'ForestWillBeDeactivatedEvent', 'ForestDeactivatedEvent'): service.deactivate() self.assertFalse(service.is_active()) # The service is not active. with self.assertRaises(ValueError): with assertNotTriggersEvents(): service.deactivate()
def test_remove_orderable(self): """If we remove an orderable, it is no longer available in the order manager, and position of content following this one are changed as well. """ source = self.root.source manager = IOrderManager(source) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(manager.get_position(source.asset1), -1) self.assertEqual(len(manager), 3) item2 = source.item2 with assertNotTriggersEvents('ContentOrderChangedEvent'): with IContainerManager(source).deleter() as deleter: self.assertEqual(deleter(item2), item2) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item3), 1) self.assertEqual(manager.get_position(item2), -1) self.assertEqual(len(manager), 2) # The order is valid, repair return False. self.assertEqual(manager.repair(source.objectValues()), False)
def test_move_orderable(self): """If you move an orderable, it is removed from the source order manager and added to the target order manager. """ source = self.root.source target = self.root.target manager_source = IOrderManager(source) manager_target = IOrderManager(target) self.assertEqual(manager_source.get_position(source.item1), 0) self.assertEqual(manager_source.get_position(source.item2), 1) self.assertEqual(manager_source.get_position(source.item3), 2) self.assertEqual(manager_source.get_position(source.asset1), -1) self.assertEqual(len(manager_source), 3) self.assertEqual(len(manager_target), 1) with assertNotTriggersEvents('ContentOrderChangedEvent'): with IContainerManager(target).mover() as mover: mover(source.item2) item2 = source._getOb('item2', None) self.assertEqual(item2, None) item2 = target._getOb('item2', None) self.assertNotEqual(item2, None) self.assertEqual(manager_source.get_position(source.item1), 0) self.assertEqual(manager_source.get_position(source.item3), 1) self.assertEqual(len(manager_source), 2) self.assertEqual(manager_target.get_position(target.base1), 0) self.assertEqual(manager_target.get_position(target.item2), 1) self.assertEqual(len(manager_target), 2) # The order is valid, repair return False. self.assertEqual(manager_source.repair(source.objectValues()), False) self.assertEqual(manager_target.repair(target.objectValues()), False)
def test_copy_orderable(self): """If we copy a orderable content, the copy is added to the order manager, and the other order are not touched. """ source = self.root.source manager = IOrderManager(source) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(manager.get_position(source.asset1), -1) self.assertEqual(len(manager), 3) item2 = source.item2 with assertNotTriggersEvents('ContentOrderChangedEvent'): with IContainerManager(source).copier() as copier: copier(item2) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(manager.get_position(source.copy_of_item2), 3) self.assertEqual(len(manager), 4) # The order is valid, repair return False. self.assertEqual(manager.repair(source.objectValues()), False)
def test_move_nonorderable(self): """If we move an nonorderable content, nothing is changed. """ source = self.root.source target = self.root.target manager_source = IOrderManager(source) manager_target = IOrderManager(target) self.assertEqual(manager_source.get_position(source.item1), 0) self.assertEqual(manager_source.get_position(source.item2), 1) self.assertEqual(manager_source.get_position(source.item3), 2) self.assertEqual(manager_source.get_position(source.asset1), -1) self.assertEqual(len(manager_source), 3) self.assertEqual(len(manager_target), 1) with assertNotTriggersEvents('ContentOrderChangedEvent'): with IContainerManager(target).mover() as mover: mover(source.asset1) asset1 = source._getOb('asset1', None) self.assertEqual(asset1, None) asset1 = target._getOb('asset1', None) self.assertNotEqual(asset1, None) self.assertEqual(manager_source.get_position(source.item1), 0) self.assertEqual(manager_source.get_position(source.item2), 1) self.assertEqual(manager_source.get_position(source.item3), 2) self.assertEqual(len(manager_source), 3) self.assertEqual(len(manager_target), 1)
def test_grant_role_as_manager(self): """Test setting a role (as a Manager). """ self.layer.login('manager') access = IAuthorizationManager(self.root.folder) authorization = access.get_authorization('reader') self.assertEqual(authorization.role, 'Reader') # The user already have role, reader, so this does nothing with assertNotTriggersEvents('SecurityRoleAddedEvent'): self.assertEqual(authorization.grant('Reader'), False) self.assertEqual(authorization.local_role, None) # The user doesn't have that role so it is set with assertTriggersEvents('SecurityRoleAddedEvent'): self.assertEqual(authorization.grant('Manager'), True) self.assertEqual(authorization.local_role, 'Manager') # Now the user is editor self.assertEqual(authorization.role, 'Manager') # A new query returns the same results authorization = access.get_authorization('reader') self.assertEqual(authorization.local_role, 'Manager') self.assertEqual(authorization.role, 'Manager')
def test_revoke_as_nobody(self): """Revoke local roles as nobody. """ self.layer.login('dummy') access = IAuthorizationManager(self.root) # We don't have the right to revoke that role authorization = access.get_authorization('reader') with assertNotTriggersEvents('SecurityRoleRemovedEvent'): with self.assertRaises(UnauthorizedRoleAssignement): authorization.revoke() # We don't have the right to revoke that role authorization = access.get_authorization('viewer') with assertNotTriggersEvents('SecurityRoleRemovedEvent'): with self.assertRaises(UnauthorizedRoleAssignement): authorization.revoke()
def test_revoke_no_role(self): """Revoke local role when there is no local role. """ access = IAuthorizationManager(self.folder) authorization = access.get_authorization('viewer') self.assertEqual(authorization.local_role, None) with assertNotTriggersEvents('SecurityRoleRemovedEvent'): self.assertEqual(authorization.revoke(), False) self.assertEqual(authorization.local_role, None)
def test_copy_not_addable_content(self): """Move a content that is not addable in the target folder. This should not be possible (for everybody). """ self.root.target.set_silva_addables_allowed_in_container(["Silva Image", "Silva File"]) manager = IContainerManager(self.root.target) with assertNotTriggersEvents("ObjectWillBeMovedEvent", "ObjectMovedEvent", "ContainerModifiedEvent"): with manager.copier() as copier: self.assertIsInstance(copier(self.root.source.toc), ContainerError) self.assertEqual(self.root.target.objectIds(), [])
def test_move_content_same_container(self): """Move a single content into the same container than it is already there. """ manager = IContainerManager(self.root.source) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance(mover(self.root.source.toc), ContainerError) self.assertTrue('toc' in self.root.source.objectIds())
def test_delete_published_recursive(self): """An author cannot delete a folder that contains published content. """ manager = IContainerManager(self.root) with assertNotTriggersEvents('ObjectWillBeRemovedEvent', 'ObjectRemovedEvent', 'ContainerModifiedEvent'): with manager.deleter() as deleter: self.assertIsInstance(deleter(self.root.folder), ContentError) self.assertTrue('folder' in self.root.objectIds())
def test_move_content_same_container(self): """Move a single content into the same container than it is already there. """ manager = IContainerManager(self.root.source) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance( mover(self.root.source.toc), ContainerError) self.assertTrue('toc' in self.root.source.objectIds())
def test_rename_title(self): """Rename only the title for a single non-publishable item. """ manager = IContainerManager(self.root.folder) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertNotEqual( renamer((self.root.folder.toc, None, 'New AutoTOC')), None) self.assertTrue('toc' in self.root.folder.objectIds()) self.assertTrue(verifyObject(IAutoTOC, self.root.folder.toc)) self.assertEqual(self.root.folder.toc.get_title(), 'New AutoTOC')
def test_add_orderable(self): """We add an orderable in the folder. It is added to the order manager. """ manager = IOrderManager(self.root.folder) factory = self.root.folder.manage_addProduct['Silva'] # First item have position 0 with assertNotTriggersEvents('ContentOrderChangedEvent'): factory.manage_addMockupVersionedContent('item1', 'Item 1') item1 = self.root.folder._getOb('item1') self.assertEqual(manager.get_position(item1), 0) self.assertEqual(len(manager), 1) # Next item have position 1 with assertNotTriggersEvents('ContentOrderChangedEvent'): factory.manage_addMockupVersionedContent('item2', 'Item 2') item2 = self.root.folder._getOb('item2') self.assertEqual(manager.get_position(item2), 1) self.assertEqual(len(manager), 2) # The order is valid, repair return False. self.assertEqual(manager.repair(self.root.folder.objectValues()), False)
def test_delete_published(self): """An author cannot delete published content. """ manager = IContainerManager(self.root.folder) with assertNotTriggersEvents( 'ObjectWillBeRemovedEvent', 'ObjectRemovedEvent', 'ContainerModifiedEvent'): with manager.deleter() as deleter: self.assertIsInstance( deleter(self.root.folder.published_link), ContentError) self.assertTrue('published_link' in self.root.folder.objectIds())
def test_move_published_container(self): """Move a single published container. Authors doesn't have the right to do it. """ manager = IContainerManager(self.root.target) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance(mover(self.root.source), ContentError) self.assertTrue('source' in self.root.objectIds()) self.assertFalse('source' in self.root.target.objectIds()) self.assertTrue(verifyObject(IFolder, self.root.source))
def test_delete_invalid(self): manager = IContainerManager(self.root.folder) with assertNotTriggersEvents('ObjectWillBeRemovedEvent', 'ObjectRemovedEvent', 'ContainerModifiedEvent'): with manager.deleter() as deleter: self.assertIsInstance(deleter(self.root.publication), ContentError) self.assertIsInstance(deleter(self.root.toc), ContentError) self.assertIsInstance(deleter(self.root.folder), ContentError) self.assertTrue('publication' in self.root.objectIds()) self.assertTrue('toc' in self.root.objectIds()) self.assertTrue('folder' in self.root.objectIds())
def test_grant_role(self): """Test setting a role (as a ChiefEditor). """ access = IAuthorizationManager(self.root.folder) authorization = access.get_authorization('reader') self.assertEqual(authorization.role, 'Reader') # We (chiefeditor) don't have Manager, so can't give that role. with assertNotTriggersEvents('SecurityRoleAddedEvent'): with self.assertRaises(UnauthorizedRoleAssignement): authorization.grant('Manager') # The user already have role, reader, so this does nothing with assertNotTriggersEvents('SecurityRoleAddedEvent'): self.assertEqual(authorization.grant('Viewer'), False) self.assertEqual(authorization.local_role, None) # The user doesn't have that role so it is set with assertTriggersEvents('SecurityRoleAddedEvent'): self.assertEqual(authorization.grant('Editor'), True) self.assertEqual(authorization.local_role, 'Editor') # Now the user is editor self.assertEqual(authorization.role, 'Editor')
def test_rename_id_already_in_use(self): """Rename a content to an id which is already in use. """ manager = IContainerManager(self.root.folder) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertIsInstance( renamer((self.root.folder.toc, 'link', None)), ContainerError) self.assertTrue('toc' in self.root.folder.objectIds()) self.assertTrue('link' in self.root.folder.objectIds()) self.assertTrue(verifyObject(IAutoTOC, self.root.folder.toc)) self.assertTrue(verifyObject(ILink, self.root.folder.link))
def test_move_published_container(self): """Move a single published container. Authors doesn't have the right to do it. """ manager = IContainerManager(self.root.target) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance( mover(self.root.source), ContentError) self.assertTrue('source' in self.root.objectIds()) self.assertFalse('source' in self.root.target.objectIds()) self.assertTrue(verifyObject(IFolder, self.root.source))
def test_move_published_content(self): """Move a single published content. Authors doesn't have the right to do it. The link stays published. """ manager = IContainerManager(self.root.target) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance(mover(self.root.source.published_link), ContentError) self.assertTrue('published_link' in self.root.source.objectIds()) self.assertFalse('published_link' in self.root.target.objectIds()) self.assertTrue(verifyObject(ILink, self.root.source.published_link)) self.assertNotEqual(self.root.source.published_link.get_viewable(), None)
def test_move_published_content(self): """Move a single published content. Authors doesn't have the right to do it. The link stays published. """ manager = IContainerManager(self.root.target) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance( mover(self.root.source.published_link), ContentError) self.assertTrue('published_link' in self.root.source.objectIds()) self.assertFalse('published_link' in self.root.target.objectIds()) self.assertTrue(verifyObject(ILink, self.root.source.published_link)) self.assertNotEqual(self.root.source.published_link.get_viewable(), None)
def test_copy_not_addable_content(self): """Move a content that is not addable in the target folder. This should not be possible (for everybody). """ self.root.target.set_silva_addables_allowed_in_container( ['Silva Image', 'Silva File']) manager = IContainerManager(self.root.target) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.copier() as copier: self.assertIsInstance( copier(self.root.source.toc), ContainerError) self.assertEqual(self.root.target.objectIds(), [])
def test_rename_published_content_title(self): """Rename only the title on a published content. Nothing happens (except an error). """ link = self.root.folder.published_link manager = IContainerManager(self.root.folder) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertIsInstance(renamer((link, None, 'Updated Link')), ContentError) self.assertEqual(link, self.root.folder.published_link) self.assertTrue('published_link' in self.root.folder.objectIds()) self.assertTrue(verifyObject(ILink, link)) self.assertEqual(link.get_title(), 'Published Link') self.assertEqual(link.get_editable(), None)
def test_rename_published_container_id_and_title(self): """Rename a published container it and title. An author can only change the title. """ manager = IContainerManager(self.root) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertNotEqual( renamer((self.root.folder, 'archives', 'Archives')), None) self.assertTrue('folder' in self.root.objectIds()) self.assertFalse('archives' in self.root.objectIds()) self.assertTrue(verifyObject(IFolder, self.root.folder)) # Author got the permission to change the title. self.assertEqual(self.root.folder.get_title(), 'Archives')
def test_close_publish(self): versioning = self.root.versioning # nothing to close self.assertRaises(Versioning.VersioningError, versioning.close_version) # create new version versioning.create_version('0', DateTime() + 10, DateTime() + 20) # change datetime versioning.set_unapproved_version_publication_datetime(DateTime() - 10) # unapproved versions cannot be closed self.assertRaises(Versioning.VersioningError, versioning.close_version) # now approve it with assertTriggersEvents('ContentApprovedEvent', 'ContentPublishedEvent'): versioning.approve_version() self.assertEqual(versioning.get_public_version(), '0') self.assertEqual(versioning.get_approved_version(), None) self.assertEqual(versioning.get_unapproved_version(), None) self.assertEqual(versioning.get_last_closed_version(), None) with assertTriggersEvents('ContentClosedEvent'): versioning.close_version() # create new version versioning.create_version('1', DateTime() - 5, DateTime() + 20) self.assertEqual(versioning.get_public_version(), None) self.assertEqual(versioning.get_approved_version(), None) self.assertEqual(versioning.get_unapproved_version(), '1') self.assertEqual(versioning.get_last_closed_version(), '0') # approve it with assertNotTriggersEvents('ContentClosedEvent'): with assertTriggersEvents('ContentApprovedEvent', 'ContentPublishedEvent'): versioning.approve_version() # second should be public now, first is close self.assertEqual(versioning.get_public_version(), '1') self.assertEqual(versioning.get_approved_version(), None) self.assertEqual(versioning.get_unapproved_version(), None) self.assertEqual(versioning.get_last_closed_version(), '0')
def test_rename_new_version_content_title(self): """Rename only the title on a new version of a published content. (The title is an utf-8 string, not unicode, to test encodings.) """ link = self.root.folder.published_link manager = IContainerManager(self.root.folder) IPublicationWorkflow(link).new_version() with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertEqual(renamer((link, None, 'Updaté Link')), link) self.assertEqual(link, self.root.folder.published_link) self.assertTrue('published_link' in self.root.folder.objectIds()) self.assertTrue(verifyObject(ILink, link)) self.assertEqual(link.get_title(), 'Published Link') self.assertEqual(link.get_editable().get_title(), u'Updaté Link')
def test_rename_published_content_title(self): """Rename only the title on a published content. Nothing happens (except an error). """ link = self.root.folder.published_link manager = IContainerManager(self.root.folder) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertIsInstance( renamer((link, None, 'Updated Link')), ContentError) self.assertEqual(link, self.root.folder.published_link) self.assertTrue('published_link' in self.root.folder.objectIds()) self.assertTrue(verifyObject(ILink, link)) self.assertEqual(link.get_title(), 'Published Link') self.assertEqual(link.get_editable(), None)
def test_rename_published_content_id_and_title(self): """Rename a published content id and title. An author can't do anything, nothing is done. """ link = self.root.folder.published_link manager = IContainerManager(self.root.folder) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertIsInstance( renamer((link, 'updated_link', 'Updated Link')), ContentError) self.assertEqual(link, self.root.folder.published_link) self.assertTrue('published_link' in self.root.folder.objectIds()) self.assertFalse('updated_link' in self.root.folder.objectIds()) self.assertTrue(verifyObject(ILink, link)) self.assertEqual(link.get_title(), 'Published Link')
def test_move_not_addable_content(self): """Move a content that is not addable in the target folder. This should not be possible (for everybody). """ self.root.target.set_silva_addables_allowed_in_container( ['Silva Image', 'Silva File']) manager = IContainerManager(self.root.target) with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.mover() as mover: self.assertIsInstance( mover(self.root.source.toc), ContainerError) self.assertTrue('toc' in self.root.source.objectIds()) self.assertEqual(self.root.target.objectIds(), []) self.assertTrue(verifyObject(IAutoTOC, self.root.source.toc))
def test_revoke_own_role_as_chiefeditor(self): """Revoke its own local role as chiefeditor. """ self.layer.login('viewer') access = IAuthorizationManager(self.root.publication) authorization = access.get_authorization('viewer') self.assertEqual(authorization.local_role, 'ChiefEditor') self.assertEqual(authorization.acquired_role, 'Reader') self.assertEqual(authorization.role, 'ChiefEditor') # We try to revoke the role with assertNotTriggersEvents('SecurityRoleRemovedEvent'): with self.assertRaises(UnauthorizedRoleAssignement): authorization.revoke() self.assertEqual(authorization.local_role, 'ChiefEditor') self.assertEqual(authorization.acquired_role, 'Reader') self.assertEqual(authorization.role, 'ChiefEditor')
def test_rename_new_version_content_title(self): """Rename only the title on a new version of a published content. (The title is an utf-8 string, not unicode, to test encodings.) """ link = self.root.folder.published_link manager = IContainerManager(self.root.folder) IPublicationWorkflow(link).new_version() with assertNotTriggersEvents('ObjectWillBeMovedEvent', 'ObjectMovedEvent', 'ContainerModifiedEvent'): with manager.renamer() as renamer: self.assertEqual( renamer((link, None, 'Updaté Link')), link) self.assertEqual(link, self.root.folder.published_link) self.assertTrue('published_link' in self.root.folder.objectIds()) self.assertTrue(verifyObject(ILink, link)) self.assertEqual(link.get_title(), 'Published Link') self.assertEqual(link.get_editable().get_title(), u'Updaté Link')
def test_delete_invalid(self): manager = IContainerManager(self.root.folder) with assertNotTriggersEvents( 'ObjectWillBeRemovedEvent', 'ObjectRemovedEvent', 'ContainerModifiedEvent'): with manager.deleter() as deleter: self.assertIsInstance( deleter(self.root.publication), ContentError) self.assertIsInstance( deleter(self.root.toc), ContentError) self.assertIsInstance( deleter(self.root.folder), ContentError) self.assertTrue('publication' in self.root.objectIds()) self.assertTrue('toc' in self.root.objectIds()) self.assertTrue('folder' in self.root.objectIds())
def test_revoke_as_chiefeditor_unauthorized(self): """Try to revoke a manager local role as a chiefeditor. """ self.layer.login('chiefeditor') access = IAuthorizationManager(self.folder) authorization = access.get_authorization('reader') self.assertEqual(authorization.local_role, 'Manager') self.assertEqual(authorization.acquired_role, 'Editor') self.assertEqual(authorization.role, 'Manager') # We don't have the right to revoke that role with assertNotTriggersEvents('SecurityRoleRemovedEvent'): with self.assertRaises(UnauthorizedRoleAssignement): authorization.revoke() # So it is not changed self.assertEqual(authorization.local_role, 'Manager') self.assertEqual(authorization.acquired_role, 'Editor') self.assertEqual(authorization.role, 'Manager')
def test_remove_nonorderable(self): """If we remove an nonorderable content nothing is changed. """ source = self.root.source manager = IOrderManager(source) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(manager.get_position(source.asset1), -1) self.assertEqual(len(manager), 3) with assertNotTriggersEvents('ContentOrderChangedEvent'): with IContainerManager(source).deleter() as deleter: self.assertEqual(deleter(source.asset1), source.asset1) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(len(manager), 3) asset1 = source._getOb('asset1', None) self.assertEqual(asset1, None)
def test_grant_role_as_nobody(self): """Test setting a role while being nobody. """ self.layer.login('dummy') access = IAuthorizationManager(self.root.folder) authorization = access.get_authorization('reader') self.assertEqual(authorization.role, 'Reader') # You don't have the right to do any of those with assertNotTriggersEvents('SecurityRoleAddedEvent'): with self.assertRaises(UnauthorizedRoleAssignement): authorization.grant('Manager') with self.assertRaises(UnauthorizedRoleAssignement): authorization.grant('Editor') with self.assertRaises(UnauthorizedRoleAssignement): authorization.grant('Author') # The user already have role, reader, so this does nothing self.assertEqual(authorization.grant('Viewer'), False) # Nothing changed self.assertEqual(authorization.local_role, None) self.assertEqual(authorization.role, 'Reader')
def test_rename_orderable(self): """If you rename a content, its order must be keept (and not changed). """ source = self.root.source manager = IOrderManager(source) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.item2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(manager.get_position(source.asset1), -1) self.assertEqual(len(manager), 3) with assertNotTriggersEvents('ContentOrderChangedEvent'): with IContainerManager(source).renamer() as renamer: renamer((source.item2, 'super2', None)) self.assertEqual(manager.get_position(source.item1), 0) self.assertEqual(manager.get_position(source.super2), 1) self.assertEqual(manager.get_position(source.item3), 2) self.assertEqual(manager.get_position(source.asset1), -1) self.assertEqual(len(manager), 3) # The order is valid, repair return False. self.assertEqual(manager.repair(source.objectValues()), False)