diff --git a/navitia_client/client/apis/datasets_apis.py b/navitia_client/client/apis/datasets_apis.py index fdb012d..178659a 100644 --- a/navitia_client/client/apis/datasets_apis.py +++ b/navitia_client/client/apis/datasets_apis.py @@ -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) diff --git a/navitia_client/client/navitia_client.py b/navitia_client/client/navitia_client.py index 51f2ac1..fbc74a0 100644 --- a/navitia_client/client/navitia_client.py +++ b/navitia_client/client/navitia_client.py @@ -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/" @@ -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 + ) diff --git a/tests/client/apis/test_datasets_apis.py b/tests/client/apis/test_datasets_apis.py index 091adb6..3637f20 100644 --- a/tests/client/apis/test_datasets_apis.py +++ b/tests/client/apis/test_datasets_apis.py @@ -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 @@ -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 @@ -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