-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a national end point, that provides elexon BMRS solar foreacsts from elexonpy package (#347) * added import statements of elexonpy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added API for solar forecast * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changed function name * added filter functionality * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added API link * minor fix * remove try except block * changed bmrs to elexon * minor fix * resolving pre hook * minor fix in docstring * removed router * minor fix in naming * added elexonpy in requirement.txt file * resolve hook error * minor fix * added response model * fixed unit test * remove plevel --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * first try at mocking elexon api * upadte url for api * update test, remove try and except * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * isort * and try and except * add intergation test * lint * PR comments, move elexon to below forecast and pvlive * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * change docker-compose to docker compose * fix test * Minor change to mock method on real class --------- Co-authored-by: Richa <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: braddf <[email protected]> Co-authored-by: braddf <[email protected]>
- Loading branch information
1 parent
00662be
commit 2f98d4f
Showing
6 changed files
with
178 additions
and
25 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ slowapi | |
pathy==0.10.3 | ||
fsspec | ||
s3fs | ||
elexonpy |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from typing import Optional | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pandas as pd | ||
import pytest | ||
from elexonpy.api.generation_forecast_api import GenerationForecastApi | ||
|
||
from pydantic_models import BaseModel, SolarForecastResponse | ||
|
||
API_URL = "/v0/solar/GB/national/elexon" | ||
|
||
|
||
class MockClass(BaseModel): | ||
start_time: str | ||
quantity: float | ||
business_type: Optional[str] = "Solar generation" | ||
|
||
def to_dict(self): | ||
return self.__dict__ | ||
|
||
|
||
mock_data = [ | ||
MockClass( | ||
**{ | ||
"start_time": "2024-07-24T16:00:00+00:00", | ||
"quantity": 0, | ||
} | ||
), | ||
MockClass( | ||
**{ | ||
"start_time": "2024-07-24T16:30:00+00:00", | ||
"quantity": 0, | ||
} | ||
), | ||
] | ||
mock_response = MagicMock() | ||
mock_response.data = mock_data | ||
|
||
|
||
@patch.object(GenerationForecastApi, "forecast_generation_wind_and_solar_day_ahead_get") | ||
def test_get_elexon_forecast_mock(mock_function, api_client): | ||
# Set mock_response | ||
mock_function.return_value = mock_response | ||
|
||
# Call the API endpoint | ||
response = api_client.get(API_URL) | ||
print("Response Headers:", response.headers) | ||
# Assertions | ||
assert response.status_code == 200 | ||
assert response.headers.get("Content-Type") == "application/json" | ||
|
||
api_data = response.json()["data"] | ||
assert len(api_data) == len(mock_data) | ||
for i in range(len(api_data)): | ||
assert api_data[i]["expected_power_generation_megawatts"] == mock_data[i].quantity | ||
assert pd.Timestamp(api_data[i]["timestamp"]) == pd.Timestamp(mock_data[i].start_time) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_get_elexon_forecast(api_client): | ||
response = api_client.get(API_URL) | ||
|
||
# Assertions | ||
assert response.status_code == 200 | ||
assert response.headers.get("Content-Type") == "application/json" | ||
|
||
solar_forecast = SolarForecastResponse(**response.json()) | ||
|
||
assert len(solar_forecast.data) > 0 |