Skip to content

Commit

Permalink
tests(parsers, ESTADISTICO_UT): add snapshot test for historical prod
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jan 14, 2025
1 parent 63f5663 commit 6d0862b
Show file tree
Hide file tree
Showing 8 changed files with 591 additions and 12 deletions.
70 changes: 70 additions & 0 deletions get_historical.html

Large diffs are not rendered by default.

426 changes: 425 additions & 1 deletion parsers/test/__snapshots__/test_ESTADISTICO_UT.ambr

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions parsers/test/mocks/ESTADISTICO_UT/get_historical.html

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions parsers/test/mocks/ESTADISTICO_UT/post_historical.html

Large diffs are not rendered by default.

File renamed without changes.
35 changes: 24 additions & 11 deletions parsers/test/test_ESTADISTICO_UT.py
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)
1 change: 1 addition & 0 deletions post_historical.html

Large diffs are not rendered by default.

0 comments on commit 6d0862b

Please sign in to comment.