Skip to content

Commit

Permalink
TEST: NAV-145 - Add integration test cases for client exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
munterfi committed Aug 19, 2024
1 parent 993bd96 commit 3c3295b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
79 changes: 77 additions & 2 deletions tests/integration/test_integration_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import pytest

from public_transit_client.client import PublicTransitClient
from public_transit_client.model import Connection, StopConnection, TimeType
from public_transit_client.client import (PublicTransitClient,
PublicTransitClientException)
from public_transit_client.model import (Connection, Coordinate,
StopConnection, TimeType)

HOST = "http://localhost:8080"

Expand Down Expand Up @@ -32,6 +34,46 @@ def test_get_connections(client):
assert connections[0].to_stop.id == to_stop


@pytest.mark.integration
def test_get_connections_invalid_stop(client):
from_stop = "INVALID_STOP"
to_stop = "BULLFROG"
departure_time = datetime(2008, 6, 1)

with pytest.raises(PublicTransitClientException) as exc_info:
client.get_connections(
from_stop=from_stop,
to_stop=to_stop,
time=departure_time,
time_type=TimeType.DEPARTURE,
)

assert exc_info.value.api_error.status == 404
assert "'INVALID_STOP' was not found" in exc_info.value.api_error.message


@pytest.mark.integration
def test_get_connections_negative_walking_duration(client):
from_stop = "NANAA"
to_stop = "BULLFROG"
departure_time = datetime(2008, 6, 1)

with pytest.raises(PublicTransitClientException) as exc_info:
client.get_connections(
from_stop=from_stop,
to_stop=to_stop,
time=departure_time,
time_type=TimeType.DEPARTURE,
max_walking_duration=-10,
)

assert exc_info.value.api_error.status == 400
assert (
"Max walking duration must be greater than or equal to 0"
in exc_info.value.api_error.message
)


@pytest.mark.integration
def test_get_isolines(client):
from_stop = "NANAA"
Expand All @@ -50,3 +92,36 @@ def test_get_isolines(client):
assert all(
isinstance(stop_connection, StopConnection) for stop_connection in isolines
)


@pytest.mark.integration
def test_get_isolines_invalid_stop(client):
from_stop = "INVALID_STOP"
departure_time = datetime(2008, 6, 1)

with pytest.raises(PublicTransitClientException) as exc_info:
client.get_isolines(
from_stop=from_stop,
time=departure_time,
time_type=TimeType.DEPARTURE,
max_walking_duration=10,
max_transfer_number=1,
return_connections=True,
)

assert exc_info.value.api_error.status == 404
assert "'INVALID_STOP' was not found" in exc_info.value.api_error.message


@pytest.mark.integration
def test_nearest_stops_invalid_coordinate(client):
invalid_coordinate = Coordinate(latitude=999.0, longitude=999.0)

with pytest.raises(PublicTransitClientException) as exc_info:
client.nearest_stops(coordinate=invalid_coordinate, limit=5, max_distance=500)

assert exc_info.value.api_error.status == 400
assert (
"Latitude must be between -90 and 90 degrees"
in exc_info.value.api_error.message
)
25 changes: 24 additions & 1 deletion tests/integration/test_integration_schedule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from public_transit_client.client import PublicTransitClient
from public_transit_client.client import (PublicTransitClient,
PublicTransitClientException)
from public_transit_client.model import Coordinate, SearchType, Stop

HOST = "http://localhost:8080"
Expand Down Expand Up @@ -31,6 +32,17 @@ def test_nearest_stops(client):
assert all(isinstance(stop.stop, Stop) for stop in stops)


@pytest.mark.integration
def test_nearest_stops_invalid_limit(client):
coordinate = Coordinate(latitude=36, longitude=-116)

with pytest.raises(PublicTransitClientException) as exc_info:
client.nearest_stops(coordinate=coordinate, limit=-1, max_distance=100000)

assert exc_info.value.api_error.status == 400
assert "Limit must be greater than 0" in exc_info.value.api_error.message


@pytest.mark.integration
def test_get_stop(client):
stop_id = "NANAA"
Expand All @@ -39,3 +51,14 @@ def test_get_stop(client):
assert stop is not None
assert isinstance(stop, Stop)
assert stop.id == stop_id


@pytest.mark.integration
def test_get_stop_invalid_stop_id(client):
invalid_stop_id = "INVALID_STOP_ID"

with pytest.raises(PublicTransitClientException) as exc_info:
client.get_stop(stop_id=invalid_stop_id)

assert exc_info.value.api_error.status == 404
assert "'INVALID_STOP_ID' was not found" in exc_info.value.api_error.message

0 comments on commit 3c3295b

Please sign in to comment.