-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agents-api): add sessions routes tests
- Loading branch information
1 parent
b82e01d
commit 7a779db
Showing
2 changed files
with
172 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.