Skip to content

Commit

Permalink
fix: test cases for sql pair and deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
paopa committed Jan 9, 2025
1 parent b85d046 commit 3a1e566
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
14 changes: 14 additions & 0 deletions wren-ai-service/tests/data/pairs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"test": [
{
"id": "1",
"question": "What is the book?",
"sql": "SELECT * FROM book"
},
{
"id": "2",
"question": "What is the author?",
"sql": "SELECT * FROM author"
}
]
}
25 changes: 10 additions & 15 deletions wren-ai-service/tests/pytest/pipelines/indexing/test_sql_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from src.config import settings
from src.core.provider import DocumentStoreProvider
from src.pipelines.indexing.sql_pairs import SqlPair, SqlPairs
from src.pipelines.indexing import SqlPairs
from src.providers import generate_components


Expand All @@ -17,12 +17,11 @@ async def test_sql_pairs_indexing_saving_to_document_store():
recreate_index=True,
)

sql_pairs = SqlPairs(**pipe_components["sql_pairs_indexing"])
sql_pairs = SqlPairs(
**pipe_components["sql_pairs_indexing"], sql_pairs_path="tests/data/pairs.json"
)
await sql_pairs.run(
sql_pairs=[
SqlPair(sql="SELECT * FROM book", id="1", question="What is the book?"),
SqlPair(sql="SELECT * FROM author", id="2", question="What is the author?"),
],
mdl_str='{"models": [{"properties": {"boilerplate": "test"}}]}',
project_id="fake-id",
)

Expand All @@ -46,20 +45,16 @@ async def test_sql_pairs_preparation_saving_to_document_store_with_multiple_proj
recreate_index=True,
)

sql_pairs = SqlPairs(**pipe_components["sql_pairs_indexing"])
sql_pairs = SqlPairs(
**pipe_components["sql_pairs_indexing"], sql_pairs_path="tests/data/pairs.json"
)
await sql_pairs.run(
sql_pairs=[
SqlPair(sql="SELECT * FROM book", id="1", question="What is the book?"),
SqlPair(sql="SELECT * FROM author", id="2", question="What is the author?"),
],
mdl_str='{"models": [{"properties": {"boilerplate": "test"}}]}',
project_id="fake-id",
)

await sql_pairs.run(
sql_pairs=[
SqlPair(sql="SELECT * FROM book", id="1", question="What is the book?"),
SqlPair(sql="SELECT * FROM author", id="2", question="What is the author?"),
],
mdl_str='{"models": [{"properties": {"boilerplate": "test"}}]}',
project_id="fake-id-2",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from src.config import settings
from src.core.provider import DocumentStoreProvider
from src.pipelines.indexing.sql_pairs import SqlPair, SqlPairs
from src.pipelines.indexing.sql_pairs_deletion import SqlPairsDeletion
from src.pipelines.indexing import SqlPairs, SqlPairsDeletion
from src.providers import generate_components


Expand All @@ -18,23 +17,17 @@ async def test_sql_pairs_deletion():
recreate_index=True,
)

sql_pairs = [
SqlPair(sql="SELECT * FROM book", id="1", question="What is the book?"),
SqlPair(sql="SELECT * FROM author", id="2", question="What is the author?"),
]
sql_pairs = SqlPairs(**pipe_components["sql_pairs_indexing"])
sql_pairs = SqlPairs(
**pipe_components["sql_pairs_indexing"], sql_pairs_path="tests/data/pairs.json"
)
await sql_pairs.run(
sql_pairs=sql_pairs,
mdl_str='{"models": [{"properties": {"boilerplate": "test"}}]}',
project_id="fake-id",
)

sql_pairs_deletion = SqlPairsDeletion(**pipe_components["sql_pairs_deletion"])
await sql_pairs_deletion.run(
id="fake-id-2", sql_pair_ids=[sql_pair.id for sql_pair in sql_pairs]
)
await sql_pairs_deletion.run(id="fake-id-2", sql_pair_ids=["1", "2"])
assert await store.count_documents() == 2

await sql_pairs_deletion.run(
id="fake-id", sql_pair_ids=[sql_pair.id for sql_pair in sql_pairs]
)
await sql_pairs_deletion.run(id="fake-id", sql_pair_ids=["1", "2"])
assert await store.count_documents() == 0

0 comments on commit 3a1e566

Please sign in to comment.