-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for docs routes in `agents-api/tests/test_docs_routes.py`. * **Create Docs Tests** - Add test for creating user doc. - Add test for creating agent doc. * **Delete Doc Test** - Add test for deleting a doc. * **Get Doc Test** - Add test for getting a doc. * **List Docs Tests** - Add test for listing user docs. - Add test for listing agent docs. * **Search Docs Tests** - Add test for searching user docs. - Add test for searching agent docs. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/julep-ai/julep?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
1 changed file
with
179 additions
and
0 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,179 @@ | ||
from uuid import uuid4 | ||
|
||
from ward import test | ||
|
||
from agents_api.autogen.openapi_model import CreateDocRequest, TextOnlyDocSearchRequest | ||
from tests.fixtures import make_request, test_agent, test_user | ||
|
||
|
||
@test("route: create user doc") | ||
def _(make_request=make_request, user=test_user): | ||
data = dict( | ||
title="Test User Doc", | ||
content=["This is a test user document."], | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/users/{user.id}/docs", | ||
json=data, | ||
) | ||
|
||
assert response.status_code == 201 | ||
|
||
|
||
@test("route: create agent doc") | ||
def _(make_request=make_request, agent=test_agent): | ||
data = dict( | ||
title="Test Agent Doc", | ||
content=["This is a test agent document."], | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/agents/{agent.id}/docs", | ||
json=data, | ||
) | ||
|
||
assert response.status_code == 201 | ||
|
||
|
||
@test("route: delete doc") | ||
def _(make_request=make_request, agent=test_agent): | ||
data = dict( | ||
title="Test Agent Doc", | ||
content=["This is a test agent document."], | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/agents/{agent.id}/docs", | ||
json=data, | ||
) | ||
doc_id = response.json()["id"] | ||
|
||
response = make_request( | ||
method="DELETE", | ||
url=f"/docs/{doc_id}", | ||
) | ||
|
||
assert response.status_code == 202 | ||
|
||
response = make_request( | ||
method="GET", | ||
url=f"/docs/{doc_id}", | ||
) | ||
|
||
assert response.status_code == 404 | ||
|
||
|
||
@test("route: get doc") | ||
def _(make_request=make_request, agent=test_agent): | ||
data = dict( | ||
title="Test Agent Doc", | ||
content=["This is a test agent document."], | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/agents/{agent.id}/docs", | ||
json=data, | ||
) | ||
doc_id = response.json()["id"] | ||
|
||
response = make_request( | ||
method="GET", | ||
url=f"/docs/{doc_id}", | ||
) | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
@test("route: list user docs") | ||
def _(make_request=make_request, user=test_user): | ||
response = make_request( | ||
method="GET", | ||
url=f"/users/{user.id}/docs", | ||
) | ||
|
||
assert response.status_code == 200 | ||
response = response.json() | ||
docs = response["items"] | ||
|
||
assert isinstance(docs, list) | ||
|
||
|
||
@test("route: list agent docs") | ||
def _(make_request=make_request, agent=test_agent): | ||
response = make_request( | ||
method="GET", | ||
url=f"/agents/{agent.id}/docs", | ||
) | ||
|
||
assert response.status_code == 200 | ||
response = response.json() | ||
docs = response["items"] | ||
|
||
assert isinstance(docs, list) | ||
|
||
|
||
@test("route: search user docs") | ||
def _(make_request=make_request, user=test_user): | ||
data = dict( | ||
title="Test User Doc", | ||
content=["This is a test user document."], | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/users/{user.id}/docs", | ||
json=data, | ||
) | ||
|
||
search_params = TextOnlyDocSearchRequest( | ||
text="test", | ||
limit=1, | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/users/{user.id}/search", | ||
json=search_params.dict(), | ||
) | ||
|
||
assert response.status_code == 200 | ||
response = response.json() | ||
docs = response["docs"] | ||
|
||
assert isinstance(docs, list) | ||
|
||
|
||
@test("route: search agent docs") | ||
def _(make_request=make_request, agent=test_agent): | ||
data = dict( | ||
title="Test Agent Doc", | ||
content=["This is a test agent document."], | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/agents/{agent.id}/docs", | ||
json=data, | ||
) | ||
|
||
search_params = TextOnlyDocSearchRequest( | ||
text="test", | ||
limit=1, | ||
) | ||
|
||
response = make_request( | ||
method="POST", | ||
url=f"/agents/{agent.id}/search", | ||
json=search_params.dict(), | ||
) | ||
|
||
assert response.status_code == 200 | ||
response = response.json() | ||
docs = response["docs"] | ||
|
||
assert isinstance(docs, list) |