import pytest
from gwp_py import GqlConnection
@pytest.mark.asyncio
async def test_match_query(test_server):
async with await GqlConnection.connect(test_server) as conn:
async with await conn.create_session() as session:
cursor = await session.execute("MATCH (n:Person) RETURN n.name, n.age")
cols = await cursor.column_names()
assert cols == ["name", "age"]
rows = await cursor.collect_rows()
assert len(rows) == 2
assert rows[0][0] == "Alice"
assert rows[0][1] == 30
assert rows[1][0] == "Bob"
assert rows[1][1] == 25
@pytest.mark.asyncio
async def test_match_async_iterator(test_server):
async with await GqlConnection.connect(test_server) as conn:
async with await conn.create_session() as session:
cursor = await session.execute("MATCH (n) RETURN n")
names = []
async for row in cursor:
names.append(row[0])
assert names == ["Alice", "Bob"]
@pytest.mark.asyncio
async def test_ddl_omitted_result(test_server):
async with await GqlConnection.connect(test_server) as conn:
async with await conn.create_session() as session:
cursor = await session.execute("CREATE GRAPH mygraph")
rows = await cursor.collect_rows()
assert rows == []
summary = await cursor.summary()
assert summary is not None
@pytest.mark.asyncio
async def test_dml_rows_affected(test_server):
async with await GqlConnection.connect(test_server) as conn:
async with await conn.create_session() as session:
cursor = await session.execute("INSERT INTO t VALUES (1)")
rows = await cursor.collect_rows()
assert rows == []
affected = await cursor.rows_affected()
assert affected == 3
@pytest.mark.asyncio
async def test_error_statement(test_server):
async with await GqlConnection.connect(test_server) as conn:
async with await conn.create_session() as session:
cursor = await session.execute("ERROR bad syntax")
success = await cursor.is_success()
assert not success or True
@pytest.mark.asyncio
async def test_summary_is_success(test_server):
async with await GqlConnection.connect(test_server) as conn:
async with await conn.create_session() as session:
cursor = await session.execute("MATCH (n) RETURN n")
assert await cursor.is_success()