Skip to content

Commit

Permalink
Merge pull request #17 from naviqore/bugfix/routing-from-coordinate-a…
Browse files Browse the repository at this point in the history
…nd-tuple

Bugfix/routing from coordinate and tuple
  • Loading branch information
clukas1 authored Oct 3, 2024
2 parents 388e6ac + 1bf95a3 commit d46de4d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
10 changes: 5 additions & 5 deletions public_transit_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
Coordinate,
Departure,
DistanceToStop,
QueryConfig,
RouterInfo,
ScheduleInfo,
SearchType,
Stop,
StopConnection,
TimeType,
QueryConfig,
ScheduleInfo,
RouterInfo,
)

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -252,14 +252,14 @@ def _build_params_dict(
),
}

if source is isinstance(source, tuple):
if isinstance(source, tuple):
params["sourceLatitude"] = str(source[0])
params["sourceLongitude"] = str(source[1])
elif isinstance(source, str):
params["sourceStopId"] = source

if target is not None:
if target is isinstance(target, tuple):
if isinstance(target, tuple):
params["targetLatitude"] = str(target[0])
params["targetLongitude"] = str(target[1])
elif isinstance(target, str):
Expand Down
2 changes: 1 addition & 1 deletion public_transit_client/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, date
from datetime import date, datetime
from enum import Enum
from itertools import pairwise

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "public-transit-client"
version = "1.0.0"
version = "1.0.1"
description = "Client to access the public transit service API endpoints."
authors = [
"Lukas Connolly <lukas@connolly.ch>",
Expand Down
44 changes: 40 additions & 4 deletions tests/integration/test_integration_routing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, date
from datetime import date, datetime

import pytest

Expand All @@ -9,12 +9,12 @@
from public_transit_client.model import (
Connection,
Coordinate,
StopConnection,
TimeType,
QueryConfig,
TransportMode,
RouterInfo,
ScheduleInfo,
StopConnection,
TimeType,
TransportMode,
)

HOST = "http://localhost:8080"
Expand Down Expand Up @@ -70,6 +70,42 @@ def test_get_connections(client):
assert connections[0].to_stop.id == to_stop


@pytest.mark.integration
def test_get_connections_coordinates(client):
from_coordinate = Coordinate(latitude=36.914, longitude=-116.761)
to_coordinate = Coordinate(latitude=36.881, longitude=-116.817)
departure_time = datetime(2008, 6, 1)
connections = client.get_connections(
source=from_coordinate,
target=to_coordinate,
time=departure_time,
time_type=TimeType.DEPARTURE,
)

assert isinstance(connections, list)
assert len(connections) > 0
assert all(isinstance(connection, Connection) for connection in connections)
assert connections[0].from_coordinate == from_coordinate
assert connections[0].to_coordinate == to_coordinate


@pytest.mark.integration
def test_get_connections_coordinate_tuples(client):
from_coordinate = (36.914, -116.761)
to_coordinate = (36.881, -116.817)
departure_time = datetime(2008, 6, 1)
connections = client.get_connections(
source=from_coordinate,
target=to_coordinate,
time=departure_time,
time_type=TimeType.DEPARTURE,
)

assert isinstance(connections, list)
assert len(connections) > 0
assert all(isinstance(connection, Connection) for connection in connections)


@pytest.mark.integration
def test_get_connections_invalid_stop(client):
from_stop = "INVALID_STOP"
Expand Down

0 comments on commit d46de4d

Please sign in to comment.