-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(parsers, ESTADISTICO_UT): add snapshot test for historical prod
- Loading branch information
1 parent
63f5663
commit 6d0862b
Showing
8 changed files
with
591 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
from datetime import datetime | ||
from importlib import resources | ||
|
||
import pytest | ||
from requests_mock import GET, POST | ||
|
||
from electricitymap.contrib.lib.types import ZoneKey | ||
from parsers.ESTADISTICO_UT import DAILY_OPERATION_URL, fetch_production | ||
from parsers.ESTADISTICO_UT import DAILY_OPERATION_URL, ZONE_INFO, fetch_production | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_response(adapter): | ||
def test_fetch_production_live(adapter, session, snapshot): | ||
adapter.register_uri( | ||
GET, | ||
DAILY_OPERATION_URL, | ||
text=resources.files("parsers.test.mocks.ESTADISTICO_UT") | ||
.joinpath("get.html") | ||
.joinpath("get_live.html") | ||
.read_text(), | ||
) | ||
adapter.register_uri( | ||
POST, | ||
DAILY_OPERATION_URL, | ||
text=resources.files("parsers.test.mocks.ESTADISTICO_UT") | ||
.joinpath("post.html") | ||
.joinpath("post_live.html") | ||
.read_text(), | ||
) | ||
assert snapshot == fetch_production(session=session) | ||
|
||
|
||
def test_fetch_production(session, snapshot): | ||
assert snapshot == fetch_production( | ||
zone_key=ZoneKey("SV"), | ||
session=session, | ||
def test_fetch_production_historical(adapter, session, snapshot): | ||
dt = datetime.fromisoformat("2025-01-01").replace(tzinfo=ZONE_INFO) | ||
|
||
adapter.register_uri( | ||
GET, | ||
DAILY_OPERATION_URL, | ||
text=resources.files("parsers.test.mocks.ESTADISTICO_UT") | ||
.joinpath("get_historical.html") | ||
.read_text(), | ||
) | ||
adapter.register_uri( | ||
POST, | ||
DAILY_OPERATION_URL, | ||
text=resources.files("parsers.test.mocks.ESTADISTICO_UT") | ||
.joinpath("post_historical.html") | ||
.read_text(), | ||
) | ||
|
||
assert snapshot == fetch_production(session=session, target_datetime=dt) |
Large diffs are not rendered by default.
Oops, something went wrong.