diff --git a/CHANGELOG.md b/CHANGELOG.md index 379d593c..70c2c151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ RELEASING: ### Fixed - Delete annotations when plugin is uninstalled ([#346](https://github.com/GIScience/orstools-qgis-plugin/issues/346)) - Reset hand cursor after deactivating line tool ([#342](https://github.com/GIScience/orstools-qgis-plugin/issues/342)) +- Set url slashes correctly with optimization requests in procs ([#347](https://github.com/GIScience/orstools-qgis-plugin/issues/347)) ## [2.0.1] - 2025-06-01 ### Added diff --git a/ORStools/proc/directions_lines_proc.py b/ORStools/proc/directions_lines_proc.py index 4d6436cb..f81b5467 100644 --- a/ORStools/proc/directions_lines_proc.py +++ b/ORStools/proc/directions_lines_proc.py @@ -190,7 +190,7 @@ def processAlgorithm( endpoint = self.get_endpoint_names_from_provider(parameters[self.IN_PROVIDER])[ "optimization" ] - response = ors_client.request(f"{endpoint}/", {}, post_json=params) + response = ors_client.request(f"/{endpoint}/", {}, post_json=params) sink.addFeature( directions_core.get_output_features_optimization( diff --git a/ORStools/proc/directions_points_layer_proc.py b/ORStools/proc/directions_points_layer_proc.py index 41c8d5cf..0f3310eb 100644 --- a/ORStools/proc/directions_points_layer_proc.py +++ b/ORStools/proc/directions_points_layer_proc.py @@ -231,7 +231,7 @@ def sort(f): endpoint = self.get_endpoint_names_from_provider(parameters[self.IN_PROVIDER])[ "optimization" ] - response = ors_client.request(f"{endpoint}/", {}, post_json=params) + response = ors_client.request(f"/{endpoint}/", {}, post_json=params) sink.addFeature( directions_core.get_output_features_optimization( diff --git a/tests/test_proc.py b/tests/test_proc.py index c13fc807..0cbd3c92 100644 --- a/tests/test_proc.py +++ b/tests/test_proc.py @@ -81,6 +81,32 @@ def test_directions_lines(self): feat_length = next(processed_layer.getFeatures()).geometry().length() self.assertTrue(feat_length > 0) + def test_directions_lines_layer_optimize(self): + parameters = { + "INPUT_AVOID_BORDERS": None, + "INPUT_AVOID_COUNTRIES": "", + "INPUT_AVOID_FEATURES": [], + "INPUT_AVOID_POLYGONS": None, + "INPUT_LAYER_FIELD": None, + "INPUT_LINE_LAYER": self.line_layer, + "INPUT_OPTIMIZE": 1, + "INPUT_PREFERENCE": 0, + "INPUT_PROFILE": 0, + "INPUT_PROVIDER": 0, + "INPUT_METRIC": 0, + "LOCATION_TYPE": 0, + "OUTPUT": "TEMPORARY_OUTPUT", + } + + directions = ORSDirectionsLinesAlgo().create() + dest_id = directions.processAlgorithm(parameters, self.context, self.feedback) + processed_layer = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT"], self.context) + + self.assertEqual(type(processed_layer), QgsVectorLayer) + + feat_length = next(processed_layer.getFeatures()).geometry().length() + self.assertTrue(feat_length > 0) + def test_directions_points_layer(self): parameters = { "INPUT_AVOID_BORDERS": None, @@ -108,6 +134,33 @@ def test_directions_points_layer(self): return processed_layer + def test_directions_points_layer_optimization(self): + parameters = { + "INPUT_AVOID_BORDERS": None, + "INPUT_AVOID_COUNTRIES": "", + "INPUT_AVOID_FEATURES": [], + "INPUT_AVOID_POLYGONS": None, + "INPUT_LAYER_FIELD": None, + "INPUT_OPTIMIZE": 1, + "INPUT_POINT_LAYER": self.point_layer_1, + "INPUT_PREFERENCE": 0, + "INPUT_PROFILE": 0, + "INPUT_PROVIDER": 0, + "INPUT_SORTBY": None, + "OUTPUT": "TEMPORARY_OUTPUT", + } + + directions = ORSDirectionsPointsLayerAlgo().create() + dest_id = directions.processAlgorithm(parameters, self.context, self.feedback) + processed_layer = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT"], self.context) + + self.assertEqual(type(processed_layer), QgsVectorLayer) + + feat_length = next(processed_layer.getFeatures()).geometry().length() + self.assertTrue(feat_length > 0) + + return processed_layer + def test_directions_points_layers(self): parameters = { "INPUT_AVOID_BORDERS": None,