linting
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m9s
Run linting on the backend code / Build (pull_request) Successful in 34s
Run testing on the backend code / Build (pull_request) Failing after 1m56s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 17s

This commit is contained in:
Helldragon67 2025-01-10 15:59:44 +01:00
parent c6cebd0fdf
commit 73373e0fc3
9 changed files with 21 additions and 21 deletions

View File

@ -402,7 +402,7 @@ preferred-modules=
# The type of string formatting that logging methods do. `old` means using % # The type of string formatting that logging methods do. `old` means using %
# formatting, `new` is for `{}` formatting. # 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 # Logging modules to check that the string format arguments are in logging
# function parameter format. # function parameter format.

View File

@ -55,4 +55,3 @@ def configure_logging():
logging.getLogger('uvicorn').handlers = logging_handlers logging.getLogger('uvicorn').handlers = logging_handlers
logging.getLogger('uvicorn.access').handlers = logging_handlers logging.getLogger('uvicorn.access').handlers = logging_handlers
logging.getLogger('uvicorn.error').handlers = logging_handlers logging.getLogger('uvicorn.error').handlers = logging_handlers

View File

@ -2,8 +2,8 @@
import logging import logging
import time import time
from fastapi import FastAPI, HTTPException, Query
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, Query
from .logging_config import configure_logging from .logging_config import configure_logging
from .structs.landmark import Landmark, Toilets from .structs.landmark import Landmark, Toilets

View File

@ -138,5 +138,7 @@ class Toilets(BaseModel) :
return f'Toilets @{self.location}' return f'Toilets @{self.location}'
class Config: class Config:
# This allows us to easily convert the model to and from dictionaries """
This allows us to easily convert the model to and from dictionaries
"""
from_attributes = True from_attributes = True

View File

@ -13,7 +13,7 @@ def client():
return TestClient(app) 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. Test n°1 : Custom test in Turckheim to ensure small villages are also supported.

View File

@ -1,9 +1,9 @@
"""Collection of tests to ensure correct implementation and track progress. """ """Collection of tests to ensure correct implementation and track progress. """
import time
from fastapi.testclient import TestClient 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 from ..main import app
@pytest.fixture(scope="module") @pytest.fixture(scope="module")

View File

@ -6,11 +6,13 @@ import pytest
from ..structs.landmark import Toilets from ..structs.landmark import Toilets
from ..main import app from ..main import app
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def client(): def client():
"""Client used to call the app.""" """Client used to call the app."""
return TestClient(app) return TestClient(app)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"location,radius,status_code", "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 assert response.status_code == status_code
@pytest.mark.parametrize( @pytest.mark.parametrize(
"location,status_code", "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()] toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()]
# checks : # 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 isinstance(toilets_list, list) # check that the return type is a list
@pytest.mark.parametrize( @pytest.mark.parametrize(
"location,status_code", "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()] toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()]
# checks : # 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 isinstance(toilets_list, list) # check that the return type is a list
assert len(toilets_list) > 0 assert len(toilets_list) > 0

View File

@ -45,19 +45,19 @@ def fetch_landmark(client, landmark_uuid: str):
logger.info(f'API Response: {json_data}') logger.info(f'API Response: {json_data}')
except ValueError as e: except ValueError as e:
logger.error(f'Failed to parse response as JSON: {response.text}') 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 validating against the Landmark model here to ensure consistency
try: try:
landmark = Landmark(**json_data) landmark = Landmark(**json_data)
except ValidationError as ve: except ValidationError as ve:
logging.error(f'Validation error: {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: if "detail" in json_data:
raise HTTPException(status_code=500, detail=json_data["detail"]) raise HTTPException(status_code=500, detail=json_data["detail"])
return Landmark(**json_data) return landmark
def fetch_landmark_cache(landmark_uuid: str): def fetch_landmark_cache(landmark_uuid: str):