예제 #1
0
def storage_model_with_files():
    """ Creates simple storage model for testing.
    Tree:
    child_1
        child_1_1
            child_1_1_1
        child_1_2
    child_2
        child_2_1
    """
    storage_model = Node(name=None)

    def create_props(size, is_dir):
        if is_dir:
            version_id = IS_DIR
        else:
            version_id = 1
        return {
            MODIFIED_DATE: dt.datetime.now(),
            SIZE: size,
            IS_DIR: is_dir,
            VERSION_ID: version_id
        }

    child_1 = storage_model.add_child(name='child_1',
                                      props=create_props(0, True))
    child_2 = storage_model.add_child(name='child_2',
                                      props=create_props(0, True))
    child_1_1 = child_1.add_child(name='child_1_1',
                                  props=create_props(MBYTE, False))
    child_1.add_child(name='child_1_2', props=create_props(MBYTE, False))
    child_2.add_child(name='child_2_1', props=create_props(MBYTE, False))
    child_1_1.add_child(name='child_1_1_1', props=create_props(MBYTE, False))

    return storage_model
예제 #2
0
def test_has_child():
    '''
    Tests has child function.
    '''
    root_node = Node(name=None)
    assert not root_node.has_child('test')

    root_node.add_child('test')
    assert root_node.has_child('test')
예제 #3
0
def test_set_operations():
    """
    check if the set operations are only effected by the path
    """
    root_node1 = Node(name=None)
    root_node2 = Node(name=None)
    root_node1.add_child("that child")
    child2 = root_node2.add_child("that child")
    child3 = child2.add_child("Hulla")

    assert {child3} == set(root_node2) - set(root_node1)

    child2.props = {'hola': 'drio'}
    assert {child3} == set(root_node2) - set(root_node1)
예제 #4
0
def test_hash_function():
    """
    check if the hash function is only effected by the path
    :return: None
    """
    root_node1 = Node(name=None)
    root_node2 = Node(name=None)
    assert hash(root_node1) == hash(root_node2)

    child1 = root_node1.add_child("that child")
    assert hash(child1) != hash(root_node1)

    child2 = root_node2.add_child("that child")
    assert hash(child1) == hash(child2)

    child3 = child2.add_child("Hulla")
    assert hash(child3) != hash(child2)
예제 #5
0
def test_delete_delete():
    """
    Tests if 2 consequent delete on the same child will not raise exceptions
    """
    root_node = Node(name=None)
    child = root_node.add_child('test')

    child.delete()
    child.delete()
예제 #6
0
def test_iter_up():
    """
    Tests the
    """
    root = Node(name=None)
    assert list(root.iter_up) == [root]

    child1 = root.add_child('test')
    assert list(child1.iter_up) == [child1, root]

    child2 = child1.add_child('test')
    assert list(child2.iter_up) == [child2, child1, root]
예제 #7
0
def test_iter_up_existing():
    """
    Tests the iter_up_existing generator
    """
    root = Node(name=None)
    assert list(root.iter_up_existing(['node'])) == [root]
    assert list(root.iter_up_existing(['node', 'bla', 'foo'])) == [root]

    child1 = root.add_child('test')
    assert list(root.iter_up_existing(['test', 'node'])) == [child1, root]
    assert list(child1.iter_up_existing(['node'])) == [child1]

    child2 = child1.add_child('test')
    assert list(root.iter_up_existing(['test', 'test',
                                       'node'])) == [child2, child1, root]
    assert list(child1.iter_up_existing(['test', 'node'])) == [child2, child1]
    assert list(child2.iter_up_existing(['node'])) == [child2]
def test_get_storage_path():
    """
    creates a small tree and sees if sync-rule inheritance works
    """
    root = Node(name=None)

    child1 = root.add_child('child1')
    metrics = child1.props.setdefault(STORAGE,
                                      {}).setdefault(FILESYSTEM_ID, {})
    metrics[DISPLAY_NAME] = "CHILD1"

    metrics = child1.props.setdefault(STORAGE,
                                      {}).setdefault(CSP_1.storage_id, {})
    metrics[DISPLAY_NAME] = "Child1"

    child2 = child1.add_child('child2')
    metrics = child2.props.setdefault(STORAGE,
                                      {}).setdefault(CSP_1.storage_id, {})
    metrics[DISPLAY_NAME] = "Child2"

    path = get_storage_path(child2, FILESYSTEM_ID, CSP_1.storage_id)
    assert ["CHILD1", "Child2"] == path
예제 #9
0
def test_node_equals_recursive():
    """
    Compares two nodes and their children
    :return:
    """

    node1 = Node(name="aaaa", props={"a": "b", "c": "d"})
    node2 = Node(name="aaaa", props={"a": "b", "c": "d"})

    node1.add_child("bbbb", props={"a": "b", "c": "d"})
    node2.add_child("aaaa", props={"a": "b", "c": "e"})

    assert node1.subtree_equals(node2) is False

    node3 = Node(name="aaaa", props={"a": "b", "c": "d"})
    node4 = Node(name="aaaa", props={"a": "b", "c": "d"})

    node3.add_child("bbbb", props={"a": "b", "c": "d"})
    node41 = node4.add_child("bbbb", props={"a": "b", "c": "d"})

    assert node3.subtree_equals(node4)
    assert not node3.subtree_equals(node41)