diff --git a/src/cache.py b/src/cache.py index a019096..a516ea9 100644 --- a/src/cache.py +++ b/src/cache.py @@ -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) @@ -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 diff --git a/src/tests/fake/test_national_fake.py b/src/tests/fake/test_national_fake.py index a468a90..bd8ba8b 100644 --- a/src/tests/fake/test_national_fake.py +++ b/src/tests/fake/test_national_fake.py @@ -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): @@ -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. @@ -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 diff --git a/src/tests/test_national.py b/src/tests/test_national.py index 7b1db7f..fe462df 100644 --- a/src/tests/test_national.py +++ b/src/tests/test_national.py @@ -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() diff --git a/test-docker-compose.yml b/test-docker-compose.yml index 1870d6a..6838d11 100644 --- a/test-docker-compose.yml +++ b/test-docker-compose.yml @@ -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