Exemple #1
0
def test_properties():
    assert graph.name == graph_name
    assert repr(graph) == (
        '<ArangoDB graph "{}">'.format(graph_name)
    )
    properties = graph.properties()
    assert properties['id'] == '_graphs/{}'.format(graph_name)
    assert properties['name'] == graph_name
    assert properties['edge_definitions'] == []
    assert properties['orphan_collections'] == []
    assert isinstance(properties['revision'], string_types)
    assert not properties['smart']
    assert 'smart_field' in properties
    assert 'shard_count' in properties

    # Test if exception is raised properly
    with pytest.raises(GraphPropertiesError):
        bad_graph.properties()

    new_graph_name = generate_graph_name()
    new_graph = db.create_graph(
        new_graph_name,
        # TODO only possible with enterprise edition
        # smart=True,
        # smart_field='foo',
        # shard_count=2
    )
    properties = new_graph.properties()
    assert properties['id'] == '_graphs/{}'.format(new_graph_name)
    assert properties['name'] == new_graph_name
    assert properties['edge_definitions'] == []
    assert properties['orphan_collections'] == []
    assert isinstance(properties['revision'], string_types)
Exemple #2
0
def test_create_graph():
    # Test create duplicate graph
    with pytest.raises(GraphCreateError):
        db.create_graph(graph_name)

    new_graph_name = generate_graph_name()
    db.create_graph(new_graph_name)
    assert new_graph_name in [g['name'] for g in db.graphs()]
Exemple #3
0
def test_delete_graph():
    # Test delete graph from the last test
    result = db.delete_graph(graph_name)
    assert result is True
    assert graph_name not in db.graphs()

    # Test delete missing graph
    with pytest.raises(GraphDeleteError):
        db.delete_graph(graph_name)

    # Test delete missing graph (ignore_missing)
    result = db.delete_graph(graph_name, ignore_missing=True)
    assert result is False

    major, minor = arango_version(arango_client)

    if major == 3 and minor >= 1:
        # Create a graph with vertex and edge collections and delete them all
        new_graph_name = generate_graph_name()
        graph = db.create_graph(new_graph_name)
        vcol_name_1 = generate_col_name()
        graph.create_vertex_collection(vcol_name_1)
        vcol_name_2 = generate_col_name()
        graph.create_vertex_collection(vcol_name_2)
        ecol_name = generate_col_name()
        graph.create_edge_definition(name=ecol_name,
                                     from_collections=[vcol_name_1],
                                     to_collections=[vcol_name_2])
        collections = set(col['name'] for col in db.collections())
        assert vcol_name_1 in collections
        assert vcol_name_2 in collections
        assert ecol_name in collections

        db.delete_graph(new_graph_name)
        collections = set(col['name'] for col in db.collections())
        assert vcol_name_1 in collections
        assert vcol_name_2 in collections
        assert ecol_name in collections

        graph = db.create_graph(new_graph_name)
        graph.create_edge_definition(name=ecol_name,
                                     from_collections=[vcol_name_1],
                                     to_collections=[vcol_name_2])
        db.delete_graph(new_graph_name, drop_collections=True)
        collections = set(col['name'] for col in db.collections())
        assert vcol_name_1 not in collections
        assert vcol_name_2 not in collections
        assert ecol_name not in collections
Exemple #4
0
def test_create_graph_with_vertices_ane_edges():
    new_graph_name = generate_graph_name()
    edge_definitions = [
        {
            'name': 'ecol1',
            'from_collections': ['vcol3'],
            'to_collections': ['vcol2']
        }
    ]
    new_graph = db.create_graph(
        new_graph_name,
        edge_definitions=edge_definitions,
        orphan_collections=['vcol1']
    )
    assert new_graph.edge_definitions() == edge_definitions
    assert new_graph.orphan_collections() == ['vcol1']
Exemple #5
0
    ServerTimeError,
    ServerVersionError,
)

from tests.utils import (generate_db_name, generate_col_name,
                         generate_graph_name, arango_version)

arango_client = ArangoClient()
db_name = generate_db_name()
db = arango_client.create_database(db_name)
bad_db_name = generate_db_name()
bad_db = arango_client.db(bad_db_name)
col_name_1 = generate_col_name()
col_name_2 = ''
db.create_collection(col_name_1)
graph_name = generate_graph_name()
db.create_graph(graph_name)


def teardown_module(*_):
    arango_client.delete_database(db_name, ignore_missing=True)


@pytest.mark.order1
def test_properties():
    assert db.name == db_name
    assert repr(db) == '<ArangoDB database "{}">'.format(db_name)

    properties = db.properties()
    assert 'id' in properties
    assert 'path' in properties