コード例 #1
0
def test_autocommit_transactions_should_support_timeout(neo4j_driver):
    with neo4j_driver.session() as s1:
        s1.run("CREATE (a:Node)").consume()
        with neo4j_driver.session() as s2:
            tx1 = s1.begin_transaction()
            tx1.run("MATCH (a:Node) SET a.property = 1").consume()
            with pytest.raises(TransientError):
                s2.run(Query("MATCH (a:Node) SET a.property = 2",
                             timeout=0.25)).consume()
コード例 #2
0
def test_autocommit_transactions_should_support_timeout(neo4j_driver):
    with neo4j_driver.session() as s1:
        s1.run("CREATE (a:Node)").consume()
        with neo4j_driver.session() as s2:
            tx1 = s1.begin_transaction()
            tx1.run("MATCH (a:Node) SET a.property = 1").consume()
            try:
                result = s2.run(
                    Query("MATCH (a:Node) SET a.property = 2", timeout=0.25))
                result.consume()
            # On 4.0 and older
            except TransientError:
                pass
            # On 4.1 and forward
            except ClientError:
                pass
            else:
                raise
コード例 #3
0
def test_autocommit_transactions_should_support_metadata(
        session, test_input, neo4j_version):
    # python -m pytest tests/integration/test_autocommit.py -s -r fEsxX -k test_autocommit_transactions_should_support_metadata
    metadata_in = {"foo": "bar"}

    result = session.run("RETURN 1")
    value = result.single().value()
    summary = result.consume()
    server_agent = summary.server.agent

    try:
        statement = Query(test_input, metadata=metadata_in)
        result = session.run(statement)
        metadata_out = result.single().value()
    except ClientError as e:
        if e.code == "Neo.ClientError.Procedure.ProcedureNotFound":
            pytest.skip(
                "Cannot assert correct metadata as {} does not support procedure '{}' introduced in Neo4j {}"
                .format(server_agent, test_input, neo4j_version))
        else:
            raise
    else:
        assert metadata_in == metadata_out
コード例 #4
0
def test_statement_object_not_supported(session):
    with session.begin_transaction() as tx:
        with pytest.raises(ValueError):
            tx.run(Query("RETURN 1", timeout=0.25))
コード例 #5
0
def test_result_single_record_value(session):
    record = session.run(Query("RETURN $x"), x=1).single()
    assert record.value() == 1
 def add_person_within_a_second(self, name):
     with self.driver.session() as session:
         session.run(Query("CREATE (a:Person {name: $name})", timeout=1.0),
                     name=name)
コード例 #7
0
def test_statement_object(session):
    value = session.run(Query("RETURN $x"), x=1).single().value()
    assert value == 1
コード例 #8
0
def to_query_and_params(data):
    cypher, param = to_cypher_and_params(data)
    metadata, timeout = to_meta_and_timeout(data)
    query = Query(cypher, metadata=metadata, timeout=timeout)
    return query, param