Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m31s
Run linting on the backend code / Build (pull_request) Successful in 28s
Run testing on the backend code / Build (pull_request) Failing after 3m58s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 23s
346 lines
13 KiB
Python
346 lines
13 KiB
Python
"""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 = 20
|
|
|
|
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, f"Trip duration not within 20\% of desired length"
|
|
assert len(landmarks) > 2 # check that there is something to visit
|
|
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
# 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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
|
|
|
|
def test_cologne(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 = 240
|
|
|
|
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": [50.942352665, 6.957777972392]
|
|
}
|
|
)
|
|
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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
|
|
|
|
def test_strasbourg(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 = 180
|
|
|
|
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.5846589226, 7.74078715721]
|
|
}
|
|
)
|
|
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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
|
|
|
|
def test_zurich(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 = 180
|
|
|
|
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": [47.377884227, 8.5395114066]
|
|
}
|
|
)
|
|
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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
|
|
|
|
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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
|
|
|
|
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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|
|
|
|
|
|
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 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
|
|
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
|