Beispiel #1
0
def test_editor_changing_root(task):
    """Setting a new root.

    """
    ed = EditorModel(root=RootTask())
    assert len(ed.nodes) == 1

    ed.root = task
    assert len(ed.nodes) == 3
    assert ('root' in ed.nodes and 'root/comp1' in ed.nodes
            and 'root/comp1/comp2' in ed.nodes)
    assert ed.nodes['root/comp1'] in ed.nodes['root'].children
    assert ed.nodes['root/comp1/comp2'] in ed.nodes['root/comp1'].children
def test_editor_changing_root(task):
    """Setting a new root.

    """
    ed = EditorModel(root=RootTask())
    assert len(ed.nodes) == 1

    ed.root = task
    assert len(ed.nodes) == 3
    assert ('root' in ed.nodes and 'root/comp1' in ed.nodes and
            'root/comp1/comp2' in ed.nodes)
    assert ed.nodes['root/comp1'] in ed.nodes['root'].children
    assert ed.nodes['root/comp1/comp2'] in ed.nodes['root/comp1'].children
Beispiel #3
0
def test_editor_modifying_exception_level(task):
    """Test modifying the level of an access exception.

    """
    ed = EditorModel(root=task)
    rnode = ed.nodes['root']

    node = rnode.children[0].children[0]
    # Check that we can desambiguate between task with same prefix
    node.task.add_child_task(
        0, SimpleTask(name='simp3_t', database_entries={'t': 1}))
    node.add_exception('simp3_t')
    assert 'simp3_t' in node.parent.exceptions
    assert 't' in node.task.children[1].access_exs

    ed.increase_exc_level('root/comp1', 'simp3_t')
    assert 'simp3_t' not in node.parent.exceptions
    assert 'simp3_t' in node.parent.parent.exceptions

    ed.decrease_exc_level('root', 'simp3_t')
    assert 'simp3_t' in node.parent.exceptions
    assert 'simp3_t' not in node.parent.parent.exceptions

    ed.decrease_exc_level('root/comp1', 'simp3_t')
    assert 'simp3_t' not in node.parent.exceptions
    assert 't' not in node.task.children[1].access_exs

    node.parent.add_exception('simp2_t')
    assert 'simp2_t' in node.parent.parent.exceptions
Beispiel #4
0
def test_handling_exceptions_modifications(task):
    """Test handling the possible modifictaion at the level of an exception.

    """
    ed = EditorModel(root=task)

    child = task.children[1].children[1].children[0]
    child.add_access_exception('t', 1)

    assert 'simp3_t' in ed.nodes['root/comp1'].exceptions
    assert 'simp3_t' in ed.nodes['root/comp1/comp2'].has_exceptions

    child.name = 'ss'
    assert 'ss_t' in ed.nodes['root/comp1'].exceptions
    assert 'ss_t' in ed.nodes['root/comp1/comp2'].has_exceptions

    parent = task.children[1]
    parent.name = 'cc'
    assert 'ss_t' in ed.nodes['root/cc'].exceptions
    assert 'ss_t' in ed.nodes['root/cc/comp2'].has_exceptions

    child.remove_access_exception('t')
    assert 'ss_t' not in ed.nodes['root/cc'].exceptions
    assert 'ss_t' not in ed.nodes['root/cc/comp2'].has_exceptions

    # For coverage try removing all exceptions.
    task.database.remove_access_exception('root/cc')
Beispiel #5
0
def test_handling_entry_modification(task):
    """Test handling the possible modifications at the entry level.

    """
    ed = EditorModel(root=task)

    child = task.children[1].children[0]
    entries = child.database_entries.copy()
    entries['t2'] = 1
    child.database_entries = entries

    assert 'simp2_t2' in ed.nodes['root/comp1'].entries

    child = task.children[1].children[1]
    child.name = 'cc'
    assert 'cc_t1' in ed.nodes['root/comp1'].entries
    assert 'cc_t2' in ed.nodes['root/comp1'].entries
    assert 'comp2_t1' not in ed.nodes['root/comp1'].entries
    assert 'comp2_t2' not in ed.nodes['root/comp1'].entries

    child = task.children[1].children[1].children[0]
    child.add_access_exception('t', 2)
    assert 'simp3_t' in ed.nodes['root'].exceptions
    child.database_entries = {}
    assert not ed.nodes['root/comp1/cc'].entries
    assert 'simp2_t' not in ed.nodes['root'].exceptions
def test_editor_modifying_exception_level(task):
    """Test modifying the level of an access exception.

    """
    ed = EditorModel(root=task)
    rnode = ed.nodes['root']

    node = rnode.children[0].children[0]
    # Check that we can desambiguate between task with same prefix
    node.task.add_child_task(0, SimpleTask(name='simp3_t',
                                           database_entries={'t': 1}))
    node.add_exception('simp3_t')
    assert 'simp3_t' in node.parent.exceptions
    assert 't' in node.task.children[1].access_exs

    ed.increase_exc_level('root/comp1', 'simp3_t')
    assert 'simp3_t' not in node.parent.exceptions
    assert 'simp3_t' in node.parent.parent.exceptions

    ed.decrease_exc_level('root', 'simp3_t')
    assert 'simp3_t' in node.parent.exceptions
    assert 'simp3_t' not in node.parent.parent.exceptions

    ed.decrease_exc_level('root/comp1', 'simp3_t')
    assert 'simp3_t' not in node.parent.exceptions
    assert 't' not in node.task.children[1].access_exs

    node.parent.add_exception('simp2_t')
    assert 'simp2_t' in node.parent.parent.exceptions
def test_handling_node_manipulation(task):
    """Test handling manipulation occuring on a node.

    """
    ed = EditorModel(root=task)

    cc = ComplexTask(name='cc')
    task.add_child_task(0, cc)
    assert 'root/cc' in ed.nodes
    assert cc is ed.nodes['root'].children[0].task

    task.remove_child_task(0)
    assert 'root/cc' not in ed.nodes

    # For coverage check that we could handle a list of changes
    ed._react_to_nodes([('', '', '')])

    # Test failing to find a task by path
    with pytest.raises(ValueError):
        ed._get_task('root/unknown')
Beispiel #8
0
def test_node_sorting(task):
    """Test that a node model correctly order its children and react to
    task re-ordering.

    """
    ed = EditorModel(root=task)
    nmodel = ed.nodes['root']
    task.add_child_task(0, ComplexTask(name='cc'))
    nmodel.sort_nodes()
    assert [c.task.name for c in nmodel.children] == ['cc', 'comp1']
    assert sorted(nmodel.entries) == sorted(
        ['default_path', 'simp1_t', 'comp1_t1', 'comp1_t2'])

    task.move_child_task(0, 2)
    assert [c.task.name for c in nmodel.children] == ['comp1', 'cc']
    assert (sorted(nmodel.children[0].entries) == sorted(
        ['simp2_t', 'comp2_t1', 'comp2_t2']))

    change = ContainerChange(collapsed=[ContainerChange()])
    nmodel._react_to_task_children_event(change)  # For coverage
Beispiel #9
0
def test_handling_node_manipulation(task):
    """Test handling manipulation occuring on a node.

    """
    ed = EditorModel(root=task)

    cc = ComplexTask(name='cc')
    task.add_child_task(0, cc)
    assert 'root/cc' in ed.nodes
    assert cc is ed.nodes['root'].children[0].task

    task.remove_child_task(0)
    assert 'root/cc' not in ed.nodes

    # For coverage check that we could handle a list of changes
    ed._react_to_nodes([('', '', '')])

    # Test failing to find a task by path
    with pytest.raises(ValueError):
        ed._get_task('root/unknown')