first test
Some checks failed
Build and push docker image / Build (pull_request) Successful in 1m27s
Run linting on the backend code / Build (pull_request) Failing after 24s
Run testing on the backend code / Build (pull_request) Failing after 57s
Build and release APK / Build APK (pull_request) Successful in 6m20s
Some checks failed
Build and push docker image / Build (pull_request) Successful in 1m27s
Run linting on the backend code / Build (pull_request) Failing after 24s
Run testing on the backend code / Build (pull_request) Failing after 57s
Build and release APK / Build APK (pull_request) Successful in 6m20s
This commit is contained in:
parent
e5a1af09cf
commit
1075e85d6b
@ -1,6 +1,54 @@
|
||||
from fastapi.testclient import TestClient
|
||||
import pytest
|
||||
import pytest, requests
|
||||
from ..main import app
|
||||
from ..structs.landmark import Landmark
|
||||
|
||||
def fetch_landmark(client, landmark_uuid):
|
||||
"""
|
||||
Fetch landmark data from the API based on the landmark UUID.
|
||||
|
||||
Args:
|
||||
landmark_uuid (str): The UUID of the landmark.
|
||||
|
||||
Returns:
|
||||
dict: Landmark data fetched from the API.
|
||||
"""
|
||||
response = client.get(f"/landmark/{landmark_uuid}")
|
||||
|
||||
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
|
||||
|
||||
|
||||
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.
|
||||
|
||||
Returns:
|
||||
LinkedLandmarks: An object containing all linked landmarks for the trip.
|
||||
"""
|
||||
landmarks = []
|
||||
next_uuid = first_uuid
|
||||
|
||||
while next_uuid is not None:
|
||||
landmark_data = fetch_landmark(next_uuid)
|
||||
landmarks.append(Landmark(**landmark_data)) # Create Landmark objects
|
||||
|
||||
# Prepare for the next iteration
|
||||
next_uuid = landmark_data.get(client, 'next_uuid') # Assuming landmark data contains 'next_uuid'
|
||||
|
||||
# Create and return a LinkedLandmarks object with the collected landmarks
|
||||
return landmarks
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client():
|
||||
@ -17,18 +65,37 @@ def test_new_trip_invalid_prefs(client):
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_new_trip_single_prefs(client):
|
||||
def test_1(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]
|
||||
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5}, "nature": {"type": "nature", "score": 5}, "shopping": {"type": "shopping", "score": 5}, "max_time_minute": 15, "detour_tolerance_minute": 0},
|
||||
"start": [48.084588, 7.280405]
|
||||
}
|
||||
)
|
||||
|
||||
# check for successful planning
|
||||
assert response.status_code == 200
|
||||
|
||||
result = response.json()
|
||||
|
||||
def test_new_trip_matches_prefs(client):
|
||||
# todo
|
||||
pass
|
||||
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
|
||||
|
||||
assert isinstance(landmarks, list)
|
||||
|
||||
|
||||
|
||||
# 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):
|
||||
# # todo
|
||||
# pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user