second test is working
Some checks failed
Build and push docker image / Build (pull_request) Successful in 1m36s
Run linting on the backend code / Build (pull_request) Failing after 24s
Run testing on the backend code / Build (pull_request) Failing after 50s
Build and release APK / Build APK (pull_request) Successful in 4m56s
Some checks failed
Build and push docker image / Build (pull_request) Successful in 1m36s
Run linting on the backend code / Build (pull_request) Failing after 24s
Run testing on the backend code / Build (pull_request) Failing after 50s
Build and release APK / Build APK (pull_request) Successful in 4m56s
This commit is contained in:
parent
bdb040b756
commit
5b5d895100
@ -3,6 +3,23 @@ import pytest, requests
|
||||
from ..main import app
|
||||
from ..structs.landmark import Landmark
|
||||
|
||||
|
||||
def landmarks_to_osmid(landmarks: list) -> list :
|
||||
"""
|
||||
Convert the list of landmarks into a list containing their osm ids for quick landmark checking.
|
||||
|
||||
Args :
|
||||
landmarks (list): the list of landmarks
|
||||
|
||||
Returns :
|
||||
ids (list) : the list of corresponding OSM ids
|
||||
"""
|
||||
ids = []
|
||||
for landmark in landmarks :
|
||||
ids.append(landmark.osm_id)
|
||||
|
||||
return ids
|
||||
|
||||
def fetch_landmark(client, landmark_uuid):
|
||||
"""
|
||||
Fetch landmark data from the API based on the landmark UUID.
|
||||
@ -31,24 +48,19 @@ def load_trip_landmarks(client, first_uuid):
|
||||
Load all landmarks for a trip using the response from the API.
|
||||
|
||||
Args:
|
||||
first_uuid (str): The first UUID of the landmark.
|
||||
first_uuid (str) : The first UUID of the landmark.
|
||||
|
||||
Returns:
|
||||
LinkedLandmarks: An object containing all linked landmarks for the trip.
|
||||
landmarks (list) : An list containing all landmarks for the trip.
|
||||
"""
|
||||
landmarks = []
|
||||
next_uuid = first_uuid
|
||||
|
||||
i = 0
|
||||
|
||||
while next_uuid is not None:
|
||||
landmark_data = fetch_landmark(client, next_uuid)
|
||||
landmarks.append(Landmark(**landmark_data)) # Create Landmark objects
|
||||
next_uuid = landmark_data.get('next_uuid') # Prepare for the next iteration
|
||||
|
||||
# Prepare for the next iteration
|
||||
next_uuid = landmark_data.get('next_uuid') # Assuming landmark data contains 'next_uuid'
|
||||
|
||||
# Create and return a LinkedLandmarks object with the collected landmarks
|
||||
return landmarks
|
||||
|
||||
|
||||
@ -57,6 +69,7 @@ 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):
|
||||
response = client.post(
|
||||
"/trip/new",
|
||||
@ -67,7 +80,9 @@ def test_new_trip_invalid_prefs(client):
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_1(client):
|
||||
|
||||
# Test no. 1
|
||||
def test_turckheim(client):
|
||||
response = client.post(
|
||||
"/trip/new",
|
||||
json={
|
||||
@ -75,16 +90,29 @@ def test_1(client):
|
||||
"start": [48.084588, 7.280405]
|
||||
}
|
||||
)
|
||||
|
||||
# check for successful planning
|
||||
assert response.status_code == 200
|
||||
|
||||
result = response.json()
|
||||
|
||||
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
|
||||
|
||||
assert isinstance(landmarks, list)
|
||||
assert len(landmarks) > 2
|
||||
# checks :
|
||||
assert response.status_code == 200 # check for successful planning
|
||||
assert isinstance(landmarks, list) # check that the return type is a list
|
||||
assert len(landmarks) > 2 # check that there is something to visit
|
||||
|
||||
def test_bellecour(client) :
|
||||
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": 35, "detour_tolerance_minute": 0},
|
||||
"start": [45.7576485, 4.8330241]
|
||||
}
|
||||
)
|
||||
result = response.json()
|
||||
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
|
||||
osm_ids = landmarks_to_osmid(landmarks)
|
||||
|
||||
# checks :
|
||||
assert response.status_code == 200 # check for successful planning
|
||||
assert 136200148 in osm_ids # check for Cathédrale St. Jean in trip
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user