Skip to content

Commit

Permalink
Experiment: Create a separate tests/fake/test_gsp_fake.py test case m…
Browse files Browse the repository at this point in the history
…odule
  • Loading branch information
VikramsDataScience committed Dec 20, 2024
1 parent b0f55e6 commit adf6855
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 83 deletions.
88 changes: 88 additions & 0 deletions src/tests/fake/test_gsp_fake.py
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")
83 changes: 0 additions & 83 deletions src/tests/test_gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")

0 comments on commit adf6855

Please sign in to comment.