|
|
import requests |
|
|
import time |
|
|
|
|
|
BASE_URL = "http://127.0.0.1:8000" |
|
|
|
|
|
|
|
|
headers = {} |
|
|
convo_id = None |
|
|
|
|
|
def test_register_and_login(): |
|
|
print("\nπ Testing Registration and Login") |
|
|
reg_data = { |
|
|
"username": "testuser", |
|
|
"password": "testpass" |
|
|
} |
|
|
|
|
|
res = requests.post(f"{BASE_URL}/auth/register", json=reg_data) |
|
|
if res.status_code == 400: |
|
|
print("β
Already registered, skipping register.") |
|
|
elif res.ok: |
|
|
print("β
Registered new user.") |
|
|
else: |
|
|
print("β Register failed:", res.text) |
|
|
|
|
|
res = requests.post(f"{BASE_URL}/auth/login", json={ |
|
|
"username": "testuser", |
|
|
"password": "testpass" |
|
|
}) |
|
|
assert res.ok, "β Login failed" |
|
|
token = res.json()["access_token"] |
|
|
global headers |
|
|
headers = {"Authorization": f"Bearer {token}"} |
|
|
print("β
Logged in and got token") |
|
|
|
|
|
def test_create_conversation(): |
|
|
print("\n㪠Testing Conversation Creation") |
|
|
res = requests.post(f"{BASE_URL}/conversations/", json={}, headers=headers) |
|
|
assert res.ok, "β Failed to create conversation" |
|
|
global convo_id |
|
|
convo_id = res.json()["id"] |
|
|
print(f"β
Created conversation with ID {convo_id}") |
|
|
|
|
|
def test_get_conversation(): |
|
|
print("\nπ Testing Fetch Conversation") |
|
|
res = requests.get(f"{BASE_URL}/conversations/{convo_id}", headers=headers) |
|
|
assert res.ok, "β Failed to get conversation" |
|
|
print("β
Retrieved conversation with messages") |
|
|
|
|
|
def test_agent_flow(): |
|
|
print("\nπ€ Testing Agent Interaction") |
|
|
|
|
|
|
|
|
res = requests.post(f"{BASE_URL}/agent/{convo_id}/message", json={"content": "Kiran Parthiban"}, headers=headers) |
|
|
assert res.ok, "β Agent message failed (1)" |
|
|
print("β
Sent user message (1):", res.json()["content"]) |
|
|
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
res = requests.post(f"{BASE_URL}/agent/{convo_id}/message", json={"content": "123 Main Street, Toronto"}, headers=headers) |
|
|
assert res.ok, "β Agent message failed (2)" |
|
|
print("β
Sent user message (2):", res.json()["content"]) |
|
|
|
|
|
|
|
|
fields = ["test@example.com", "1234567890", "2025-07-09"] |
|
|
for i, field in enumerate(fields, start=3): |
|
|
res = requests.post(f"{BASE_URL}/agent/{convo_id}/message", json={"content": field}, headers=headers) |
|
|
assert res.ok, f"β Agent message failed ({i})" |
|
|
print(f"β
Sent user message ({i}):", res.json()["content"]) |
|
|
|
|
|
def test_document_view_and_edit(): |
|
|
print("\nπ Testing Document View and Edit") |
|
|
res = requests.get(f"{BASE_URL}/documents/{convo_id}", headers=headers) |
|
|
assert res.ok, "β Failed to get document" |
|
|
print("β
Document content retrieved") |
|
|
|
|
|
res = requests.post(f"{BASE_URL}/documents/{convo_id}/edit", json={"instruction": "Add confidentiality clause"}, headers=headers) |
|
|
assert res.ok, "β Document refinement failed" |
|
|
print("β
Document refined") |
|
|
|
|
|
def test_list_conversations(): |
|
|
print("\nπ Testing List Conversations") |
|
|
res = requests.get(f"{BASE_URL}/conversations/", headers=headers) |
|
|
assert res.ok, "β Failed to list conversations" |
|
|
print("β
Listed conversations:", [c['id'] for c in res.json()]) |
|
|
|
|
|
def test_delete_conversation(): |
|
|
print("\nποΈ Testing Delete Conversation") |
|
|
res = requests.delete(f"{BASE_URL}/conversations/{convo_id}", headers=headers) |
|
|
assert res.ok, "β Failed to delete conversation" |
|
|
print("β
Conversation deleted") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
test_register_and_login() |
|
|
test_create_conversation() |
|
|
test_get_conversation() |
|
|
test_agent_flow() |
|
|
test_document_view_and_edit() |
|
|
test_list_conversations() |
|
|
test_delete_conversation() |
|
|
|