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:
		@@ -1,6 +1,54 @@
 | 
				
			|||||||
from fastapi.testclient import TestClient
 | 
					from fastapi.testclient import TestClient
 | 
				
			||||||
import pytest
 | 
					import pytest, requests
 | 
				
			||||||
from ..main import app
 | 
					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()
 | 
					@pytest.fixture()
 | 
				
			||||||
def client():
 | 
					def client():
 | 
				
			||||||
@@ -17,18 +65,37 @@ def test_new_trip_invalid_prefs(client):
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
    assert response.status_code == 422
 | 
					    assert response.status_code == 422
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_1(client):
 | 
				
			||||||
def test_new_trip_single_prefs(client):
 | 
					 | 
				
			||||||
    response = client.post(
 | 
					    response = client.post(
 | 
				
			||||||
        "/trip/new",
 | 
					        "/trip/new",
 | 
				
			||||||
        json={
 | 
					        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},
 | 
					            "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.8566, 2.3522]
 | 
					            "start": [48.084588, 7.280405]
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    # check for successful planning
 | 
				
			||||||
    assert response.status_code == 200
 | 
					    assert response.status_code == 200
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    result = response.json()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_new_trip_matches_prefs(client):
 | 
					    landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
 | 
				
			||||||
    # todo
 | 
					
 | 
				
			||||||
    pass
 | 
					    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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user