Skip to content

Commit

Permalink
Merge pull request #104 from geoadmin/bug-BGDIINF_SB-2381-203
Browse files Browse the repository at this point in the history
BGDIINF_SB-2381: Return 203 when we have more points than expected.
  • Loading branch information
ltshb authored May 6, 2022
2 parents fad34af + eeea6aa commit 16ee2bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
6 changes: 3 additions & 3 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ def _get_profile(output_to_json):

# If profile calculation resulted in a lower number of point than requested (because there's no
# need to add points closer to each other than the min resolution of 2m), we return HTTP 203 to
# notify that nb_points couldn't be match.
# notify that nb_points couldn't be match. Smartfilling can result in more points as expected.
status_code = 200
if output_to_json and is_custom_nb_points and len(result) < nb_points:
if output_to_json and is_custom_nb_points and len(result) != nb_points:
status_code = 203
elif not output_to_json and is_custom_nb_points and len(result['rows']) < nb_points:
elif not output_to_json and is_custom_nb_points and len(result['rows']) != nb_points:
status_code = 203

return result, status_code
Expand Down
31 changes: 23 additions & 8 deletions tests/unit_tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,18 @@ def test_profile_lv03_json_wrong_shape(self, mock_georaster_utils):
self.assert_response_contains(resp, 'geom parameter must be a LineString/Point GEOJSON')

@patch('app.routes.georaster_utils')
def test_profile_lv03_json_nb_points(self, mock_georaster_utils):
def test_profile_lv03_json_small_line(self, mock_georaster_utils):

resp = self.prepare_mock_and_test_json_profile(
mock_georaster_utils=mock_georaster_utils,
params={'geom': LINESTRING_SMALL_LINE_LV03},
expected_status=200
)
self.assertEqual(resp.content_type, 'application/json')
self.assertLessEqual(len(resp.json), PROFILE_DEFAULT_AMOUNT_POINTS)

@patch('app.routes.georaster_utils')
def test_profile_lv03_json_nb_points_smart_filling(self, mock_georaster_utils):
# as 150 is too much for this profile (distance between points will be smaller than 2m
# resolution of the altitude model), the service will return 203 and a smaller amount of
# points
Expand All @@ -236,29 +247,33 @@ def test_profile_lv03_json_nb_points(self, mock_georaster_utils):
expected_status=203
)
self.assertEqual(resp.content_type, 'application/json')
self.assertNotEqual(len(resp.json), 150)
self.assertLessEqual(len(resp.json), 150)

@patch('app.routes.georaster_utils')
def test_profile_lv03_json_simplify_linestring(self, mock_georaster_utils):
def test_profile_lv03_json_fewer_nb_points_as_input_point(self, mock_georaster_utils):
input_points = 4
resp = self.prepare_mock_and_test_json_profile(
mock_georaster_utils=mock_georaster_utils,
params={
'geom': create_json(4, 21781), 'nb_points': '2'
'geom': create_json(input_points, 21781), 'nb_points': '2'
},
expected_status=200
expected_status=203
)
self.assertEqual(resp.content_type, 'application/json')
self.assertEqual(len(resp.json), input_points)

@patch('app.routes.georaster_utils')
def test_profile_lv03_json_nb_points_smart_filling(self, mock_georaster_utils):
def test_profile_lv03_json_only_input_point(self, mock_georaster_utils):
input_points = 4
resp = self.prepare_mock_and_test_json_profile(
mock_georaster_utils=mock_georaster_utils,
params={
'geom': LINESTRING_SMALL_LINE_LV03, 'smart_filling': True, 'nbPoints': '150'
'geom': create_json(input_points, 21781), 'only_requested_points': True
},
expected_status=203
expected_status=200
)
self.assertEqual(resp.content_type, 'application/json')
self.assertEqual(len(resp.json), input_points)

@patch('app.routes.georaster_utils')
def test_profile_lv03_json_nb_points_wrong(self, mock_georaster_utils):
Expand Down

0 comments on commit 16ee2bc

Please sign in to comment.