"""Collection of tests to ensure correct implementation and track progress. """ import time from fastapi.testclient import TestClient import pytest from .test_utils import load_trip_landmarks, log_trip_details from ..main import app @pytest.fixture(scope="module") def client(): """Client used to call the app.""" return TestClient(app) def test_turckheim(client, request): # pylint: disable=redefined-outer-name """ Test n°1 : Custom test in Turckheim to ensure small villages are also supported. Args: client: request: """ start_time = time.time() # Start timer duration_minutes = 15 response = client.post( "/trip/new", json={ "preferences": {"sightseeing": {"type": "sightseeing", "score": 5}, "nature": {"type": "nature", "score": 5}, "shopping": {"type": "shopping", "score": 5}, "max_time_minute": duration_minutes, "detour_tolerance_minute": 0}, "start": [48.084588, 7.280405] } ) result = response.json() landmarks = load_trip_landmarks(client, result['first_landmark_uuid']) # Get computation time comp_time = time.time() - start_time # Add details to report log_trip_details(request, landmarks, result['total_time'], duration_minutes) # for elem in landmarks : # print(elem) # checks : assert response.status_code == 200 # check for successful planning assert isinstance(landmarks, list) # check that the return type is a list assert duration_minutes*0.8 < int(result['total_time']) < duration_minutes*1.2 assert len(landmarks) > 2 # check that there is something to visit assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds" # assert 2==3 ''' def test_bellecour(client, request) : # pylint: disable=redefined-outer-name """ Test n°2 : Custom test in Lyon centre to ensure proper decision making in crowded area. Args: client: request: """ start_time = time.time() # Start timer duration_minutes = 120 response = client.post( "/trip/new", json={ "preferences": {"sightseeing": {"type": "sightseeing", "score": 5}, "nature": {"type": "nature", "score": 5}, "shopping": {"type": "shopping", "score": 5}, "max_time_minute": duration_minutes, "detour_tolerance_minute": 0}, "start": [45.7576485, 4.8330241] } ) result = response.json() landmarks = load_trip_landmarks(client, result['first_landmark_uuid']) # Get computation time comp_time = time.time() - start_time # Add details to report log_trip_details(request, landmarks, result['total_time'], duration_minutes) # for elem in landmarks : # print(elem) # checks : assert response.status_code == 200 # check for successful planning assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds" assert duration_minutes*0.8 < int(result['total_time']) < duration_minutes*1.2 # assert 2 == 3 def test_Paris(client, request) : # pylint: disable=redefined-outer-name """ Test n°2 : Custom test in Paris (les Halles) centre to ensure proper decision making in crowded area. Args: client: request: """ start_time = time.time() # Start timer duration_minutes = 300 response = client.post( "/trip/new", json={ "preferences": {"sightseeing": {"type": "sightseeing", "score": 5}, "nature": {"type": "nature", "score": 5}, "shopping": {"type": "shopping", "score": 5}, "max_time_minute": duration_minutes, "detour_tolerance_minute": 0}, "start": [48.86248803298562, 2.346451131285925] } ) result = response.json() landmarks = load_trip_landmarks(client, result['first_landmark_uuid']) # Get computation time comp_time = time.time() - start_time # Add details to report log_trip_details(request, landmarks, result['total_time'], duration_minutes) # for elem in landmarks : # print(elem) # checks : assert response.status_code == 200 # check for successful planning assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds" assert duration_minutes*0.8 < int(result['total_time']) < duration_minutes*1.2 def test_New_York(client, request) : # pylint: disable=redefined-outer-name """ Test n°2 : Custom test in New York (les Halles) centre to ensure proper decision making in crowded area. Args: client: request: """ start_time = time.time() # Start timer duration_minutes = 600 response = client.post( "/trip/new", json={ "preferences": {"sightseeing": {"type": "sightseeing", "score": 5}, "nature": {"type": "nature", "score": 5}, "shopping": {"type": "shopping", "score": 5}, "max_time_minute": duration_minutes, "detour_tolerance_minute": 0}, "start": [40.72592726802, -73.9920434795] } ) result = response.json() landmarks = load_trip_landmarks(client, result['first_landmark_uuid']) # Get computation time comp_time = time.time() - start_time # Add details to report log_trip_details(request, landmarks, result['total_time'], duration_minutes) # for elem in landmarks : # print(elem) # checks : assert response.status_code == 200 # check for successful planning assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds" assert duration_minutes*0.8 < int(result['total_time']) < duration_minutes*1.2 def test_shopping(client, request) : # pylint: disable=redefined-outer-name """ Test n°3 : Custom test in Lyon centre to ensure shopping clusters are found. Args: client: request: """ start_time = time.time() # Start timer duration_minutes = 240 response = client.post( "/trip/new", json={ "preferences": {"sightseeing": {"type": "sightseeing", "score": 0}, "nature": {"type": "nature", "score": 0}, "shopping": {"type": "shopping", "score": 5}, "max_time_minute": duration_minutes, "detour_tolerance_minute": 0}, "start": [45.7576485, 4.8330241] } ) result = response.json() landmarks = load_trip_landmarks(client, result['first_landmark_uuid']) # Get computation time comp_time = time.time() - start_time # Add details to report log_trip_details(request, landmarks, result['total_time'], duration_minutes) # for elem in landmarks : # print(elem) # checks : assert response.status_code == 200 # check for successful planning assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds" assert duration_minutes*0.8 < int(result['total_time']) < duration_minutes*1.2 ''' # def test_new_trip_single_prefs(client): # response = client.post( # "/trip/new", # json={ # "preferences": {"sightseeing": {"type": "sightseeing", "score": 1}, # "nature": {"type": "nature", "score": 1}, # "shopping": {"type": "shopping", "score": 1}, # "max_time_minute": 360, # "detour_tolerance_minute": 0}, # "start": [48.8566, 2.3522] # } # ) # assert response.status_code == 200 # def test_new_trip_matches_prefs(client): # pass