first pylint correction
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m26s
Run linting on the backend code / Build (pull_request) Failing after 30s
Run testing on the backend code / Build (pull_request) Successful in 2m12s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 15s

This commit is contained in:
2024-11-22 11:55:25 +01:00
parent 1b955f249e
commit 4f169c483e
12 changed files with 237 additions and 118 deletions

View File

@@ -1,6 +1,9 @@
from fastapi.testclient import TestClient
"""Collection of tests to ensure correct implementation and track progress. """
from typing import List
from fastapi.testclient import TestClient
import pytest
from ..main import app
from ..structs.landmark import Landmark
@@ -10,8 +13,13 @@ def client():
return TestClient(app)
# Base test for checking if the API returns correct error code when no preferences are specified.
def test_new_trip_invalid_prefs(client):
"""
Test n°1 : base test for checking if the API returns correct error code when no preferences are specified.
Args:
client:
"""
response = client.post(
"/trip/new",
json={
@@ -21,9 +29,15 @@ def test_new_trip_invalid_prefs(client):
)
assert response.status_code == 422
# Test no. 2
def test_turckheim(client, request):
"""
Test n°2 : Custom test in Turckheim to ensure small villages are also supported.
Args:
client:
request:
"""
duration_minutes = 15
response = client.post(
"/trip/new",
@@ -47,6 +61,13 @@ def test_turckheim(client, request):
# Test no. 3
def test_bellecour(client, request) :
"""
Test n°3 : Custom test in Lyon centre to ensure proper decision making in crowded area.
Args:
client:
request:
"""
duration_minutes = 60
response = client.post(
"/trip/new",
@@ -99,12 +120,12 @@ def fetch_landmark(client, landmark_uuid: str):
if response.status_code != 200:
raise Exception(f"Failed to fetch landmark with UUID {landmark_uuid}: {response.status_code}")
json_data = response.json()
if "detail" in json_data:
raise Exception(json_data["detail"])
return json_data
@@ -135,10 +156,17 @@ def load_trip_landmarks(client, first_uuid: str) -> List[Landmark]:
def log_trip_details(request, landmarks: List[Landmark], duration: int, target_duration: int) :
# Create the trip string
trip_string = [f"{landmark.name} ({landmark.attractiveness} | {landmark.duration}) - {landmark.time_to_reach_next}" for landmark in landmarks]
"""
Allows to show the detailed trip in the html test report.
Args:
request:
landmarks (list): the ordered list of visited landmarks
duration (int): the total duration of this trip
target_duration(int): the target duration of this trip
"""
trip_string = [f"{landmark.name} ({landmark.attractiveness} | {landmark.duration}) - {landmark.time_to_reach_next}" for landmark in landmarks]
# Pass additional info to pytest for reporting
request.node.trip_details = trip_string
request.node.trip_duration = str(duration) # result['total_time']