示例#1
0
def test_replace_vertex():
    vcol = graph.vertex_collection('vcol1')

    # Test preconditions
    assert 'bar' in vcol.get('1')
    assert 'value' in vcol.get('1')

    # Test replace vertex with a single field change
    result = vcol.replace({'_key': '1', 'baz': 100})
    assert result['_id'] == 'vcol1/1'
    assert result['_key'] == '1'
    assert 'foo' not in vcol['1']
    assert 'bar' not in vcol['1']
    assert vcol['1']['baz'] == 100
    old_rev = result['_rev']

    # Test replace vertex with multiple field changes
    vertex = {'_key': '1', 'foo': 200, 'bar': 300}
    result = vcol.replace(vertex)
    assert result['_id'] == 'vcol1/1'
    assert result['_key'] == '1'
    assert result['_old_rev'] == old_rev
    assert clean_keys(vcol['1']) == vertex
    old_rev = result['_rev']

    # Test replace vertex with correct revision
    vertex = {'_key': '1', '_rev': old_rev, 'bar': 500}
    result = vcol.replace(vertex)
    assert result['_id'] == 'vcol1/1'
    assert result['_key'] == '1'
    assert result['_old_rev'] == old_rev
    assert clean_keys(vcol['1']) == clean_keys(vertex)
    old_rev = result['_rev']

    # Test replace vertex with incorrect revision
    new_rev = old_rev + '10'
    vertex = {'_key': '1', '_rev': new_rev, 'bar': 600}
    with pytest.raises(DocumentRevisionError):
        vcol.replace(vertex)
    assert vcol['1']['bar'] == 500
    assert 'foo' not in vcol['1']

    # Test replace vertex in missing vertex collection
    with pytest.raises(DocumentReplaceError):
        bad_vcol.replace({'_key': '1', 'bar': 600})
    assert vcol['1']['bar'] == 500
    assert 'foo' not in vcol['1']

    # Test replace vertex with sync option
    vertex = {'_key': '1', 'bar': 400, 'foo': 200}
    result = vcol.replace(vertex, sync=True)
    assert result['_id'] == 'vcol1/1'
    assert result['_key'] == '1'
    assert result['_old_rev'] == old_rev
    assert vcol['1']['foo'] == 200
    assert vcol['1']['bar'] == 400
示例#2
0
def test_write_cursor_first():
    assert clean_keys(cursor.next()) == doc1
    assert cursor.id == cursor_id
    assert cursor.has_more() is True
    assert cursor.cached() is False
    assert cursor.statistics()['modified'] == 2
    assert cursor.statistics()['filtered'] == 0
    assert cursor.statistics()['ignored'] == 0
    assert cursor.statistics()['scanned_full'] == 0
    assert cursor.statistics()['scanned_index'] == 2
    assert cursor.warnings() == []
    assert cursor.count() == 2
    assert clean_keys(cursor.batch()) == []
    assert isinstance(cursor.statistics()['execution_time'], (int, float))
示例#3
0
def test_read_cursor_third():
    clean_keys(cursor.next()) == doc3
    assert cursor.id is None
    assert cursor.has_more() is False
    assert cursor.cached() is False
    assert cursor.statistics()['modified'] == 0
    assert cursor.statistics()['filtered'] == 0
    assert cursor.statistics()['ignored'] == 0
    assert cursor.statistics()['scanned_full'] == 4
    assert cursor.statistics()['scanned_index'] == 0
    assert cursor.warnings() == []
    assert cursor.count() == 4
    assert clean_keys(cursor.batch()) == [doc3]
    assert isinstance(cursor.statistics()['execution_time'], (int, float))
示例#4
0
def test_write_cursor_init():
    global cursor, cursor_id
    col.truncate()
    col.import_bulk([doc1, doc2, doc3])
    cursor = db.aql.execute('''
        FOR d IN {col} FILTER d._key == @first OR d._key == @second
        UPDATE {{_key: d._key, _val: @val }} IN {col}
        RETURN NEW
        '''.format(col=col_name),
                            bind_vars={
                                'first': '1',
                                'second': '2',
                                'val': 42
                            },
                            count=True,
                            batch_size=1,
                            ttl=1000,
                            optimizer_rules=['+all'])
    cursor_id = cursor.id
    assert cursor.has_more() is True
    assert cursor.cached() is False
    assert cursor.statistics()['modified'] == 2
    assert cursor.statistics()['filtered'] == 0
    assert cursor.statistics()['ignored'] == 0
    assert cursor.statistics()['scanned_full'] == 0
    assert cursor.statistics()['scanned_index'] == 2
    assert cursor.warnings() == []
    assert cursor.count() == 2
    assert clean_keys(cursor.batch()) == [doc1]
    assert isinstance(cursor.statistics()['execution_time'], (int, float))
示例#5
0
def test_get_vertex():
    vcol = graph.vertex_collection('vcol1')

    # Test get missing vertex
    assert vcol.get('0') is None

    # Test get existing vertex
    result = vcol.get('1')
    old_rev = result['_rev']
    assert clean_keys(result) == {'_key': '1', 'value': 1}

    # Test get existing vertex with wrong revision
    with pytest.raises(ArangoError):
        vcol.get('1', rev=old_rev + '1')

    # Test get existing vertex from missing vertex collection
    with pytest.raises(DocumentGetError):
        bad_vcol.get('1')

    # Test get existing vertex again
    assert clean_keys(vcol.get('2')) == {'_key': '2', 'value': 2}
示例#6
0
def test_get_edge():
    ecol = graph.edge_collection('ecol2')
    ecol.truncate()
    for edge in [edge1, edge2, edge4]:
        ecol.insert(edge)

    # Test get missing edge
    assert ecol.get('0') is None

    # Test get existing edge
    result = ecol.get('1')
    old_rev = result['_rev']
    assert clean_keys(result) == edge1

    # Test get existing edge with wrong revision
    with pytest.raises(DocumentRevisionError):
        ecol.get('1', rev=old_rev + '1')

    # Test get existing edge from missing edge collection
    with pytest.raises(DocumentGetError):
        bad_ecol.get('1')

    # Test get existing edge again
    assert clean_keys(ecol.get('2')) == edge2
示例#7
0
def test_cursor_context_manager():
    global cursor, cursor_id

    col.truncate()
    col.import_bulk([doc1, doc2, doc3])

    with db.aql.execute('FOR d IN {} RETURN d'.format(col_name),
                        count=False,
                        batch_size=2,
                        ttl=1000,
                        optimizer_rules=['+all']) as cursor:
        assert clean_keys(cursor.next()) == doc1
    with pytest.raises(CursorCloseError):
        cursor.close(ignore_missing=False)

    with db.aql.execute('FOR d IN {} RETURN d'.format(col_name),
                        count=False,
                        batch_size=2,
                        ttl=1000,
                        optimizer_rules=['+all']) as cursor:
        assert clean_keys(cursor.__next__()) == doc1
    with pytest.raises(CursorCloseError):
        cursor.close(ignore_missing=False)
    assert cursor.close(ignore_missing=True) is False
示例#8
0
def test_write_cursor_second():
    clean_keys(cursor.next()) == doc2
    assert cursor.id is None
    assert cursor.has_more() is False
    assert cursor.cached() is False
    assert cursor.statistics()['modified'] == 2
    assert cursor.statistics()['filtered'] == 0
    assert cursor.statistics()['ignored'] == 0
    assert cursor.statistics()['scanned_full'] == 0
    assert cursor.statistics()['scanned_index'] == 2
    assert cursor.warnings() == []
    assert cursor.count() == 2
    assert clean_keys(cursor.batch()) == []
    assert isinstance(cursor.statistics()['execution_time'], (int, float))
    with pytest.raises(StopIteration):
        cursor.next()
    assert cursor.close(ignore_missing=True) is False

    incorrect_cursor_data = {'id': 'invalid', 'hasMore': True, 'result': []}
    setattr(cursor, '_data', incorrect_cursor_data)
    with pytest.raises(CursorCloseError):
        cursor.close(ignore_missing=False)
    with pytest.raises(CursorNextError):
        cursor.next()
示例#9
0
def test_read_cursor_early_finish():
    global cursor, cursor_id

    col.truncate()
    col.import_bulk([doc1, doc2, doc3, doc4])
    cursor = db.aql.execute('FOR d IN {} RETURN d'.format(col_name),
                            count=True,
                            batch_size=2,
                            ttl=1000,
                            optimizer_rules=['+all'])
    assert cursor.close() is True
    with pytest.raises(CursorCloseError):
        cursor.close(ignore_missing=False)

    assert clean_keys(cursor.batch()) == [doc1, doc2]
示例#10
0
def test_read_cursor_init():
    global cursor, cursor_id

    col.import_bulk([doc1, doc2, doc3, doc4])
    cursor = db.aql.execute('FOR d IN {} RETURN d'.format(col_name),
                            count=True,
                            batch_size=2,
                            ttl=1000,
                            optimizer_rules=['+all'])
    cursor_id = cursor.id
    assert 'ArangoDB cursor' in repr(cursor)
    assert cursor.has_more() is True
    assert cursor.cached() is False
    assert cursor.statistics()['modified'] == 0
    assert cursor.statistics()['filtered'] == 0
    assert cursor.statistics()['ignored'] == 0
    assert cursor.statistics()['scanned_full'] == 4
    assert cursor.statistics()['scanned_index'] == 0
    assert cursor.warnings() == []
    assert cursor.count() == 4
    assert clean_keys(cursor.batch()) == [doc1, doc2]
    assert isinstance(cursor.statistics()['execution_time'], (int, float))