Esempio n. 1
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. 2
0
    def test_save(self, mock_save):
        wrapped_doc = IndexedFile(**{
            'name': 'file1',
            'system': 'test.system',
            'path': '/path/to/file'
        })
        base = BaseESFile('test_user',
                          system='test.system',
                          wrapped_doc=wrapped_doc)

        # Need to set attrs manually because the custom setter/getter in BaseESResource are mocked
        object.__setattr__(base, 'path', '/path/to/file')
        object.__setattr__(base, '_wrapped', wrapped_doc)

        base.save()
        # self.mock_base_update.assert_called_with(**{'basePath': '/path/to'})
        mock_save.assert_called_with()