Example #1
0
def test_access_exceptions():
    """Test access exceptions.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    assert database.list_accessible_entries('root') == ['val1']

    database.add_access_exception('root', 'root/node1', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val2']
    assert database.get_value('root', 'val2') == 'a'

    database.add_access_exception('root', 'root/node2', 'val3')
    assert database.list_accessible_entries('root') == ['val1', 'val2', 'val3']
    assert database.get_value('root', 'val3') == 2.0

    database.remove_access_exception('root', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val3']

    database.remove_access_exception('root')
    assert database.list_accessible_entries('root') == ['val1']
Example #2
0
def test_access_exceptions():
    """Test access exceptions.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    assert database.list_accessible_entries('root') == ['val1']

    database.add_access_exception('root', 'root/node1', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val2']
    assert database.get_value('root', 'val2') == 'a'

    database.add_access_exception('root', 'root/node2', 'val3')
    assert database.list_accessible_entries('root') == ['val1', 'val2', 'val3']
    assert database.get_value('root', 'val3') == 2.0

    database.remove_access_exception('root', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val3']

    database.remove_access_exception('root')
    assert database.list_accessible_entries('root') == ['val1']
Example #3
0
def test_access_exceptions_renaming_values():
    """Test renaming values linked to an access ex.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val1', 2.0)

    database.add_access_exception('root', 'root/node1', 'val1')
    database.rename_values('root/node1', ['val1'], ['new_val'], {'val1': 1})
    assert database.get_value('root', 'new_val') == 2.0
Example #4
0
def test_access_exceptions_renaming_values():
    """Test renaming values linked to an access ex.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val1', 2.0)

    database.add_access_exception('root', 'root/node1', 'val1')
    database.rename_values('root/node1', ['val1'], ['new_val'], {'val1': 1})
    assert database.get_value('root', 'new_val') == 2.0
Example #5
0
def test_get_set_on_flat_database2():
    """Test get/set operations on flat database using names when an access ex
    exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_for_running()
    assert not database.set_value('root', 'val2', 2)
    assert database.get_value('root', 'val2') == 2
Example #6
0
def test_get_set_on_flat_database2():
    """Test get/set operations on flat database using names when an access ex
    exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_to_run()
    assert not database.set_value('root', 'val2', 2)
    assert database.get_value('root', 'val2') == 2
Example #7
0
def test_index_op_on_flat_database2():
    """Test operation on flat database relying on indexes when a simple access
    ex exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_for_running()
    assert database.get_entries_indexes('root', ['val1']) == {'val1': 0}
    assert database.get_entries_indexes('root', ['val1', 'val2']) == \
        {'val1': 0, 'val2': 1}
Example #8
0
def test_index_op_on_flat_database2():
    """Test operation on flat database relying on indexes when a simple access
    ex exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_to_run()
    assert database.get_entries_indexes('root', ['val1']) == {'val1': 0}
    assert database.get_entries_indexes('root', ['val1', 'val2']) == \
        {'val1': 0, 'val2': 1}
Example #9
0
def test_access_exceptions_renaming_node():
    """Test renaming a node holding an access exception.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.set_value('root/node1/node2', 'val1', 2.0)

    database.add_access_exception('root', 'root/node1/node2', 'val1')
    assert database.get_value('root', 'val1') == 2.0

    database.rename_node('root/node1', 'node2', 'node22')
    assert database.get_value('root', 'val1') == 2.0

    database.rename_node('root', 'node1', 'node11')
    assert database.get_value('root', 'val1') == 2.0
Example #10
0
def test_access_exceptions_renaming_node():
    """Test renaming a node holding an access exception.

    The relative path is exactly the name of the renamed node.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.set_value('root/node1/node2', 'val1', 2.0)

    database.add_access_exception('root/node1', 'root/node1/node2', 'val1')
    assert database.get_value('root/node1', 'val1') == 2.0

    database.rename_node('root/node1', 'node2', 'node22')
    assert database.get_value('root/node1', 'val1') == 2.0

    database.rename_node('root', 'node1', 'node11')
    assert database.get_value('root/node11', 'val1') == 2.0