Skip to content

Commit

Permalink
Merge pull request #992 from julep-ai/x/fix-tools-tests
Browse files Browse the repository at this point in the history
fix(agents-api): Fix tools tests
  • Loading branch information
Ahmad-mtos authored Dec 25, 2024
2 parents c37fcfc + 2e96022 commit 6646882
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
19 changes: 5 additions & 14 deletions agents-api/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ async def test_task(dsn=pg_dsn, developer=test_developer, agent=test_agent):
description="test task about",
input_schema={"type": "object", "additionalProperties": True},
main=[{"evaluate": {"hi": "_"}}],
metadata={"test": True},
),
connection_pool=pool,
)
Expand Down Expand Up @@ -344,7 +345,7 @@ async def test_session(
# yield transition


@fixture(scope="global")
@fixture(scope="test")
async def test_tool(
dsn=pg_dsn,
developer_id=test_developer_id,
Expand All @@ -356,7 +357,7 @@ async def test_tool(
"parameters": {"type": "object", "properties": {}},
}

tool = {
tool_spec = {
"function": function,
"name": "hello_world1",
"type": "function",
Expand All @@ -365,20 +366,10 @@ async def test_tool(
[tool, *_] = await create_tools(
developer_id=developer_id,
agent_id=agent.id,
data=[CreateToolRequest(**tool)],
data=[CreateToolRequest(**tool_spec)],
connection_pool=pool,
)
yield tool

# Cleanup
try:
await delete_tool(
developer_id=developer_id,
tool_id=tool.id,
connection_pool=pool,
)
finally:
await pool.close()
return tool


@fixture(scope="global")
Expand Down
14 changes: 9 additions & 5 deletions agents-api/tests/test_task_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ async def _(dsn=pg_dsn, developer_id=test_developer_id, agent=test_agent):


@test("query: list tasks sql - no filters")
async def _(dsn=pg_dsn, developer_id=test_developer_id, agent=test_agent):
async def _(
dsn=pg_dsn, developer_id=test_developer_id, agent=test_agent, task=test_task
):
"""Test that a list of tasks can be successfully retrieved."""

pool = await create_db_pool(dsn=dsn)
Expand All @@ -183,10 +185,12 @@ async def _(dsn=pg_dsn, developer_id=test_developer_id, agent=test_agent):
agent_id=agent.id,
connection_pool=pool,
)
assert result is not None
assert isinstance(result, list)
assert len(result) > 0
assert all(isinstance(task, Task) for task in result)
assert result is not None, "Result is None"
assert isinstance(result, list), f"Result is not a list, got {type(result)}"
assert len(result) > 0, "Result is empty"
assert all(
isinstance(task, Task) for task in result
), "Not all listed tasks are of type Task"


@test("query: update task sql - exists")
Expand Down
11 changes: 7 additions & 4 deletions agents-api/tests/test_tool_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ async def _(
dsn=pg_dsn, developer_id=test_developer_id, tool=test_tool, agent=test_agent
):
pool = await create_db_pool(dsn=dsn)
result = get_tool(
result = await get_tool(
developer_id=developer_id,
agent_id=agent.id,
tool_id=tool.id,
connection_pool=pool,
)

assert result is not None
assert result is not None, "Result is None"


@test("query: list tools")
Expand All @@ -102,8 +102,11 @@ async def _(
connection_pool=pool,
)

assert result is not None
assert all(isinstance(tool, Tool) for tool in result)
assert result is not None, "Result is None"
assert len(result) > 0, "Result is empty"
assert all(
isinstance(tool, Tool) for tool in result
), "Not all listed tools are of type Tool"


@test("query: patch tool")
Expand Down

0 comments on commit 6646882

Please sign in to comment.