Skip to content

Commit

Permalink
Merge pull request #110 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v1.3.1 - #patch
  • Loading branch information
ltshb authored May 9, 2022
2 parents ea63919 + 6911d28 commit a0b693e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/helpers/validation/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ def read_number_points():
else:
nb_points = PROFILE_DEFAULT_AMOUNT_POINTS

if (isinstance(nb_points, int) or nb_points.isdigit()) and int(nb_points) <= 1:
try:
nb_points = int(nb_points)
except ValueError:
abort(400, "Please provide a numerical value for the parameter 'NbPoints'/'nb_points'")

if nb_points <= 1:
abort(
400,
"Please provide a numerical value for the parameter 'NbPoints'/'nb_points' greater "
"or equal to 2"
)
if (isinstance(nb_points, int) or
nb_points.isdigit()) and int(nb_points) <= PROFILE_MAX_AMOUNT_POINTS:
nb_points = int(nb_points)
else:
if nb_points > PROFILE_MAX_AMOUNT_POINTS:
abort(
400,
"Please provide a numerical value for the parameter 'NbPoints'/'nb_points'"
Expand Down
35 changes: 34 additions & 1 deletion tests/unit_tests/test_profile_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_profile_validation_nb_points_too_big(self, mock_georaster_utils):
self.assert_response(response, expected_status=400)

@patch('app.routes.georaster_utils')
def test_profile_validation_nb_points_not_int(self, mock_georaster_utils):
def test_profile_validation_invalid_nb_points(self, mock_georaster_utils):
response = self.prepare_mock_and_test(
linestring=create_json(2),
spatial_reference=VALID_SPATIAL_REFERENCES[0],
Expand All @@ -174,6 +174,39 @@ def test_profile_validation_nb_points_not_int(self, mock_georaster_utils):
mock_georaster_utils=mock_georaster_utils
)
self.assert_response(response, expected_status=400)
self.assertEqual(
response.json['error']['message'],
'Please provide a numerical value for the parameter '
"'NbPoints'/'nb_points'"
)

response = self.prepare_mock_and_test(
linestring=create_json(2),
spatial_reference=VALID_SPATIAL_REFERENCES[0],
nb_points=0,
offset=VALID_OFFSET,
mock_georaster_utils=mock_georaster_utils
)
self.assert_response(response, expected_status=400)
self.assertEqual(
response.json['error']['message'],
'Please provide a numerical value for the parameter '
"'NbPoints'/'nb_points' greater or equal to 2"
)

response = self.prepare_mock_and_test(
linestring=create_json(2),
spatial_reference=VALID_SPATIAL_REFERENCES[0],
nb_points=-1,
offset=VALID_OFFSET,
mock_georaster_utils=mock_georaster_utils
)
self.assert_response(response, expected_status=400)
self.assertEqual(
response.json['error']['message'],
'Please provide a numerical value for the parameter '
"'NbPoints'/'nb_points' greater or equal to 2"
)

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

0 comments on commit a0b693e

Please sign in to comment.