backend/new-overpass #52
| @@ -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. | ||||||
|   | |||||||
| @@ -70,6 +70,6 @@ else: | |||||||
|         MEMCACHED_HOST_PATH, |         MEMCACHED_HOST_PATH, | ||||||
|         timeout=1, |         timeout=1, | ||||||
|         allow_unicode_keys=True, |         allow_unicode_keys=True, | ||||||
|         encoding='utf-8',  |         encoding='utf-8', | ||||||
|         serde=serde.pickle_serde |         serde=serde.pickle_serde | ||||||
|     ) |     ) | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ def configure_logging(): | |||||||
|         loki_url = "http://localhost:3100/loki/api/v1/push" |         loki_url = "http://localhost:3100/loki/api/v1/push" | ||||||
|         if loki_url is None: |         if loki_url is None: | ||||||
|             raise ValueError("LOKI_URL environment variable is not set") |             raise ValueError("LOKI_URL environment variable is not set") | ||||||
|          |  | ||||||
|         loki_handler = LokiLoggerHandler( |         loki_handler = LokiLoggerHandler( | ||||||
|             url = loki_url, |             url = loki_url, | ||||||
|             labels = {'app': 'anyway', 'environment': 'staging' if is_debug else 'production'} |             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').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 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -136,7 +136,9 @@ class Toilets(BaseModel) : | |||||||
|             str: A formatted string with the toilets location. |             str: A formatted string with the toilets location. | ||||||
|         """ |         """ | ||||||
|         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 |         """ | ||||||
|         from_attributes = True |         This allows us to easily convert the model to and from dictionaries | ||||||
|  |         """ | ||||||
|  |         from_attributes = True | ||||||
|   | |||||||
| @@ -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. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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") | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user