Skip to content

Commit

Permalink
fix(journey): fix support of add_poi_infos
Browse files Browse the repository at this point in the history
Fix issue in PR #63

* Add arg as optionnal (see documentation)
* Update docs
* Add tests to check URL
  • Loading branch information
jonperron committed Jun 15, 2024
1 parent 6b767fc commit d3f0c7c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/api_support/journeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Methods
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -74,7 +74,7 @@ Methods
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -111,7 +111,7 @@ Methods
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down
24 changes: 15 additions & 9 deletions navitia_client/client/apis/journeys_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class JourneyApiClient(ApiBaseClient):
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -79,7 +79,7 @@ class JourneyApiClient(ApiBaseClient):
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -116,7 +116,7 @@ class JourneyApiClient(ApiBaseClient):
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -173,7 +173,7 @@ def list_journeys(
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -274,7 +274,6 @@ def list_journeys(
"max_duration": max_duration,
"wheelchair": wheelchair,
"direct_path": direct_path,
"add_poi_infos[]": add_poi_infos,
"debug": debug,
"free_radius_from": free_radius_from,
"free_radius_to": free_radius_to,
Expand All @@ -299,6 +298,9 @@ def list_journeys(
if last_section_mode:
filters["last_section_mode[]"] = last_section_mode

if add_poi_infos:
filters["add_poi_infos[]"] = add_poi_infos

if any([direct_path_mode, first_section_mode]):
filters["direct_path_mode[]"] = direct_path_mode or first_section_mode

Expand Down Expand Up @@ -333,7 +335,7 @@ def list_journeys_with_region_id(
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -436,7 +438,6 @@ def list_journeys_with_region_id(
"max_duration": max_duration,
"wheelchair": wheelchair,
"direct_path": direct_path,
"add_poi_infos[]": add_poi_infos,
"debug": debug,
"free_radius_from": free_radius_from,
"free_radius_to": free_radius_to,
Expand All @@ -461,6 +462,9 @@ def list_journeys_with_region_id(
if last_section_mode:
filters["last_section_mode[]"] = last_section_mode

if add_poi_infos:
filters["add_poi_infos[]"] = add_poi_infos

if any([direct_path_mode, first_section_mode]):
filters["direct_path_mode[]"] = direct_path_mode or first_section_mode

Expand Down Expand Up @@ -495,7 +499,7 @@ def list_journeys_with_resource_path(
wheelchair: bool = False,
direct_path: str = "indifferent",
direct_path_mode: Optional[Sequence[str]] = None,
add_poi_infos: Sequence[str] = [],
add_poi_infos: Optional[Sequence[str]] = None,
debug: bool = False,
free_radius_from: int = 0,
free_radius_to: int = 0,
Expand Down Expand Up @@ -598,7 +602,6 @@ def list_journeys_with_resource_path(
"max_duration": max_duration,
"wheelchair": wheelchair,
"direct_path": direct_path,
"add_poi_infos[]": add_poi_infos,
"debug": debug,
"free_radius_from": free_radius_from,
"free_radius_to": free_radius_to,
Expand All @@ -623,6 +626,9 @@ def list_journeys_with_resource_path(
if last_section_mode:
filters["last_section_mode[]"] = last_section_mode

if add_poi_infos:
filters["add_poi_infos[]"] = add_poi_infos

if any([direct_path_mode, first_section_mode]):
filters["direct_path_mode[]"] = direct_path_mode or first_section_mode

Expand Down
43 changes: 43 additions & 0 deletions tests/client/apis/test_journeys_apis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import json
from unittest.mock import MagicMock, patch

Expand Down Expand Up @@ -69,3 +70,45 @@ def test_list_covered_areas(
# Then
assert len(journeys) == 1
assert isinstance(journeys[0], Journey)


@patch.object(JourneyApiClient, "get_navitia_api")
def test_list_empty_add_poi_infos_parameter(
mock_get_navitia_api: MagicMock, journeys_apis: JourneyApiClient
) -> None:
# Given
mock_response = MagicMock()
with open("tests/test_data/journeys.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response
expected_url = "https://api.navitia.io/v1//journeys?datetime=2024-06-01T00:00:00&datetime_represents=departure&traveler_type=standard&data_freshness=realtime&language=en-GB&depth=1&max_duration_to_pt=1800&walking_speed=1.12&bike_speed=4.1&bss_speed=4.1&car_speed=16.8&min_nb_journeys=1&max_nb_journeys=1&count=1&max_nb_transfers=10&min_nb_transfers=0&max_duration=86400&wheelchair=False&direct_path=indifferent&debug=False&free_radius_from=0&free_radius_to=0&timeframe_duration=0&from=foo"

# When
journeys_apis.list_journeys(datetime_=datetime(2024, 6, 1), from_="foo")

# Then
mock_get_navitia_api.assert_called_with(expected_url)


@patch.object(JourneyApiClient, "get_navitia_api")
def test_list_add_poi_infos_parameter(
mock_get_navitia_api: MagicMock, journeys_apis: JourneyApiClient
) -> None:
# Given
mock_response = MagicMock()
with open("tests/test_data/journeys.json", encoding="utf-8") as file:
mock_response.json.return_value = json.load(file)

mock_get_navitia_api.return_value = mock_response
expected_url = "https://api.navitia.io/v1//journeys?datetime=2024-06-01T00:00:00&datetime_represents=departure&traveler_type=standard&data_freshness=realtime&language=en-GB&depth=1&max_duration_to_pt=1800&walking_speed=1.12&bike_speed=4.1&bss_speed=4.1&car_speed=16.8&min_nb_journeys=1&max_nb_journeys=1&count=1&max_nb_transfers=10&min_nb_transfers=0&max_duration=86400&wheelchair=False&direct_path=indifferent&debug=False&free_radius_from=0&free_radius_to=0&timeframe_duration=0&from=foo&add_poi_infos[]=bss_stands&add_poi_infos[]=car_parks"

# When
journeys_apis.list_journeys(
datetime_=datetime(2024, 6, 1),
from_="foo",
add_poi_infos=["bss_stands", "car_parks"],
)

# Then
mock_get_navitia_api.assert_called_with(expected_url)

0 comments on commit d3f0c7c

Please sign in to comment.