-
-
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.
* Fake data Issue #354 (#360) * Fake data Issue #354 * Fake data Issue #354 * Fake data Issue #354 * Changed relative imports and removed pre-commit from requirements.txt * Using more flexible python3 version to attempt to fix pre-commit.ci build issue * Written new Unit Test for fake forecast with specified GSP ID * Written unit tests for all endpoints/routes and modified gsp.py to support new tests * Removed duplicated Test Cases * 1st test case for fake environment * Fixed accidental activation of fake environment in gsp.py module * Written and tested remaining test cases for is_fake * Moved isintance check to prior to is_fake condition * Added 2 Tests to test_national.py and cleaned up some logic in test_gsp test cases * Modified gsp.py and national.py modules and accompanying test cases to address feedback * Fixed incorrect for loop iteration through list (should be singular ForecastSQL object) to forecasts object in the test_national.py test cases * Modified test cases to use NationalForecastValue, ForecastValue, and the ManyForecasts as the return objects * Modified test cases to uss pytest.fixture() to yield values from db_session * Possible fix for test_read_latest_all_gsp_normalized() and test_read_latest_all_gsp() * 1st experiment for test_read_truth_national_gsp() and test_read_forecast_values_gsp() * 1st experiment with make_fake_gsp_yields() * 2nd experiment with make_fake_gsp_yields() - modified test_gsp routes * 3rd experiment with make_fake_gsp_yields() - modified List Comprehension * 4th experiment with make_fake_gsp_yields() - hard coded _gsp_id_ * Removed yield and fixture * Experiment: Create a separate tests/fake/test_gsp_fake.py test case module * split national tests * role back changes in tests * fix national test * rename * is_fake to is_fake() * add to readme, don't use any caching in tests * role back, * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * tests run locally --------- Co-authored-by: Vikram Pande <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7531e9e
commit 97bbca1
Showing
8 changed files
with
194 additions
and
8 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
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,88 @@ | ||
from nowcasting_datamodel.models import ForecastValue, LocationWithGSPYields, ManyForecasts | ||
|
||
from gsp import GSP_TOTAL, is_fake | ||
|
||
|
||
def test_is_fake_specific_gsp(monkeypatch, api_client, gsp_id=1): | ||
"""### Test FAKE environment specific _gsp_id_ routes are populating | ||
with fake data. | ||
#### Parameters | ||
- **gsp_id**: Please set to any non-zero integer that is <= GSP_TOTAL | ||
""" | ||
|
||
monkeypatch.setenv("FAKE", "1") | ||
assert is_fake() == 1 | ||
|
||
# Specific _gsp_id_ route/endpoint for successful connection | ||
response = api_client.get(f"/v0/solar/GB/gsp/{gsp_id}/forecast") | ||
assert response.status_code == 200 | ||
|
||
forecast_value = [ForecastValue(**f) for f in response.json()] | ||
assert forecast_value is not None | ||
|
||
# Disable is_fake environment | ||
monkeypatch.setenv("FAKE", "0") | ||
|
||
|
||
def test_is_fake_get_truths_for_a_specific_gsp(monkeypatch, api_client, gsp_id=1): | ||
"""### Test FAKE environment specific _gsp_id_ routes are populating | ||
with fake data. | ||
#### Parameters | ||
- **gsp_id**: Please set to any non-zero integer that is <= GSP_TOTAL | ||
""" | ||
|
||
monkeypatch.setenv("FAKE", "1") | ||
assert is_fake() == 1 | ||
|
||
# Specific _gsp_id_ route/endpoint for successful connection | ||
response = api_client.get(f"/v0/solar/GB/gsp/{gsp_id}/pvlive") | ||
assert response.status_code == 200 | ||
|
||
forecast_value = [ForecastValue(**f) for f in response.json()] | ||
assert forecast_value is not None | ||
|
||
# Disable is_fake environment | ||
monkeypatch.setenv("FAKE", "0") | ||
|
||
|
||
def test_is_fake_all_available_forecasts(monkeypatch, api_client): | ||
"""Test FAKE environment for all GSPs are populating | ||
with fake data. | ||
""" | ||
|
||
monkeypatch.setenv("FAKE", "1") | ||
assert is_fake() == 1 | ||
|
||
# Connect to DB endpoint | ||
response = api_client.get("/v0/solar/GB/gsp/forecast/all/") | ||
assert response.status_code == 200 | ||
|
||
all_forecasts = ManyForecasts(**response.json()) | ||
assert all_forecasts is not None | ||
|
||
# Disable is_fake environment | ||
monkeypatch.setenv("FAKE", "0") | ||
|
||
|
||
def test_is_fake_get_truths_for_all_gsps( | ||
monkeypatch, api_client, gsp_ids=list(range(1, GSP_TOTAL)) | ||
): | ||
"""Test FAKE environment for all GSPs for yesterday and today | ||
are populating with fake data. | ||
""" | ||
|
||
monkeypatch.setenv("FAKE", "1") | ||
assert is_fake() == 1 | ||
|
||
# Connect to DB endpoint | ||
gsp_ids_str = ", ".join(map(str, gsp_ids)) | ||
response = api_client.get(f"/v0/solar/GB/gsp/pvlive/all?gsp_ids={gsp_ids_str}") | ||
assert response.status_code == 200 | ||
|
||
all_forecasts = [LocationWithGSPYields(**f) for f in response.json()] | ||
assert all_forecasts is not None | ||
|
||
# Disable is_fake environment | ||
monkeypatch.setenv("FAKE", "0") |
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,47 @@ | ||
""" Test for main app """ | ||
|
||
from freezegun import freeze_time | ||
|
||
from national import is_fake | ||
from pydantic_models import NationalForecastValue, NationalYield | ||
|
||
|
||
def test_is_fake_national_all_available_forecasts(monkeypatch, api_client): | ||
"""Test FAKE environment for all GSPs are populating | ||
with fake data. | ||
""" | ||
|
||
monkeypatch.setenv("FAKE", "1") | ||
assert is_fake() == 1 | ||
# Connect to DB endpoint | ||
response = api_client.get("/v0/solar/GB/national/forecast") | ||
assert response.status_code == 200 | ||
|
||
national_forecast_values = [NationalForecastValue(**f) for f in response.json()] | ||
assert national_forecast_values is not None | ||
|
||
# Disable is_fake environment | ||
monkeypatch.setenv("FAKE", "0") | ||
|
||
|
||
# The freeze time is needed so the cahce doesnt interact with the test in test_national.py | ||
# Ideally we would not have this | ||
@freeze_time("2021-12-01") | ||
def test_is_fake_national_get_truths_for_all_gsps(monkeypatch, api_client): | ||
"""Test FAKE environment for all GSPs for yesterday and today | ||
are populating with fake data. | ||
""" | ||
|
||
monkeypatch.setenv("FAKE", "1") | ||
assert is_fake() == 1 | ||
# Connect to DB endpoint | ||
response = api_client.get("/v0/solar/GB/national/pvlive/") | ||
assert response.status_code == 200 | ||
|
||
print(response.json()) | ||
|
||
national_forecast_values = [NationalYield(**f) for f in response.json()] | ||
assert national_forecast_values is not None | ||
|
||
# Disable is_fake environment | ||
monkeypatch.setenv("FAKE", "0") |
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