-
-
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 f…
…rom 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>
- Loading branch information
1 parent
00662be
commit a6b5e1b
Showing
5 changed files
with
180 additions
and
32 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
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,63 @@ | ||
import pytest | ||
import requests | ||
import requests_mock | ||
|
||
API_URL = "/v0/solar/GB/national/elexon" | ||
|
||
|
||
@pytest.fixture | ||
def mock_data(): | ||
return { | ||
"data": [ | ||
{ | ||
"timestamp": "2024-07-24T16:45:09+00:00", | ||
"expected_power_generation_megawatts": 0, | ||
"plevels": None, | ||
}, | ||
{ | ||
"timestamp": "2024-07-24T16:45:09+00:00", | ||
"expected_power_generation_megawatts": 0, | ||
"plevels": None, | ||
}, | ||
] | ||
} | ||
|
||
|
||
def test_get_elexon_forecast_with_data(mock_data): | ||
with requests_mock.Mocker() as m: | ||
url = ( | ||
f"{API_URL}?start_datetime_utc=2024-07-22T10:56:59.194610" | ||
f"&end_datetime_utc=2024-07-28T10:56:59.194680" | ||
f"&process_type=Day Ahead" | ||
) | ||
m.get(url, json=mock_data, headers={"Content-Type": "application/json"}) | ||
|
||
response = requests.get(url) | ||
print("Response Headers:", response.headers) | ||
# Assertions | ||
assert response.status_code == 200 | ||
assert response.headers.get("Content-Type") == "application/json" | ||
assert response.json() == mock_data | ||
|
||
|
||
@pytest.fixture | ||
def empty_mock_data(): | ||
return {"data": []} | ||
|
||
|
||
def test_get_elexon_forecast_no_data(empty_mock_data): | ||
with requests_mock.Mocker() as m: | ||
url = ( | ||
f"{API_URL}?start_datetime_utc=2024-07-22T10:56:59.194610" | ||
f"&end_datetime_utc=2024-07-28T10:56:59.194680" | ||
f"&process_type=Day Ahead" | ||
) | ||
|
||
m.get(url, json=empty_mock_data, headers={"Content-Type": "application/json"}) | ||
|
||
response = requests.get(url) | ||
print("Response Headers:", response.headers) | ||
# Assertions | ||
assert response.status_code == 200 | ||
assert response.headers.get("Content-Type") == "application/json" | ||
assert response.json() == empty_mock_data |