Esempio n. 1
0
    def test_delete_recursive(self, mock_children, mock_delete):
        wrapped_doc = IndexedFile(
            **{
                'name': 'folder1',
                'system': 'test.system',
                'path': '/path/to/folder',
                'format': 'folder'
            })
        base = BaseESFile('test_user',
                          system='test.system',
                          wrapped_doc=wrapped_doc)
        object.__setattr__(base, '_wrapped', wrapped_doc)
        object.__setattr__(base, 'format', 'folder')
        object.__setattr__(base, 'path', '/path/to/folder')

        child_doc = IndexedFile(
            **{
                'name': 'child1',
                'system': 'test.system',
                'path': '/path/to/child1',
                'format': 'file'
            })
        base_child = BaseESFile('test_user',
                                system='test.system',
                                wrapped_doc=child_doc)
        object.__setattr__(base_child, '_wrapped', child_doc)
        object.__setattr__(base_child, 'format', 'file')
        object.__setattr__(base_child, 'path', '/path/to/child1')

        mock_children.return_value = iter([base_child])

        base.delete()
        # Assert 2 delete calls: 1 for parent, 1 for child
        self.assertEqual(mock_delete.call_count, 2)
Esempio n. 2
0
def index_level(client,
                path,
                folders,
                files,
                systemId,
                username,
                reindex=False,
                update_pems=True):
    """
    Index a set of folders and files corresponding to the output from one 
    iteration of walk_levels
    """
    from designsafe.libs.elasticsearch.docs.files import BaseESFile
    for obj in folders + files:
        obj_dict = obj.to_dict()
        obj_dict.pop('permissions')
        obj_dict.pop('trail')
        obj_dict.pop('_links')
        doc = BaseESFile(username, reindex=reindex, **obj_dict)

        saved = doc.save()

        if update_pems:
            permissions = client.files.listPermissions(systemId=systemId,
                                                       filePath=obj.path)
            for pem in permissions:
                pem.pop('_links')
            doc.update(**{'permissions': permissions})

    children_paths = [_file.path for _file in folders + files]
    es_root = BaseESFile(username, systemId, path, reindex=reindex)
    for doc in es_root.children():
        if doc is not None and doc.path not in children_paths:
            doc.delete()
Esempio n. 3
0
    def test_delete_no_dir(self, mock_delete):
        wrapped_doc = IndexedFile(
            **{
                'name': 'file1',
                'system': 'test.system',
                'path': '/path/to/file',
                'format': 'file'
            })
        base = BaseESFile('test_user',
                          system='test.system',
                          wrapped_doc=wrapped_doc)

        object.__setattr__(base, '_wrapped', wrapped_doc)

        base.delete()
        mock_delete.assert_called_with()