mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-22 12:12:49 +05:30
feat: Add google-genai & structured output
This commit is contained in:
@@ -101,3 +101,49 @@ async def test_get_all_jobs(client: AsyncClient):
|
||||
response = await client.get("/api/v1/jobs")
|
||||
assert response.status_code == 200
|
||||
assert isinstance(response.json(), list)
|
||||
|
||||
|
||||
async def test_upload_csv_new_anomalies(client: AsyncClient):
|
||||
# ACC03 has Cafe transactions: 10 INR, 12 INR, 100 INR (median 12 INR, 3x median = 36 INR)
|
||||
# ACC03 also has a domestic merchant 'Ola' in USD
|
||||
csv_content = (
|
||||
"txn_id,date,amount,merchant,currency,category,account\n"
|
||||
"TX3001,2026-06-25,10.00,Cafe,INR,Food,ACC03\n"
|
||||
"TX3002,2026-06-26,12.00,Cafe,INR,Food,ACC03\n"
|
||||
"TX3003,2026-06-27,100.00,Cafe,INR,Food,ACC03\n" # 3x median outlier (> 36)
|
||||
"TX3004,2026-06-28,50.00,Ola cabs,USD,Travel,ACC03\n" # Domestic in USD
|
||||
)
|
||||
|
||||
files = {
|
||||
"file": (
|
||||
"transactions_new_anomalies.csv",
|
||||
io.BytesIO(csv_content.encode("utf-8")),
|
||||
"text/csv",
|
||||
)
|
||||
}
|
||||
|
||||
response = await client.post("/api/v1/jobs/upload", files=files)
|
||||
assert response.status_code == 201
|
||||
job_id = response.json()["id"]
|
||||
|
||||
# Retrieve status and verify anomalies count
|
||||
status_response = await client.get(f"/api/v1/jobs/{job_id}/status")
|
||||
assert status_response.status_code == 200
|
||||
status_data = status_response.json()
|
||||
assert status_data["summary"]["anomaly_count"] == 2 # TX3003 and TX3004
|
||||
|
||||
# Retrieve full results and verify reasons
|
||||
results_response = await client.get(f"/api/v1/jobs/{job_id}/results")
|
||||
assert results_response.status_code == 200
|
||||
results_data = results_response.json()
|
||||
txns = results_data["transactions"]
|
||||
|
||||
# TX3003 outlier check
|
||||
outlier_txn = next(t for t in txns if t["txn_id"] == "TX3003")
|
||||
assert outlier_txn["is_anomaly"] is True
|
||||
assert "Statistical outlier" in outlier_txn["anomaly_reason"]
|
||||
|
||||
# TX3004 domestic in USD check
|
||||
domestic_txn = next(t for t in txns if t["txn_id"] == "TX3004")
|
||||
assert domestic_txn["is_anomaly"] is True
|
||||
assert "Domestic brand transacted in USD" in domestic_txn["anomaly_reason"]
|
||||
|
||||
@@ -36,7 +36,7 @@ def initialize_test_db():
|
||||
"""Create test tables and clean them up after all tests finish."""
|
||||
global _db_offline
|
||||
try:
|
||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||
loop = asyncio.get_event_loop()
|
||||
except RuntimeError:
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
Reference in New Issue
Block a user