Skip to content

fix: Replace example.com URL and mock network in test_evcc#291

Merged
MaStr merged 1 commit intomainfrom
copilot/fix-test-with-remote-url
Mar 10, 2026
Merged

fix: Replace example.com URL and mock network in test_evcc#291
MaStr merged 1 commit intomainfrom
copilot/fix-test-with-remote-url

Conversation

@MaStr
Copy link
Owner

@MaStr MaStr commented Mar 10, 2026

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

Closed: #285

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>
Copilot AI review requested due to automatic review settings March 10, 2026 15:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/prices with https://demo.evcc.io/api/tariff/grid
  • Add patch.object(evcc, 'get_raw_data_from_provider', return_value=raw_data) around the test_get_prices_with_target_resolution_60 test to prevent real network calls
  • Re-indent the patch('batcontrol.dynamictariff.evcc.datetime') and patch('batcontrol.dynamictariff.baseclass.datetime') context managers to nest inside the new patch.object context

"""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'
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
self.url = 'https://demo.evcc.io/api/tariff/grid'
self.url = 'http://evcc.local/api/tariff/grid'

Copilot uses AI. Check for mistakes.
@MaStr MaStr merged commit c306b04 into main Mar 10, 2026
17 checks passed
@MaStr MaStr deleted the copilot/fix-test-with-remote-url branch March 10, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: evcc prices , fix domain

2 participants