From fc14c77da9f476cbba92f4416b7f92d49983d6a6 Mon Sep 17 00:00:00 2001 From: Seth <140578547+pisethTang@users.noreply.github.com> Date: Tue, 1 Sep 2026 01:34:26 +0930 Subject: [PATCH] Update test_main.py --- tests/test_main.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index f708c80..c8db9fc 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -12,9 +12,7 @@ -# --- 1. UNIT TEST: The Math Engine --- def test_calculate_optimal_dispatch_basic_arbitrage(): - # Setup a perfectly efficient battery for easy math battery = BatterySpecs(capacity_mwh=2.0, max_mw=1.0, efficiency=1.0) market_data = [ MarketInterval(timestamp=datetime.now(timezone.utc), price_aud_mwh=10.0), # Cheap @@ -35,18 +33,13 @@ def test_calculate_optimal_dispatch_basic_arbitrage(): # ---------------- - # The Math: - # Charge 1.0 MW for 1 hour (2 blocks) = 1.0 MWh total energy - # Cost: 1.0 MWh * $10 = $10 - # Discharge: 1.0 MWh * $100 = $100 - # Expected Profit: $100 - $10 = $90 + assert result["total_profit_aud"] == 90.0 assert result["schedule"][0]["charge_mw"] == 1.0 # Should charge in the first block -# --- 2. INTEGRATION TEST: The API Endpoint --- def test_optimize_endpoint_success(): payload = { "battery": { @@ -60,13 +53,10 @@ def test_optimize_endpoint_success(): ] } - # Send a fake POST request to your API response = client.post("/api/v1/optimize", json=payload) - # Assert the server responded with 200 OK assert response.status_code == 200 - # Assert the JSON structure is exactly what we expect data = response.json() assert data["status"] == "success" assert "total_profit_aud" in data["data"] @@ -75,11 +65,10 @@ def test_optimize_endpoint_success(): -# --- 3. EDGE CASE TEST: Pydantic Validation --- def test_optimize_endpoint_invalid_battery(): payload = { "battery": { - "capacity_mwh": -5.0, # INVALID: Capacity cannot be negative! + "capacity_mwh": -5.0, "max_mw": 2.5, "efficiency": 0.9 }, @@ -90,6 +79,4 @@ def test_optimize_endpoint_invalid_battery(): response = client.post("/api/v1/optimize", json=payload) - # Pydantic should intercept this bad data and return a 422 Unprocessable Entity error - # before it ever reaches the PuLP math engine. - assert response.status_code == 422 \ No newline at end of file + assert response.status_code == 422