Пример #1
0
def test_config_to_filter():
    """
    Tests the transformation of a dict-filter config into a tree config
    """
    config = [{"children": True, "path": ["a"]}, {"children": True, "path": []}]
    filter_tree = config_to_tree(config)
    assert filter_tree.get_node(['a']).props['children']
Пример #2
0
def test_filter_tree_filter_root_props(default_root):
    """ See if the props of the root are copied """
    create_binary_tree(default_root, 4)
    filter_config = [{'children': True, 'path': []}]
    filter_tree = config_to_tree(filter_config)
    other = filter_tree_by_path(default_root, filter_tree)
    assert other.props == {'level': 4}
Пример #3
0
def test_filter_tree(default_root):
    """
    Tests an inclusive filter set for root
    """
    create_binary_tree(default_root, 4)
    filter_config = [{'children': False, 'path': []}]
    filter_tree = config_to_tree(filter_config)
    other = filter_tree_by_path(default_root, filter_tree)

    assert default_root.subtree_equals(other)
Пример #4
0
def test_filter_tree_filter(default_root):
    """
    Tests an inclusive filter set for one half of the binary tree
    """
    create_binary_tree(default_root, 4)
    filter_config = [{'children': False, 'path': []}, {'children': False, 'path': ['0']}]
    filter_tree = config_to_tree(filter_config)
    other = filter_tree_by_path(default_root, filter_tree)

    assert not other.has_child('1')
    assert default_root.get_node(['0']).subtree_equals(other.get_node(['0']))
Пример #5
0
def test_filter_tree_filter_root_children(default_root):
    """ The root path still should have [0] as children but nothing below """
    create_binary_tree(default_root, 4)
    filter_config = [{'children': True, 'path': []},
                     {'children': False, 'path': ['1', '0']}]
    filter_tree = config_to_tree(filter_config)
    other = filter_tree_by_path(default_root, filter_tree)

    assert other.has_child('0')
    assert not other.get_node(['0']).has_child('0')
    assert other.get_node(['1']).has_child('1')
    assert not other.get_node(['1', '1']).has_child('1')
    assert other.get_node(['1']).props == {'level': 3}
    assert default_root.get_node(['1', '0']).subtree_equals(other.get_node(['1', '0']))
Пример #6
0
def instantiate_storage(storage_factory,
                        storage_id,
                        config=None,
                        selected_sync_dirs=None,
                        sync_engine=None):
    """Build a new storage instance using the provided `storage_factory` and configuration.

    :param configuration: the base configuration to use.
    :param storage_factory: A subclass of jars.storage
    :param storage_id: id to use for the created storage.
    :type storage_id: str
    :param selected_sync_dirs: directories selected in the selective sync.
    :type selected_sync_dirs: list
    """
    logger.debug('Instantiate storage with id %s', storage_id)

    if selected_sync_dirs is None:
        logger.info("Selective Synchronization is not configured.")
        selected_sync_dirs = []

    # creating reader and writer so storage can update authentication data
    storage_cred_reader = partial(get_credentials_from_config, config,
                                  storage_id)
    storage_cred_writer = partial(store_credentials_in_config, config,
                                  storage_id)

    # defining cache dir for storage
    storage_cache_dir = get_storage_cache_dir(config, storage_id)

    filter_tree = config_to_tree(selected_sync_dirs)
    # register the auto updating filter config signals
    update_func = partial(update_filter_in_config, config, csp_id=storage_id)
    filter_tree.on_update.connect(update_func, weak=False)
    filter_tree.on_delete.connect(update_func, weak=False)
    filter_tree.on_create.connect(update_func, weak=False)

    event_sink = FilterEventSinkWrapper(sync_engine, filter_tree)

    # wrap the syncengine for filtering
    storage_instance = storage_factory(event_sink=event_sink,
                                       storage_id=storage_id,
                                       storage_cache_dir=storage_cache_dir,
                                       storage_cred_reader=storage_cred_reader,
                                       storage_cred_writer=storage_cred_writer)

    storage_instance.filter_tree = filter_tree

    logger.info("Storage Provider '%s' setup!", storage_id)
    return storage_instance
Пример #7
0
def event_sink():
    """
    setup mocked event sink wrapper which is able to monitor function calls
    """
    orig_event_sink = mock.MagicMock()
    orig_event_sink.storage_modify = mock.MagicMock()
    orig_event_sink.storage_create = mock.MagicMock()
    orig_event_sink.storage_delete = mock.MagicMock()
    orig_event_sink.storage_move = mock.MagicMock()

    filters = config_to_tree([{'children': True, 'path': []},
                              {'children': True, 'path': ['a']},
                              {'children': True, 'path': ['a', 'b']}])
    event_sink = FilterEventSinkWrapper(orig_event_sink, filters)
    return event_sink
Пример #8
0
def test_filter_tree_filter_deep(default_root):
    """
    Tests the tree filtering
    """
    create_binary_tree(default_root, 4)
    filter_config = [{'children': False, 'path': ['0']},
                     {'children': False, 'path': ['1', '0']},
                     {'children': False, 'path': ['1']}]
    filter_tree = config_to_tree(filter_config)
    other = filter_tree_by_path(default_root, filter_tree)

    # node ['1', '1'] should not exist since the rule (False, ['1']) excludes that
    assert not other.get_node(['1']).has_child('1')
    assert other.get_node(['1']).props == {'level': 3}
    assert default_root.get_node(['0']).subtree_equals(other.get_node(['0']))
    assert default_root.get_node(['1', '0']).subtree_equals(other.get_node(['1', '0']))