diff --git a/fittrackee/tests/workouts/test_workouts_api_0_get.py b/fittrackee/tests/workouts/test_workouts_api_0_get.py index cafcb620..b6d708e7 100644 --- a/fittrackee/tests/workouts/test_workouts_api_0_get.py +++ b/fittrackee/tests/workouts/test_workouts_api_0_get.py @@ -1158,6 +1158,27 @@ class TestGetWorkout(ApiTestCaseMixin): self.assert_404_with_message(response, 'Map does not exist') + def test_it_returns_404_if_map_file_not_found( + self, + app: Flask, + user_1: User, + sport_1_cycling: Sport, + workout_cycling_user_1: Workout, + ) -> None: + map_ip = self.random_string() + workout_cycling_user_1.map = self.random_string() + workout_cycling_user_1.map_id = map_ip + client, auth_token = self.get_test_client_and_auth_token( + app, user_1.email + ) + + response = client.get( + f'/api/workouts/map/{map_ip}', + headers=dict(Authorization=f'Bearer {auth_token}'), + ) + + self.assert_404_with_message(response, 'Map file does not exist') + class TestDownloadWorkoutGpx(ApiTestCaseMixin): def test_it_returns_404_if_workout_does_not_exist( diff --git a/fittrackee/tests/workouts/test_workouts_api_1_post.py b/fittrackee/tests/workouts/test_workouts_api_1_post.py index f75320ec..6a8c73eb 100644 --- a/fittrackee/tests/workouts/test_workouts_api_1_post.py +++ b/fittrackee/tests/workouts/test_workouts_api_1_post.py @@ -10,7 +10,6 @@ from flask import Flask from fittrackee.users.models import User from fittrackee.workouts.models import Sport, Workout -from fittrackee.workouts.utils.short_id import decode_short_id from ..mixins import ApiTestCaseMixin, CallArgsMixin @@ -974,23 +973,6 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin): ) assert response.status_code == 200 - # error case in the same test to avoid generate a new map file - workout_uuid = decode_short_id(workout_short_id) - workout = Workout.query.filter_by(uuid=workout_uuid).first() - workout.map = 'incorrect path' - - assert response.status_code == 200 - assert 'success' in data['status'] - assert '' in data['message'] - assert len(data['data']['gpx']) != '' - - response = client.get( - f'/api/workouts/map/{map_id}', - headers=dict(Authorization=f'Bearer {auth_token}'), - ) - - self.assert_500(response) - def test_it_gets_a_workout_created_with_gpx( self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str ) -> None: diff --git a/fittrackee/workouts/workouts.py b/fittrackee/workouts/workouts.py index a6152189..d74b0dd6 100644 --- a/fittrackee/workouts/workouts.py +++ b/fittrackee/workouts/workouts.py @@ -13,7 +13,7 @@ from flask import ( send_from_directory, ) from sqlalchemy import exc -from werkzeug.exceptions import RequestEntityTooLarge +from werkzeug.exceptions import NotFound, RequestEntityTooLarge from werkzeug.utils import secure_filename from fittrackee import appLog, db @@ -798,6 +798,8 @@ def get_map(map_id: int) -> Union[HttpResponse, Response]: current_app.config['UPLOAD_FOLDER'], workout.map, ) + except NotFound: + return NotFoundErrorResponse('Map file does not exist.') except Exception as e: return handle_error_and_return_response(e)