mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-12 05:27:24 -04:00
test: update e2e test to use new results endpoint parameters
This commit is contained in:
@@ -334,18 +334,29 @@ class TestFullSimulationWorkflow:
|
|||||||
db.connection.commit()
|
db.connection.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
# 4. Query results WITHOUT reasoning (default)
|
# 4. Query each day individually to get detailed format
|
||||||
results_response = e2e_client.get(f"/results?job_id={job_id}")
|
# Query Day 1
|
||||||
|
day1_response = e2e_client.get(f"/results?job_id={job_id}&start_date=2025-01-16&end_date=2025-01-16")
|
||||||
|
assert day1_response.status_code == 200
|
||||||
|
day1_data = day1_response.json()
|
||||||
|
assert day1_data["count"] == 1
|
||||||
|
day1 = day1_data["results"][0]
|
||||||
|
|
||||||
assert results_response.status_code == 200
|
# Query Day 2
|
||||||
results_data = results_response.json()
|
day2_response = e2e_client.get(f"/results?job_id={job_id}&start_date=2025-01-17&end_date=2025-01-17")
|
||||||
|
assert day2_response.status_code == 200
|
||||||
|
day2_data = day2_response.json()
|
||||||
|
assert day2_data["count"] == 1
|
||||||
|
day2 = day2_data["results"][0]
|
||||||
|
|
||||||
# Should have 3 trading days
|
# Query Day 3
|
||||||
assert results_data["count"] == 3
|
day3_response = e2e_client.get(f"/results?job_id={job_id}&start_date=2025-01-18&end_date=2025-01-18")
|
||||||
assert len(results_data["results"]) == 3
|
assert day3_response.status_code == 200
|
||||||
|
day3_data = day3_response.json()
|
||||||
|
assert day3_data["count"] == 1
|
||||||
|
day3 = day3_data["results"][0]
|
||||||
|
|
||||||
# 4. Verify Day 1 structure and data
|
# 4. Verify Day 1 structure and data
|
||||||
day1 = results_data["results"][0]
|
|
||||||
|
|
||||||
assert day1["date"] == "2025-01-16"
|
assert day1["date"] == "2025-01-16"
|
||||||
assert day1["model"] == "test-mock-e2e"
|
assert day1["model"] == "test-mock-e2e"
|
||||||
@@ -385,9 +396,6 @@ class TestFullSimulationWorkflow:
|
|||||||
assert day1["reasoning"] is None
|
assert day1["reasoning"] is None
|
||||||
|
|
||||||
# 5. Verify holdings chain across days
|
# 5. Verify holdings chain across days
|
||||||
day2 = results_data["results"][1]
|
|
||||||
day3 = results_data["results"][2]
|
|
||||||
|
|
||||||
# Day 2 starting holdings should match Day 1 ending holdings
|
# Day 2 starting holdings should match Day 1 ending holdings
|
||||||
assert day2["starting_position"]["holdings"] == day1["final_position"]["holdings"]
|
assert day2["starting_position"]["holdings"] == day1["final_position"]["holdings"]
|
||||||
assert day2["starting_position"]["cash"] == day1["final_position"]["cash"]
|
assert day2["starting_position"]["cash"] == day1["final_position"]["cash"]
|
||||||
@@ -407,35 +415,37 @@ class TestFullSimulationWorkflow:
|
|||||||
|
|
||||||
# 7. Verify portfolio value calculations
|
# 7. Verify portfolio value calculations
|
||||||
# Ending portfolio value should be cash + (sum of holdings * prices)
|
# Ending portfolio value should be cash + (sum of holdings * prices)
|
||||||
for day in results_data["results"]:
|
for day in [day1, day2, day3]:
|
||||||
assert day["final_position"]["portfolio_value"] >= day["final_position"]["cash"], \
|
assert day["final_position"]["portfolio_value"] >= day["final_position"]["cash"], \
|
||||||
f"Portfolio value should be >= cash. Day: {day['date']}"
|
f"Portfolio value should be >= cash. Day: {day['date']}"
|
||||||
|
|
||||||
# 8. Query results with reasoning SUMMARY
|
# 8. Query results with reasoning SUMMARY (single date)
|
||||||
summary_response = e2e_client.get(f"/results?job_id={job_id}&reasoning=summary")
|
summary_response = e2e_client.get(f"/results?job_id={job_id}&start_date=2025-01-16&end_date=2025-01-16&reasoning=summary")
|
||||||
assert summary_response.status_code == 200
|
assert summary_response.status_code == 200
|
||||||
summary_data = summary_response.json()
|
summary_data = summary_response.json()
|
||||||
|
|
||||||
# Each day should have reasoning summary
|
# Should have reasoning summary
|
||||||
for result in summary_data["results"]:
|
assert summary_data["count"] == 1
|
||||||
assert result["reasoning"] is not None
|
result = summary_data["results"][0]
|
||||||
assert isinstance(result["reasoning"], str)
|
assert result["reasoning"] is not None
|
||||||
# Summary should be non-empty (mock model generates summaries)
|
assert isinstance(result["reasoning"], str)
|
||||||
# Note: Summary might be empty if AI generation failed - that's OK
|
# Summary should be non-empty (mock model generates summaries)
|
||||||
# Just verify the field exists and is a string
|
# Note: Summary might be empty if AI generation failed - that's OK
|
||||||
|
# Just verify the field exists and is a string
|
||||||
|
|
||||||
# 9. Query results with FULL reasoning
|
# 9. Query results with FULL reasoning (single date)
|
||||||
full_response = e2e_client.get(f"/results?job_id={job_id}&reasoning=full")
|
full_response = e2e_client.get(f"/results?job_id={job_id}&start_date=2025-01-16&end_date=2025-01-16&reasoning=full")
|
||||||
assert full_response.status_code == 200
|
assert full_response.status_code == 200
|
||||||
full_data = full_response.json()
|
full_data = full_response.json()
|
||||||
|
|
||||||
# Each day should have full reasoning log
|
# Should have full reasoning log
|
||||||
for result in full_data["results"]:
|
assert full_data["count"] == 1
|
||||||
assert result["reasoning"] is not None
|
result = full_data["results"][0]
|
||||||
assert isinstance(result["reasoning"], list)
|
assert result["reasoning"] is not None
|
||||||
# Full reasoning should contain messages
|
assert isinstance(result["reasoning"], list)
|
||||||
assert len(result["reasoning"]) > 0, \
|
# Full reasoning should contain messages
|
||||||
f"Expected full reasoning log for {result['date']}"
|
assert len(result["reasoning"]) > 0, \
|
||||||
|
f"Expected full reasoning log for {result['date']}"
|
||||||
|
|
||||||
# 10. Verify database structure directly
|
# 10. Verify database structure directly
|
||||||
from api.database import get_db_connection
|
from api.database import get_db_connection
|
||||||
|
|||||||
Reference in New Issue
Block a user