def get_file_guids(cls, materialized_path, provider, target=None): guids = [] path = materialized_path.strip('/') file_obj = cls.load(path) if not file_obj: file_obj = TrashedFileNode.load(path) # At this point, file_obj may be an OsfStorageFile, an OsfStorageFolder, or a # TrashedFileNode. TrashedFileNodes do not have *File and *Folder subclasses, since # only osfstorage trashes folders. To search for children of TrashFileNodes # representing ex-OsfStorageFolders, we will reimplement the `children` method of the # Folder class here. if not file_obj.is_file: children = [] if isinstance(file_obj, TrashedFileNode): children = file_obj.trashed_children.all() else: children = file_obj.children for item in children: guids.extend(cls.get_file_guids(item.path, provider, target=target)) else: guid = file_obj.get_guid() if guid: guids.append(guid._id) return sorted(guids)
def test_delete_action_creates_trashed_file_node(self): file_node = self.get_test_file() payload = { 'provider': file_node.provider, 'metadata': { 'path': '/test/Test', 'materialized': '/test/Test' } } views.addon_delete_file_node(self=None, node=self.project, user=self.user, event_type='file_removed', payload=payload) assert_false(GithubFileNode.load(file_node._id)) assert_true(TrashedFileNode.load(file_node._id))
def test_delete_action_for_folder_deletes_subfolders_and_creates_trashed_file_nodes(self): file_node = self.get_test_file() subfolder = GithubFolder( name='folder', node=self.project, path='/test/folder/', materialized_path='/test/folder/', ) subfolder.save() payload = { 'provider': file_node.provider, 'metadata': { 'path': '/test/', 'materialized': '/test/' } } views.addon_delete_file_node(self=None, node=self.project, user=self.user, event_type='file_removed', payload=payload) assert_false(GithubFileNode.load(subfolder._id)) assert_true(TrashedFileNode.load(file_node._id))
def test_view_file_does_not_delete_file_when_requesting_invalid_version(self): with mock.patch('addons.github.models.NodeSettings.is_private', new_callable=mock.PropertyMock) as mock_is_private: mock_is_private.return_value = False file_node = self.get_test_file() assert_is(file_node.get_guid(), None) url = self.project.web_url_for( 'addon_view_or_download_file', path=file_node.path.strip('/'), provider='github', ) # First view generated GUID self.app.get(url, auth=self.user.auth) self.app.get(url + '?version=invalid', auth=self.user.auth, expect_errors=True) assert_is_not_none(BaseFileNode.load(file_node._id)) assert_is_none(TrashedFileNode.load(file_node._id))