Skip to content

Commit

Permalink
feat(agents-api): add sessions routes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad-mtos committed Jan 2, 2025
1 parent b82e01d commit 7a779db
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 36 deletions.
172 changes: 172 additions & 0 deletions agents-api/tests/test_session_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
from ward import test

from uuid_extensions import uuid7
from tests.fixtures import client, make_request, test_agent, test_session, test_user

from agents_api.autogen.openapi_model import History
@test("route: unauthorized should fail")
def _(client=client):
response = client.request(
method="GET",
url="/sessions",
)

assert response.status_code == 403

@test("route: create session")
def _(make_request=make_request, agent=test_agent):
data = {
"agent": str(agent.id),
"situation": "test session about",
"metadata": {"test": "test"},
"system_template": "test system template",
}

response = make_request(
method="POST",
url="/sessions",
json=data,
)

assert response.status_code == 201

@test("route: create or update session - create")
def _(make_request=make_request, agent=test_agent):
session_id = uuid7()

data = {
"agent": str(agent.id),
"situation": "test session about",
"metadata": {"test": "test"},
"system_template": "test system template",
}

response = make_request(
method="POST",
url=f"/sessions/{session_id}",
json=data,
)

assert response.status_code == 201

@test("route: create or update session - update")
def _(make_request=make_request, session=test_session, agent=test_agent):
data = {
"agent": str(agent.id),
"situation": "test session about",
"metadata": {"test": "test"},
"system_template": "test system template",
}

response = make_request(
method="POST",
url=f"/sessions/{session.id}",
json=data,
)

assert response.status_code == 201, f"{response.json()}"

@test("route: get session - exists")
def _(make_request=make_request, session=test_session):
response = make_request(
method="GET",
url=f"/sessions/{session.id}",
)

assert response.status_code == 200


@test("route: get session - does not exist")
def _(make_request=make_request):
session_id = uuid7()
response = make_request(
method="GET",
url=f"/sessions/{session_id}",
)

assert response.status_code == 404

@test("route: list sessions")
def _(make_request=make_request, session=test_session):
response = make_request(
method="GET",
url="/sessions",
)

assert response.status_code == 200
response = response.json()
sessions = response["items"]

assert isinstance(sessions, list)
assert len(sessions) > 0


@test("route: list sessions with metadata filter")
def _(make_request=make_request, session=test_session):
response = make_request(
method="GET",
url="/sessions",
params={
"metadata_filter": {"test": "test"},
},
)

assert response.status_code == 200
response = response.json()
sessions = response["items"]

assert isinstance(sessions, list)
assert len(sessions) > 0


@test("route: get session history")
def _(make_request=make_request, session=test_session):
response = make_request(
method="GET",
url=f"/sessions/{session.id}/history",
)

assert response.status_code == 200

history = response.json()
assert history["session_id"] == str(session.id)


@test("route: patch session")
def _(make_request=make_request, session=test_session):
data = {
"situation": "test session about",
}

response = make_request(
method="PATCH",
url=f"/sessions/{session.id}",
json=data,
)

assert response.status_code == 200


@test("route: update session")
def _(make_request=make_request, session=test_session):
data = {
"situation": "test session about",
}

response = make_request(
method="PUT",
url=f"/sessions/{session.id}",
json=data,
)

assert response.status_code == 200


@test("route: delete session")
def _(make_request=make_request, session=test_session):
response = make_request(
method="DELETE",
url=f"/sessions/{session.id}",
)

assert response.status_code == 202
36 changes: 0 additions & 36 deletions agents-api/tests/test_sessions.py

This file was deleted.

0 comments on commit 7a779db

Please sign in to comment.