11from unittest .mock import Mock
2- from control .optional import Optional
3- from helpermodules import timecheck
42import pytest
3+ from helpermodules import timecheck
4+ from control .optional import Optional
5+
56
67ONE_HOUR_SECONDS = 3600
78IGNORED = 0.0001
220221 ),
221222 ],
222223)
223- def test_et_get_loading_hours (granularity ,
224+ def test_ep_get_loading_hours (granularity ,
224225 now_ts ,
225226 duration ,
226227 remaining_time ,
@@ -229,17 +230,16 @@ def test_et_get_loading_hours(granularity,
229230 monkeypatch ):
230231 # setup
231232 opt = Optional ()
232- opt .data .et .get .prices = price_list
233- mock_et_provider_available = Mock (return_value = True )
234- monkeypatch .setattr (opt , "et_provider_available" , mock_et_provider_available )
233+ opt .data .electricity_pricing .get .prices = price_list
234+ opt .data .electricity_pricing .configured = True
235235 monkeypatch .setattr (
236236 timecheck ,
237237 "create_timestamp" ,
238238 Mock (return_value = now_ts )
239239 )
240240
241241 # execution
242- loading_hours = opt .et_get_loading_hours (duration = duration , remaining_time = remaining_time )
242+ loading_hours = opt .ep_get_loading_hours (duration = duration , remaining_time = remaining_time )
243243
244244 # evaluation
245245 assert loading_hours == expected_loading_hours
@@ -256,18 +256,18 @@ def test_et_get_loading_hours(granularity,
256256)
257257def test_et_charging_allowed (monkeypatch , provider_available , current_price , max_price , expected ):
258258 opt = Optional ()
259- monkeypatch . setattr ( opt , "et_provider_available" , Mock ( return_value = provider_available ))
259+ opt . data . electricity_pricing . configured = provider_available
260260 if provider_available :
261- monkeypatch .setattr (opt , "et_get_current_price " , Mock (return_value = current_price ))
262- result = opt .et_is_charging_allowed_price_threshold (max_price )
261+ monkeypatch .setattr (opt , "ep_get_current_price " , Mock (return_value = current_price ))
262+ result = opt .ep_is_charging_allowed_price_threshold (max_price )
263263 assert result == expected
264264
265265
266266def test_et_charging_allowed_exception (monkeypatch ):
267267 opt = Optional ()
268- monkeypatch . setattr ( opt , "et_provider_available" , Mock ( return_value = True ))
269- monkeypatch .setattr (opt , "et_get_current_price " , Mock (side_effect = Exception ))
270- result = opt .et_is_charging_allowed_price_threshold (0.15 )
268+ opt . data . electricity_pricing . configured = True
269+ monkeypatch .setattr (opt , "ep_get_current_price " , Mock (side_effect = Exception ))
270+ result = opt .ep_is_charging_allowed_price_threshold (0.15 )
271271 assert result is False
272272
273273
@@ -425,17 +425,18 @@ def test_et_charging_available(now_ts, provider_available, price_list, selected_
425425 Mock (return_value = now_ts )
426426 )
427427 opt = Optional ()
428- opt .data .et .get .prices = price_list
429- monkeypatch . setattr ( opt , "et_provider_available" , Mock ( return_value = provider_available ))
430- result = opt .et_is_charging_allowed_hours_list (selected_hours )
428+ opt .data .electricity_pricing .get .prices = price_list
429+ opt . data . electricity_pricing . configured = provider_available
430+ result = opt .ep_is_charging_allowed_hours_list (selected_hours )
431431 assert result == expected
432432
433433
434434def test_et_charging_available_exception (monkeypatch ):
435435 opt = Optional ()
436- monkeypatch .setattr (opt , "et_provider_available" , Mock (return_value = True ))
437- opt .data .et .get .prices = {} # empty prices list raises exception
438- result = opt .et_is_charging_allowed_hours_list ([])
436+ opt .data .electricity_pricing .configured = True
437+
438+ opt .data .electricity_pricing .get .prices = {} # empty prices list raises exception
439+ result = opt .ep_is_charging_allowed_hours_list ([])
439440 assert result is False
440441
441442
@@ -446,10 +447,6 @@ def test_et_charging_available_exception(monkeypatch):
446447 {}, None , 1698224400 , True ,
447448 id = "update_required_when_no_prices"
448449 ),
449- pytest .param (
450- {"1698224400" : 0.1 , "1698228000" : 0.2 }, None , 1698224400 , False ,
451- id = "no_update_required_when_prices_available_and_recent"
452- ),
453450 pytest .param (
454451 {"1698224400" : 0.1 , "1698228000" : 0.2 }, 1698310800 , 1698224400 , False ,
455452 id = "no_update_required_when_next_query_time_not_reached"
@@ -467,10 +464,11 @@ def test_et_charging_available_exception(monkeypatch):
467464def test_et_price_update_required (monkeypatch , prices , next_query_time , current_timestamp , expected ):
468465 # setup
469466 opt = Optional ()
470- opt .data .et .get .prices = prices
471- opt .data .et .get .next_query_time = next_query_time
467+ opt .data .electricity_pricing .get .prices = prices
468+ opt .data .electricity_pricing .get .next_query_time = next_query_time
472469
473470 monkeypatch .setattr (timecheck , "create_timestamp" , Mock (return_value = current_timestamp ))
471+ opt .data .electricity_pricing .configured = True
474472
475473 # execution
476474 result = opt .et_price_update_required ()
0 commit comments