Skip to content

Commit

Permalink
fix(datasets): add missing parameters in url for datasets
Browse files Browse the repository at this point in the history
* Update test
* Update navitiaClient to call datasets as property
  • Loading branch information
jonperron committed Apr 7, 2024
1 parent e69d7b8 commit 0b580e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 8 additions & 4 deletions navitia_client/client/apis/datasets_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ def _get_datasets_from_response(raw_datasets_response: Any) -> Sequence[Dataset]

return datasets

def list_datasets(self) -> Sequence[Dataset]:
results = self.get_navitia_api(f"{self.base_navitia_url}/datasets")
def list_datasets(self, region_id: str) -> Sequence[Dataset]:
results = self.get_navitia_api(
f"{self.base_navitia_url}/coverage/{region_id}/datasets"
)
raw_results = results.json()["datasets"]
return DatasetsApiClient._get_datasets_from_response(raw_results)

def get_dataset_by_id(self, dataset_id: str) -> Sequence[Dataset]:
results = self.get_navitia_api(f"{self.base_navitia_url}/coverage/{dataset_id}")
def get_dataset_by_id(self, region_id: str, dataset_id: str) -> Sequence[Dataset]:
results = self.get_navitia_api(
f"{self.base_navitia_url}/coverage/{region_id}/datasets/{dataset_id}"
)
raw_results = results.json()["datasets"]
return DatasetsApiClient._get_datasets_from_response(raw_results)
8 changes: 8 additions & 0 deletions navitia_client/client/navitia_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from dataclasses import dataclass

from navitia_client.client.apis.coverage_apis import CoverageApiClient
from navitia_client.client.apis.datasets_apis import DatasetsApiClient

BASE_NAVITIA_URL: str = "https://api.navitia.io/v1/"

Expand All @@ -14,3 +16,9 @@ def coverage(self) -> CoverageApiClient:
return CoverageApiClient(
auth_token=self.auth_token, base_navitia_url=self.base_navitia_url
)

@property
def datasets(self) -> DatasetsApiClient:
return DatasetsApiClient(
auth_token=self.auth_token, base_navitia_url=self.base_navitia_url
)
10 changes: 7 additions & 3 deletions tests/client/apis/test_datasets_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_list_covered_areas(
mock_get_navitia_api.return_value = mock_response

# When
datasets = datasets_apis.list_datasets()
datasets = datasets_apis.list_datasets(region_id="bar")

# Then
assert len(datasets) == 1
Expand Down Expand Up @@ -86,7 +86,9 @@ def test_get_region_by_id(
mock_get_navitia_api.return_value = mock_response

# When
datasets = datasets_apis.get_dataset_by_id("foo:foo-piv")
datasets = datasets_apis.get_dataset_by_id(
region_id="bar", dataset_id="foo:foo-piv"
)

# Then
assert len(datasets) == 1
Expand Down Expand Up @@ -114,7 +116,9 @@ def test_get_region_by_id_missing_contributor(
mock_get_navitia_api.return_value = mock_response

# When
datasets = datasets_apis.get_dataset_by_id("foo:foo-piv")
datasets = datasets_apis.get_dataset_by_id(
region_id="bar", dataset_id="foo:foo-piv"
)

# Then
assert len(datasets) == 0

0 comments on commit 0b580e5

Please sign in to comment.