diff --git a/backend/.pylintrc b/backend/.pylintrc index db084dd..706cf02 100644 --- a/backend/.pylintrc +++ b/backend/.pylintrc @@ -402,7 +402,7 @@ preferred-modules= # The type of string formatting that logging methods do. `old` means using % # formatting, `new` is for `{}` formatting. -logging-format-style=old +logging-format-style=new # Logging modules to check that the string format arguments are in logging # function parameter format. diff --git a/backend/src/cache.py b/backend/src/cache.py index 97f9bb7..dffc222 100644 --- a/backend/src/cache.py +++ b/backend/src/cache.py @@ -70,6 +70,6 @@ else: MEMCACHED_HOST_PATH, timeout=1, allow_unicode_keys=True, - encoding='utf-8', + encoding='utf-8', serde=serde.pickle_serde ) diff --git a/backend/src/logging_config.py b/backend/src/logging_config.py index c43a246..c59d6d3 100644 --- a/backend/src/logging_config.py +++ b/backend/src/logging_config.py @@ -22,7 +22,7 @@ def configure_logging(): loki_url = "http://localhost:3100/loki/api/v1/push" if loki_url is None: raise ValueError("LOKI_URL environment variable is not set") - + loki_handler = LokiLoggerHandler( url = loki_url, labels = {'app': 'anyway', 'environment': 'staging' if is_debug else 'production'} @@ -55,4 +55,3 @@ def configure_logging(): logging.getLogger('uvicorn').handlers = logging_handlers logging.getLogger('uvicorn.access').handlers = logging_handlers logging.getLogger('uvicorn.error').handlers = logging_handlers - diff --git a/backend/src/main.py b/backend/src/main.py index b1c865b..b7f796c 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -2,8 +2,8 @@ import logging import time -from fastapi import FastAPI, HTTPException, Query from contextlib import asynccontextmanager +from fastapi import FastAPI, HTTPException, Query from .logging_config import configure_logging from .structs.landmark import Landmark, Toilets diff --git a/backend/src/structs/landmark.py b/backend/src/structs/landmark.py index da0f122..b320f49 100644 --- a/backend/src/structs/landmark.py +++ b/backend/src/structs/landmark.py @@ -136,7 +136,9 @@ class Toilets(BaseModel) : str: A formatted string with the toilets location. """ return f'Toilets @{self.location}' - + class Config: - # This allows us to easily convert the model to and from dictionaries - from_attributes = True \ No newline at end of file + """ + This allows us to easily convert the model to and from dictionaries + """ + from_attributes = True diff --git a/backend/src/tests/test_cache.py b/backend/src/tests/test_cache.py index d2cfaca..6994a6c 100644 --- a/backend/src/tests/test_cache.py +++ b/backend/src/tests/test_cache.py @@ -13,7 +13,7 @@ def client(): return TestClient(app) -def test_cache(client, request): # pylint: disable=redefined-outer-name +def test_cache(client): # pylint: disable=redefined-outer-name """ Test n°1 : Custom test in Turckheim to ensure small villages are also supported. diff --git a/backend/src/tests/test_main.py b/backend/src/tests/test_main.py index 0759f1e..c2e49cf 100644 --- a/backend/src/tests/test_main.py +++ b/backend/src/tests/test_main.py @@ -1,9 +1,9 @@ """Collection of tests to ensure correct implementation and track progress. """ - +import time from fastapi.testclient import TestClient -import pytest, time +import pytest -from .test_utils import landmarks_to_osmid, load_trip_landmarks, log_trip_details +from .test_utils import load_trip_landmarks, log_trip_details from ..main import app @pytest.fixture(scope="module") diff --git a/backend/src/tests/test_toilets.py b/backend/src/tests/test_toilets.py index 29d9f06..90ea5ea 100644 --- a/backend/src/tests/test_toilets.py +++ b/backend/src/tests/test_toilets.py @@ -6,11 +6,13 @@ import pytest from ..structs.landmark import Toilets from ..main import app + @pytest.fixture(scope="module") def client(): """Client used to call the app.""" return TestClient(app) + @pytest.mark.parametrize( "location,radius,status_code", [ @@ -39,8 +41,6 @@ def test_invalid_input(client, location, radius, status_code): # pylint: disa assert response.status_code == status_code - - @pytest.mark.parametrize( "location,status_code", [ @@ -66,11 +66,10 @@ def test_no_toilets(client, location, status_code): # pylint: disable=redefin toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()] # checks : - assert response.status_code == 200 # check for successful planning + assert response.status_code == status_code # check for successful planning assert isinstance(toilets_list, list) # check that the return type is a list - @pytest.mark.parametrize( "location,status_code", [ @@ -97,6 +96,6 @@ def test_toilets(client, location, status_code): # pylint: disable=redefined- toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()] # checks : - assert response.status_code == 200 # check for successful planning + assert response.status_code == status_code # check for successful planning assert isinstance(toilets_list, list) # check that the return type is a list - assert len(toilets_list) > 0 \ No newline at end of file + assert len(toilets_list) > 0 diff --git a/backend/src/tests/test_utils.py b/backend/src/tests/test_utils.py index 2f266ce..68d4fb8 100644 --- a/backend/src/tests/test_utils.py +++ b/backend/src/tests/test_utils.py @@ -45,19 +45,19 @@ def fetch_landmark(client, landmark_uuid: str): logger.info(f'API Response: {json_data}') except ValueError as e: logger.error(f'Failed to parse response as JSON: {response.text}') - raise HTTPException(status_code=500, detail="Invalid response format from API") + raise HTTPException(status_code=500, detail="Invalid response format from API") from e # Try validating against the Landmark model here to ensure consistency try: landmark = Landmark(**json_data) except ValidationError as ve: logging.error(f'Validation error: {ve}') - raise HTTPException(status_code=500, detail="Invalid data format received from API") + raise HTTPException(status_code=500, detail="Invalid data format received from API") from ve if "detail" in json_data: raise HTTPException(status_code=500, detail=json_data["detail"]) - return Landmark(**json_data) + return landmark def fetch_landmark_cache(landmark_uuid: str):