Skip to content

Commit

Permalink
tests run locally
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 20, 2024
1 parent 7f99a2d commit f3a9810
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def remove_old_cache(
logger.debug(f"Removing {key} from cache, ({value})")
keys_to_remove.append(key)

logger.debug(f"Removing {len(keys_to_remove)} keys from cache")

for key in keys_to_remove:
try:
last_updated.pop(key)
Expand Down Expand Up @@ -129,7 +131,7 @@ def wrapper(*args, **kwargs): # noqa
return response[route_variables]

# use cache
logger.debug("Using cache route")
logger.debug(f"Using cache route, cache made at {last_updated[route_variables]}")
return response[route_variables]

return wrapper
11 changes: 9 additions & 2 deletions src/tests/fake/test_national_fake.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
""" Test for main app """

from freezegun import freeze_time

from national import is_fake
from pydantic_models import NationalForecastValue
from pydantic_models import NationalForecastValue, NationalYield


def test_is_fake_national_all_available_forecasts(monkeypatch, api_client):
Expand All @@ -22,6 +24,9 @@ def test_is_fake_national_all_available_forecasts(monkeypatch, api_client):
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.
Expand All @@ -33,7 +38,9 @@ def test_is_fake_national_get_truths_for_all_gsps(monkeypatch, api_client):
response = api_client.get("/v0/solar/GB/national/pvlive/")
assert response.status_code == 200

national_forecast_values = [NationalForecastValue(**f) for f in response.json()]
print(response.json())

national_forecast_values = [NationalYield(**f) for f in response.json()]
assert national_forecast_values is not None

# Disable is_fake environment
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_national.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_read_truth_national_gsp(db_session, api_client):

app.dependency_overrides[get_session] = lambda: db_session

response = api_client.get("/v0/solar/GB/national/pvlive/?This_does_nothing_apart_force_no_caching")
response = api_client.get("/v0/solar/GB/national/pvlive/")
assert response.status_code == 200

r_json = response.json()
Expand Down
2 changes: 2 additions & 0 deletions test-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
- DB_URL_PV=postgresql://postgres:postgres@postgres_db:5432/postgres
- GIT_PYTHON_REFRESH=quiet
- LOG_LEVEL=DEBUG
- DELETE_CACHE_TIME_SECONDS=0
- CACHE_TIME_SECONDS=0
command: >
bash -c "pytest --cov=./src
&& coverage report -m
Expand Down

0 comments on commit f3a9810

Please sign in to comment.