diff --git a/src/tests/fake/test_gsp_fake.py b/src/tests/fake/test_gsp_fake.py new file mode 100644 index 00000000..79780bd6 --- /dev/null +++ b/src/tests/fake/test_gsp_fake.py @@ -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") diff --git a/src/tests/test_gsp.py b/src/tests/test_gsp.py index 4d407182..ed68bfd3 100644 --- a/src/tests/test_gsp.py +++ b/src/tests/test_gsp.py @@ -18,7 +18,6 @@ from nowcasting_datamodel.save.update import update_all_forecast_latest from database import get_session -from gsp import GSP_TOTAL, is_fake from main import app from pydantic_models import GSPYieldGroupByDatetime, OneDatetimeManyForecastValues @@ -426,85 +425,3 @@ def test_read_truths_for_all_gsp_compact(db_session, api_client): assert len(datetimes_with_gsp_yields[0].generation_kw_by_gsp_id) == 1 assert len(datetimes_with_gsp_yields[1].generation_kw_by_gsp_id) == 2 assert len(datetimes_with_gsp_yields[2].generation_kw_by_gsp_id) == 1 - - -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")