fix: Replace example.com URL and mock network in test_evcc#291
Conversation
test_evcc.py used 'http://test.example.com/api/prices' as the test URL. get_prices() calls refresh_data() which always hits the network on the first call (next_update_ts == 0), even when store_raw_data() was called beforehand. This caused the pipeline to make a real HTTP request to an external domain. - Replace test URL with 'https://demo.evcc.io/api/tariff/grid' - Mock get_raw_data_from_provider in test_get_prices_with_target_resolution_60 so the test is fully self-contained and never reaches out to the network Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a test isolation issue in test_evcc.py where test_get_prices_with_target_resolution_60 was making real HTTP requests to an external domain because get_prices() always triggers refresh_data() (and thus get_raw_data_from_provider()) on the first call when next_update_ts == 0, even after store_raw_data() has been called. The PR also replaces the placeholder example.com test URL.
Changes:
- Replace the placeholder test URL
http://test.example.com/api/priceswithhttps://demo.evcc.io/api/tariff/grid - Add
patch.object(evcc, 'get_raw_data_from_provider', return_value=raw_data)around thetest_get_prices_with_target_resolution_60test to prevent real network calls - Re-indent the
patch('batcontrol.dynamictariff.evcc.datetime')andpatch('batcontrol.dynamictariff.baseclass.datetime')context managers to nest inside the newpatch.objectcontext
| """Set up test fixtures""" | ||
| self.timezone = pytz.timezone('Europe/Berlin') | ||
| self.url = 'http://test.example.com/api/prices' | ||
| self.url = 'https://demo.evcc.io/api/tariff/grid' |
There was a problem hiding this comment.
The new test URL https://demo.evcc.io/api/tariff/grid points to a real external domain, which is inconsistent with the rest of the codebase. Other tests that construct EVCC instances use non-routable URLs such as http://evcc.local/api/tariff/grid (see test_baseclass.py lines 268, 277). While no test here actually makes a network request to this URL (since they all call _get_prices_native() directly or mock get_raw_data_from_provider), using a real external URL is misleading and deviates from the project convention. It should be replaced with a local, non-routable URL like http://evcc.local/api/tariff/grid to match the pattern established in test_baseclass.py.
| self.url = 'https://demo.evcc.io/api/tariff/grid' | |
| self.url = 'http://evcc.local/api/tariff/grid' |
test_evcc.py used 'http://test.example.com/api/prices' as the test URL. get_prices() calls refresh_data() which always hits the network on the first call (next_update_ts == 0), even when store_raw_data() was called beforehand. This caused the pipeline to make a real HTTP request to an external domain.
Closed: #285