File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111import json
1212import os
1313from datetime import datetime , timedelta
14+ from unittest .mock import MagicMock , patch
1415
1516from futurerate import FutureRate
1617
@@ -75,6 +76,18 @@ def run_nordpool_test(my_predbat):
7576 my_predbat .args ["futurerate_peak_premium_export" ] = 6.5
7677 failed = False
7778
79+ mock_response = MagicMock ()
80+ mock_response .status_code = 200
81+ mock_response .text = json .dumps ({"multiAreaEntries" : []})
82+ with patch ("futurerate.requests.get" , return_value = mock_response ) as mock_get :
83+ FutureRate (my_predbat ).download_futurerate_data_func ("https://example.com/nordpool" )
84+ if mock_get .call_count != 1 :
85+ print ("ERROR: Expected 1 Nord Pool HTTP call for timeout coverage, got {}" .format (mock_get .call_count ))
86+ failed = True
87+ elif mock_get .call_args .kwargs .get ("timeout" ) != 120 :
88+ print ("ERROR: Expected Nord Pool download timeout 120, got {}" .format (mock_get .call_args .kwargs .get ("timeout" )))
89+ failed = True
90+
7891 fixture = _load_fixture ()
7992 if fixture :
8093 print ("Using saved nordpool fixture (no network calls)" )
Original file line number Diff line number Diff line change @@ -76,6 +76,20 @@ def test_octopus_free(my_predbat):
7676 temp_dir = tempfile .mkdtemp ()
7777 original_config_root = getattr (my_predbat , "config_root" , None )
7878 try :
79+ with patch ("octopus.requests.get" , return_value = _mock_http_response (_JSON_BODY )) as mock_get :
80+ body = my_predbat .download_octopus_free_func (_URL )
81+ if mock_get .call_count != 1 :
82+ print ("FAIL: Expected 1 HTTP call when covering free-session timeout, got {}" .format (mock_get .call_count ))
83+ failed = True
84+ elif mock_get .call_args .kwargs .get ("timeout" ) != 30 :
85+ print ("FAIL: Expected Octopus free-session timeout 30, got {}" .format (mock_get .call_args .kwargs .get ("timeout" )))
86+ failed = True
87+ elif body != _JSON_BODY :
88+ print ("FAIL: Expected Octopus free-session body to round-trip unchanged" )
89+ failed = True
90+ else :
91+ print ("PASS: Free-session direct download uses the configured timeout" )
92+
7993 # --- Test 1: no storage (components=None) — no exception, returns sessions ---
8094 _reset_free_cache (my_predbat )
8195 my_predbat .components = None
You can’t perform that action at this time.
0 commit comments