Esempio n. 1
0
def create_entity_tree(
    test_with_baton: TestWithBaton, root: str, node: EntityNode, access_controls: Iterable[AccessControl] = None
) -> Iterable[IrodsEntity]:
    """
    TODO
    :param test_with_baton:
    :param root:
    :param node:
    :param access_controls:
    :return:
    """
    entities = []
    setup_helper = SetupHelper(test_with_baton.icommands_location)

    if isinstance(node, DataObjectNode):
        entity = DataObject(setup_helper.create_data_object(node.name))
    else:
        entity = Collection(setup_helper.create_collection(node.name))

    _set_access_controls(test_with_baton, entity.path, access_controls)
    entity.access_controls = access_controls

    new_path = "%s/%s" % (root, entity.get_name())
    setup_helper.run_icommand(["imv", entity.path, new_path])
    entity.path = new_path
    entities.append(entity)

    if isinstance(node, CollectionNode):
        for child in node.children:
            descendants = create_entity_tree(test_with_baton, "%s/%s" % (root, node.name), child, access_controls)
            entities.extend(descendants)

    if isinstance(node, CollectionNode):
        assert len(entities) == len(list(node.get_all_descendants()) + [node])
    else:
        assert len(entities) == 1
    return entities