Some checks failed
		
		
	
	Build and deploy the backend to staging / Build and push image (pull_request) Failing after 2m17s
				
			Build and deploy the backend to staging / Deploy to staging (pull_request) Has been skipped
				
			Run linting on the backend code / Build (pull_request) Failing after 30s
				
			Run testing on the backend code / Build (pull_request) Failing after 1m28s
				
			
		
			
				
	
	
		
			63 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""Collection of tests to ensure correct handling of invalid input."""
 | 
						|
 | 
						|
from fastapi.testclient import TestClient
 | 
						|
import pytest
 | 
						|
 | 
						|
from ..main import app
 | 
						|
 | 
						|
 | 
						|
@pytest.fixture(scope="module")
 | 
						|
def invalid_client():
 | 
						|
    """Client used to call the app."""
 | 
						|
    return TestClient(app)
 | 
						|
 | 
						|
 | 
						|
@pytest.mark.parametrize(
 | 
						|
    "start,preferences,status_code",
 | 
						|
    [
 | 
						|
        # Invalid case: no preferences at all.
 | 
						|
        ([48.8566, 2.3522], {}, 422),
 | 
						|
 | 
						|
        # Invalid cases: incomplete preferences.
 | 
						|
        ([48.084588, 7.280405], {"sightseeing": {"type": "nature", "score": 5}, # no shopping
 | 
						|
                                 "nature": {"type": "nature", "score": 5},
 | 
						|
                                 }, 422),
 | 
						|
        ([48.084588, 7.280405], {"sightseeing": {"type": "nature", "score": 5}, # no nature
 | 
						|
                                 "shopping": {"type": "shopping", "score": 5},
 | 
						|
                                 }, 422),
 | 
						|
        ([48.084588, 7.280405], {"nature": {"type": "nature", "score": 5},      # no sightseeing
 | 
						|
                                 "shopping": {"type": "shopping", "score": 5},
 | 
						|
                                 }, 422),
 | 
						|
 | 
						|
        # Invalid cases: unexisting coords
 | 
						|
        ([91, 181], {"sightseeing": {"type": "nature", "score": 5},
 | 
						|
                     "nature": {"type": "nature", "score": 5},
 | 
						|
                     "shopping": {"type": "shopping", "score": 5},
 | 
						|
                    }, 422),
 | 
						|
        ([-91, 181], {"sightseeing": {"type": "nature", "score": 5},
 | 
						|
                     "nature": {"type": "nature", "score": 5},
 | 
						|
                     "shopping": {"type": "shopping", "score": 5},
 | 
						|
                    }, 422),
 | 
						|
        ([91, -181], {"sightseeing": {"type": "nature", "score": 5},
 | 
						|
                     "nature": {"type": "nature", "score": 5},
 | 
						|
                     "shopping": {"type": "shopping", "score": 5},
 | 
						|
                    }, 422),
 | 
						|
        ([-91, -181], {"sightseeing": {"type": "nature", "score": 5},
 | 
						|
                     "nature": {"type": "nature", "score": 5},
 | 
						|
                     "shopping": {"type": "shopping", "score": 5},
 | 
						|
                    }, 422),
 | 
						|
    ]
 | 
						|
)
 | 
						|
def test_input(invalid_client, start, preferences, status_code):   # pylint: disable=redefined-outer-name
 | 
						|
    """
 | 
						|
    Test new trip creation with different sets of preferences and locations.
 | 
						|
    """
 | 
						|
    response = invalid_client.post(
 | 
						|
        "/trip/new",
 | 
						|
        json={
 | 
						|
            "preferences": preferences,
 | 
						|
            "start": start
 | 
						|
        }
 | 
						|
    )
 | 
						|
    assert response.status_code == status_code
 |