def test_install_all():
    install_labels(TestAbstractNode)
    # run install all labels
    install_all_labels()
    assert True
    # remove constraint for above test
    db.cypher_query("DROP CONSTRAINT on (n:NoConstraintsSetup) ASSERT n.name IS UNIQUE")
Exemple #2
0
def test_install_all():
    # run install all labels
    install_all_labels()
    assert True
    # remove constraint for above test
    db.cypher_query(
        "DROP CONSTRAINT on (n:NoConstraintsSetup) ASSERT n.name IS UNIQUE")
Exemple #3
0
def test_install_labels_db_property():
    stdout = StringIO()
    install_labels(SomeNotUniqueNode, quiet=False, stdout=stdout)
    assert 'id' in stdout.getvalue()
    # make sure that the id_ constraint doesn't exist
    with pytest.raises(DatabaseError) as exc_info:
        db.cypher_query(
            'DROP CONSTRAINT on (n:SomeNotUniqueNode) ASSERT n.id_ IS UNIQUE')
    assert 'No such constraint' in exc_info.exconly()
    # make sure the id constraint exists and can be removed
    db.cypher_query('DROP CONSTRAINT on (n:SomeNotUniqueNode) ASSERT n.id IS UNIQUE')
def test_install_labels_db_property():
    class SomeNode(StructuredNode):
        id_ = UniqueIdProperty(db_property='id')
    stdout = StringIO()
    install_labels(SomeNode, quiet=False, stdout=stdout)
    assert 'id' in stdout.getvalue()
    # make sure that the id_ constraint doesn't exist
    with pytest.raises(DatabaseError) as exc_info:
        db.cypher_query(
            'DROP CONSTRAINT on (n:SomeNode) ASSERT n.id_ IS UNIQUE')
    assert 'No such constraint' in exc_info.exconly()
    # make sure the id constraint exists and can be removed
    db.cypher_query('DROP CONSTRAINT on (n:SomeNode) ASSERT n.id IS UNIQUE')
def test_drop_labels():
    constraints_before, meta = db.cypher_query("CALL db.constraints()")
    indexes_before, meta = db.cypher_query("CALL db.indexes()")

    assert len(constraints_before) > 0
    assert len(indexes_before) > 0

    remove_all_labels()

    constraints, meta = db.cypher_query("CALL db.constraints()")
    indexes, meta = db.cypher_query("CALL db.indexes()")

    assert len(constraints) == 0
    assert len(indexes) == 0

    # Returning all old constraints and indexes
    for constraint in constraints_before:
        db.cypher_query('CREATE ' + constraint[0])
    for index in indexes_before:
        try:
            db.cypher_query('CREATE ' + index[0])
        except ClientError:
            pass
def test_drop_labels():
    constraints_before, meta = db.cypher_query("CALL db.constraints()")
    indexes_before, meta = db.cypher_query("CALL db.indexes()")

    assert len(constraints_before) > 0
    assert len(indexes_before) > 0

    remove_all_labels()

    constraints, meta = db.cypher_query("CALL db.constraints()")
    indexes, meta = db.cypher_query("CALL db.indexes()")

    assert len(constraints) == 0
    assert len(indexes) == 0

    # Returning all old constraints and indexes
    # Versions prior to 4.0 have a very different return format
    for constraint in constraints_before:
        if constraint[0].startswith("CONSTRAINT "):
            db.cypher_query("CREATE " + constraint[0])
        else:
            db.cypher_query("CREATE " + constraint[1])
    for index in indexes_before:
        try:
            if not isinstance(index[0], int) and index[0].startswith("INDEX "):
                db.cypher_query("CREATE " + index[0])
            else:
                db.cypher_query(
                    "CREATE INDEX {0} FOR (n:{1}) ON (n.{2})".format(
                        index[1], index[7][0], index[8][0]))
        except ClientError:
            pass