def get_version_info_test(self): store = Mock(GenericServerStore) # Block doesn't exist and user is other p = PublishService(store, 'any_user') block_brl = BRLBlock("user/user/theblock/master") store.read_block_permissions = Mock(side_effect=NotInStoreException()) block_info = p.get_block_info(block_brl) self.assertFalse(block_info.can_write) # Now block exists store.read_block_permissions = Mock(return_value=ElementPermissions(block_brl)) # Block exists and user is the authorized one p = PublishService(store, 'theuser') block_brl = BRLBlock("theuser/theuser/theblock/master") block_info = p.get_block_info(block_brl) self.assertTrue(block_info.can_write) # No authorized write to an existing block p = PublishService(store, 'wronguser') user = Mock(User) user.administrators = Permissions() store.read_user = Mock(return_value=user) block_info = p.get_block_info(block_brl) self.assertFalse(block_info.can_write) # Authorized user with an existing block p = PublishService(store, 'theuser') block_brl = BRLBlock("theuser/theuser/theblock/master") block_info = p.get_block_info(block_brl) self.assertTrue(block_info.can_write)
def get_version_info_test(self): store = Mock(GenericServerStore) # Block doesn't exist and user is other p = PublishService(store, 'any_user') block_brl = BRLBlock("user/user/theblock/master") store.read_block_permissions = Mock(side_effect=NotInStoreException()) block_info = p.get_block_info(block_brl) self.assertFalse(block_info.can_write) # Now block exists store.read_block_permissions = Mock( return_value=ElementPermissions(block_brl)) # Block exists and user is the authorized one p = PublishService(store, 'theuser') block_brl = BRLBlock("theuser/theuser/theblock/master") block_info = p.get_block_info(block_brl) self.assertTrue(block_info.can_write) # No authorized write to an existing block p = PublishService(store, 'wronguser') user = Mock(User) user.administrators = Permissions() store.read_user = Mock(return_value=user) block_info = p.get_block_info(block_brl) self.assertFalse(block_info.can_write) # Authorized user with an existing block p = PublishService(store, 'theuser') block_brl = BRLBlock("theuser/theuser/theblock/master") block_info = p.get_block_info(block_brl) self.assertTrue(block_info.can_write)
def get_block_info(self, brl_block): ''' Read the block and get a BlockInfo object''' p = PublishService(self._store, self._auth_user) return p.get_block_info(brl_block)