DB-GPT/tests/intetration_tests/datasource/test_conn_tugraph.py
M1n9X 759f7d99cc
feat(GraphRAG): enhance GraphRAG by graph community summary (#1801)
Co-authored-by: Florian <fanzhidongyzby@163.com>
Co-authored-by: KingSkyLi <15566300566@163.com>
Co-authored-by: aries_ckt <916701291@qq.com>
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
Co-authored-by: yvonneyx <zhuyuxin0627@gmail.com>
2024-08-30 21:59:44 +08:00

55 lines
1.6 KiB
Python

import pytest
from dbgpt.datasource.conn_tugraph import TuGraphConnector
# Set database connection parameters.
HOST = "localhost"
PORT = 7687
USER = "admin"
PWD = "73@TuGraph"
DB_NAME = "default"
@pytest.fixture(scope="session")
def connector():
"""Create a TuGraphConnector for the entire test session."""
# Initialize connection.
connector = TuGraphConnector.from_uri_db(HOST, PORT, USER, PWD, DB_NAME)
yield connector
# Close the connection after all tests are completed.
connector.close()
def test_get_table_names(connector):
"""Test retrieving table names from the graph database."""
table_names = connector.get_table_names()
# Verify the quantity of vertex and edge tables.
assert len(table_names["vertex_tables"]) == 5
assert len(table_names["edge_tables"]) == 8
def test_get_columns(connector):
"""Test retrieving columns for a specific table."""
# Get column information of the vertex table named 'person'.
columns = connector.get_columns("person", "vertex")
assert len(columns) == 4
assert any(col["name"] == "id" for col in columns)
def test_get_indexes(connector):
"""Test retrieving indexes for a specific table."""
# Get the index information of the vertex table named 'person'.
indexes = connector.get_indexes("person", "vertex")
assert len(indexes) > 0
def test_run_without_stream(connector):
query = "MATCH (n) RETURN n limit 10"
result = connector.run(query)
assert len(result) == 10
def test_run_with_stream(connector):
query = "MATCH (n) RETURN n limit 10"
result = list(connector.run_stream(query))
assert len(result) == 10