API & Client - update API error messages to remove i18n workarounds

This commit is contained in:
Sam 2021-11-01 09:44:10 +01:00
parent fb6491638c
commit 7f6f33a6aa
36 changed files with 357 additions and 340 deletions

View File

@ -49,7 +49,7 @@ def get_application_config() -> Union[Dict, HttpResponse]:
} }
:statuscode 200: success :statuscode 200: success
:statuscode 500: Error on getting configuration. :statuscode 500: error on getting configuration
""" """
try: try:
@ -57,7 +57,7 @@ def get_application_config() -> Union[Dict, HttpResponse]:
return {'status': 'success', 'data': config.serialize()} return {'status': 'success', 'data': config.serialize()}
except (MultipleResultsFound, NoResultFound) as e: except (MultipleResultsFound, NoResultFound) as e:
return handle_error_and_return_response( return handle_error_and_return_response(
e, message='Error on getting configuration.' e, message='error on getting configuration'
) )
@ -107,11 +107,11 @@ def update_application_config(auth_user_id: int) -> Union[Dict, HttpResponse]:
:statuscode 200: success :statuscode 200: success
:statuscode 400: invalid payload :statuscode 400: invalid payload
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 403: You do not have permissions. :statuscode 403: you do not have permissions
:statuscode 500: Error on updating configuration. :statuscode 500: error when updating configuration
""" """
config_data = request.get_json() config_data = request.get_json()
if not config_data: if not config_data:
@ -145,7 +145,7 @@ def update_application_config(auth_user_id: int) -> Union[Dict, HttpResponse]:
except Exception as e: except Exception as e:
return handle_error_and_return_response( return handle_error_and_return_response(
e, message='Error on updating configuration.' e, message='error when updating configuration'
) )

View File

@ -64,7 +64,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/img/workouts/mountains.svg" "url": "/img/workouts/mountains.svg"
}, },
{ {
"revision": "2cfd100ce4c5acaf0068499df96fa840", "revision": "45170abcbb428b727d6c19c2ad2b035e",
"url": "/index.html" "url": "/index.html"
}, },
{ {
@ -80,7 +80,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/admin.c784857e.css" "url": "/static/css/admin.c784857e.css"
}, },
{ {
"revision": "d9bfacb8dc8f5a151839", "revision": "08e51982ad17cd69b5d3",
"url": "/static/css/app.6f17ce7a.css" "url": "/static/css/app.6f17ce7a.css"
}, },
{ {
@ -108,8 +108,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/reset.528e2916.css" "url": "/static/css/reset.528e2916.css"
}, },
{ {
"revision": "71aefc8221f9e9fcf5c2", "revision": "37e775456654cbd24e0b",
"url": "/static/css/workouts.80ddc1b5.css" "url": "/static/css/workouts.105c79ea.css"
}, },
{ {
"revision": "e719f9244c69e28e7d00e725ca1e280e", "revision": "e719f9244c69e28e7d00e725ca1e280e",
@ -196,8 +196,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/admin.b2c267a7.js" "url": "/static/js/admin.b2c267a7.js"
}, },
{ {
"revision": "d9bfacb8dc8f5a151839", "revision": "08e51982ad17cd69b5d3",
"url": "/static/js/app.da2a9740.js" "url": "/static/js/app.cbc2c869.js"
}, },
{ {
"revision": "bd7d183c9f68e5f4027d", "revision": "bd7d183c9f68e5f4027d",
@ -240,7 +240,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/reset.607f183f.js" "url": "/static/js/reset.607f183f.js"
}, },
{ {
"revision": "71aefc8221f9e9fcf5c2", "revision": "37e775456654cbd24e0b",
"url": "/static/js/workouts.850179fa.js" "url": "/static/js/workouts.833bfd44.js"
} }
]); ]);

View File

@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts( importScripts(
"/precache-manifest.2993d681f0886c270e7f04b02d8ff7c6.js" "/precache-manifest.2384a8066007a7b5a9dea87ccb53b3f8.js"
); );
workbox.core.setCacheNameDetails({prefix: "fittrackee_client"}); workbox.core.setCacheNameDetails({prefix: "fittrackee_client"});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -68,7 +68,7 @@ class InvalidPayloadErrorResponse(GenericErrorResponse):
message: Optional[Union[str, List]] = None, message: Optional[Union[str, List]] = None,
status: Optional[str] = None, status: Optional[str] = None,
) -> None: ) -> None:
message = 'Invalid payload.' if message is None else message message = 'invalid payload' if message is None else message
super().__init__(status_code=400, message=message, status=status) super().__init__(status_code=400, message=message, status=status)
@ -84,7 +84,7 @@ class DataInvalidPayloadErrorResponse(HttpResponse):
class UnauthorizedErrorResponse(GenericErrorResponse): class UnauthorizedErrorResponse(GenericErrorResponse):
def __init__(self, message: Optional[str] = None) -> None: def __init__(self, message: Optional[str] = None) -> None:
message = ( message = (
'Invalid token. Please request a new token.' 'invalid token, please request a new token'
if message is None if message is None
else message else message
) )
@ -93,9 +93,7 @@ class UnauthorizedErrorResponse(GenericErrorResponse):
class ForbiddenErrorResponse(GenericErrorResponse): class ForbiddenErrorResponse(GenericErrorResponse):
def __init__(self, message: Optional[str] = None) -> None: def __init__(self, message: Optional[str] = None) -> None:
message = ( message = 'you do not have permissions' if message is None else message
'You do not have permissions.' if message is None else message
)
super().__init__(status_code=403, message=message) super().__init__(status_code=403, message=message)
@ -106,7 +104,7 @@ class NotFoundErrorResponse(GenericErrorResponse):
class UserNotFoundErrorResponse(NotFoundErrorResponse): class UserNotFoundErrorResponse(NotFoundErrorResponse):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__(message='User does not exist.') super().__init__(message='user does not exist')
class DataNotFoundErrorResponse(HttpResponse): class DataNotFoundErrorResponse(HttpResponse):
@ -142,7 +140,7 @@ class InternalServerErrorResponse(GenericErrorResponse):
self, message: Optional[str] = None, status: Optional[str] = None self, message: Optional[str] = None, status: Optional[str] = None
): ):
message = ( message = (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
if message is None if message is None
else message else message
) )

View File

@ -48,7 +48,7 @@ class TestGetConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Error on getting configuration.' in data['message'] assert 'error on getting configuration' in data['message']
def test_it_returns_error_if_application_has_several_config( def test_it_returns_error_if_application_has_several_config(
self, app: Flask, app_config: Flask, user_1_admin: User self, app: Flask, app_config: Flask, user_1_admin: User
@ -66,7 +66,7 @@ class TestGetConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Error on getting configuration.' in data['message'] assert 'error on getting configuration' in data['message']
class TestUpdateConfig(ApiTestCaseMixin): class TestUpdateConfig(ApiTestCaseMixin):
@ -138,7 +138,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
assert response.status_code == 403 assert response.status_code == 403
assert 'success' not in data['status'] assert 'success' not in data['status']
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_it_returns_400_if_invalid_is_payload( def test_it_returns_400_if_invalid_is_payload(
self, app: Flask, user_1_admin: User self, app: Flask, user_1_admin: User
@ -157,7 +157,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
def test_it_returns_error_on_update_if_application_has_no_config( def test_it_returns_error_on_update_if_application_has_no_config(
self, app_no_config: Flask, user_1_admin: User self, app_no_config: Flask, user_1_admin: User
@ -176,7 +176,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Error on updating configuration.' in data['message'] assert 'error when updating configuration' in data['message']
def test_it_raises_error_if_archive_max_size_is_below_files_max_size( def test_it_raises_error_if_archive_max_size_is_below_files_max_size(
self, app: Flask, user_1_admin: User self, app: Flask, user_1_admin: User

View File

@ -32,7 +32,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'Successfully registered.' assert data['message'] == 'successfully registered'
assert data['auth_token'] assert data['auth_token']
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 201 assert response.status_code == 201
@ -55,7 +55,7 @@ class TestUserRegistration:
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Sorry. That user already exists.' assert data['message'] == 'sorry, that user already exists'
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -79,7 +79,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == "Username: 3 to 12 characters required.\n" assert data['message'] == "username: 3 to 12 characters required\n"
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -101,7 +101,7 @@ class TestUserRegistration:
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == "Username: 3 to 12 characters required.\n" assert data['message'] == "username: 3 to 12 characters required\n"
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -123,7 +123,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == "Valid email must be provided.\n" assert data['message'] == "email: valid email must be provided\n"
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -147,7 +147,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == "Password: 8 characters required.\n" assert data['message'] == "password: 8 characters required\n"
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -171,7 +171,7 @@ class TestUserRegistration:
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] data['message']
== "Password and password confirmation don\'t match.\n" == "password: password and password confirmation do not match\n"
) )
assert response.content_type == 'application/json' assert response.content_type == 'application/json'
assert response.status_code == 400 assert response.status_code == 400
@ -185,7 +185,7 @@ class TestUserRegistration:
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code, 400 assert response.status_code, 400
assert 'Invalid payload.', data['message'] assert 'invalid payload', data['message']
assert 'error', data['status'] assert 'error', data['status']
def test_it_returns_error_if_username_is_missing(self, app: Flask) -> None: def test_it_returns_error_if_username_is_missing(self, app: Flask) -> None:
@ -205,7 +205,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
assert 'error' in data['status'] assert 'error' in data['status']
def test_it_returns_error_if_email_is_missing(self, app: Flask) -> None: def test_it_returns_error_if_email_is_missing(self, app: Flask) -> None:
@ -225,7 +225,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
assert 'error' in data['status'] assert 'error' in data['status']
def test_it_returns_error_if_password_is_missing(self, app: Flask) -> None: def test_it_returns_error_if_password_is_missing(self, app: Flask) -> None:
@ -245,7 +245,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'Invalid payload.', data['message'] assert 'invalid payload', data['message']
assert 'error', data['status'] assert 'error', data['status']
def test_it_returns_error_if_password_confirmation_is_missing( def test_it_returns_error_if_password_confirmation_is_missing(
@ -263,7 +263,7 @@ class TestUserRegistration:
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
assert 'error' in data['status'] assert 'error' in data['status']
def test_it_returns_error_if_username_is_invalid(self, app: Flask) -> None: def test_it_returns_error_if_username_is_invalid(self, app: Flask) -> None:
@ -285,7 +285,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 500 assert response.status_code == 500
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
assert 'error' in data['status'] assert 'error' in data['status']
@ -305,7 +305,7 @@ class TestUserLogin:
assert response.status_code == 200 assert response.status_code == 200
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'Successfully logged in.' assert data['message'] == 'successfully logged in'
assert data['auth_token'] assert data['auth_token']
def test_it_returns_error_if_user_does_not_exists( def test_it_returns_error_if_user_does_not_exists(
@ -323,7 +323,7 @@ class TestUserLogin:
assert response.status_code == 401 assert response.status_code == 401
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid credentials.' assert data['message'] == 'invalid credentials'
def test_it_returns_error_on_invalid_payload(self, app: Flask) -> None: def test_it_returns_error_on_invalid_payload(self, app: Flask) -> None:
client = app.test_client() client = app.test_client()
@ -338,7 +338,7 @@ class TestUserLogin:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
def test_it_returns_error_if_password_is_invalid( def test_it_returns_error_if_password_is_invalid(
self, app: Flask, user_1: User self, app: Flask, user_1: User
@ -355,7 +355,7 @@ class TestUserLogin:
assert response.status_code == 401 assert response.status_code == 401
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid credentials.' assert data['message'] == 'invalid credentials'
class TestUserLogout(ApiTestCaseMixin): class TestUserLogout(ApiTestCaseMixin):
@ -370,7 +370,7 @@ class TestUserLogout(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'Successfully logged out.' assert data['message'] == 'successfully logged out'
assert response.status_code == 200 assert response.status_code == 200
def test_it_returns_error_with_expired_token( def test_it_returns_error_with_expired_token(
@ -386,7 +386,7 @@ class TestUserLogout(ApiTestCaseMixin):
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Signature expired. Please log in again.' assert data['message'] == 'signature expired, please log in again'
assert response.status_code == 401 assert response.status_code == 401
def test_it_returns_error_with_invalid_token(self, app: Flask) -> None: def test_it_returns_error_with_invalid_token(self, app: Flask) -> None:
@ -396,7 +396,7 @@ class TestUserLogout(ApiTestCaseMixin):
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid token. Please log in again.' assert data['message'] == 'invalid token, please log in again'
assert response.status_code == 401 assert response.status_code == 401
def test_it_returns_error_with_invalid_headers(self, app: Flask) -> None: def test_it_returns_error_with_invalid_headers(self, app: Flask) -> None:
@ -404,7 +404,7 @@ class TestUserLogout(ApiTestCaseMixin):
response = client.get('/api/auth/logout', headers=dict()) response = client.get('/api/auth/logout', headers=dict())
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Provide a valid auth token.' assert data['message'] == 'provide a valid auth token'
assert response.status_code == 401 assert response.status_code == 401
@ -509,7 +509,7 @@ class TestUserProfile(ApiTestCaseMixin):
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid token. Please log in again.' assert data['message'] == 'invalid token, please log in again'
assert response.status_code == 401 assert response.status_code == 401
@ -536,7 +536,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'User profile updated.' assert data['message'] == 'user profile updated'
assert response.status_code == 200 assert response.status_code == 200
assert data['data']['username'] == 'test' assert data['data']['username'] == 'test'
assert data['data']['email'] == 'test@test.com' assert data['data']['email'] == 'test@test.com'
@ -579,7 +579,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'User profile updated.' assert data['message'] == 'user profile updated'
assert response.status_code == 200 assert response.status_code == 200
assert data['data']['username'] == 'test' assert data['data']['username'] == 'test'
assert data['data']['email'] == 'test@test.com' assert data['data']['email'] == 'test@test.com'
@ -614,7 +614,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
assert response.status_code == 400 assert response.status_code == 400
def test_it_returns_error_if_payload_is_empty( def test_it_returns_error_if_payload_is_empty(
@ -631,7 +631,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
assert 'error' in data['status'] assert 'error' in data['status']
def test_it_returns_error_if_passwords_mismatch( def test_it_returns_error_if_passwords_mismatch(
@ -660,7 +660,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] data['message']
== 'Password and password confirmation don\'t match.\n' == 'password: password and password confirmation do not match\n'
) )
assert response.status_code == 400 assert response.status_code == 400
@ -689,7 +689,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] data['message']
== 'Password and password confirmation don\'t match.\n' == 'password: password and password confirmation do not match\n'
) )
assert response.status_code == 400 assert response.status_code == 400
@ -715,7 +715,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'User preferences updated.' assert data['message'] == 'user preferences updated'
assert response.status_code == 200 assert response.status_code == 200
assert data['data']['username'] == 'test' assert data['data']['username'] == 'test'
assert data['data']['email'] == 'test@test.com' assert data['data']['email'] == 'test@test.com'
@ -750,7 +750,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
assert response.status_code == 400 assert response.status_code == 400
def test_it_returns_error_if_payload_is_empty( def test_it_returns_error_if_payload_is_empty(
@ -767,7 +767,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
assert 'error' in data['status'] assert 'error' in data['status']
@ -786,7 +786,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'User picture updated.' assert data['message'] == 'user picture updated'
assert response.status_code == 200 assert response.status_code == 200
assert 'avatar.png' in user_1.picture assert 'avatar.png' in user_1.picture
@ -801,7 +801,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'User picture updated.' assert data['message'] == 'user picture updated'
assert response.status_code == 200 assert response.status_code == 200
assert 'avatar.png' not in user_1.picture assert 'avatar.png' not in user_1.picture
assert 'avatar2.png' in user_1.picture assert 'avatar2.png' in user_1.picture
@ -821,7 +821,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'fail' assert data['status'] == 'fail'
assert data['message'] == 'No file part.' assert data['message'] == 'no file part'
assert response.status_code == 400 assert response.status_code == 400
def test_it_returns_error_if_file_is_invalid( def test_it_returns_error_if_file_is_invalid(
@ -840,7 +840,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'fail' assert data['status'] == 'fail'
assert data['message'] == 'File extension not allowed.' assert data['message'] == 'file extension not allowed'
assert response.status_code == 400 assert response.status_code == 400
def test_it_returns_error_if_image_size_exceeds_file_limit( def test_it_returns_error_if_image_size_exceeds_file_limit(
@ -935,7 +935,7 @@ class TestRegistrationConfiguration:
assert response.status_code == 403 assert response.status_code == 403
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Error. Registration is disabled.' assert data['message'] == 'error, registration is disabled'
def test_it_disables_registration_on_user_registration( def test_it_disables_registration_on_user_registration(
self, self,
@ -973,7 +973,7 @@ class TestRegistrationConfiguration:
assert response.status_code == 403 assert response.status_code == 403
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Error. Registration is disabled.' assert data['message'] == 'error, registration is disabled'
def test_it_does_not_disable_registration_on_user_registration( def test_it_does_not_disable_registration_on_user_registration(
self, self,
@ -1024,7 +1024,7 @@ class TestPasswordResetRequest:
assert response.status_code == 200 assert response.status_code == 200
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'Password reset request processed.' assert data['message'] == 'password reset request processed'
def test_it_does_not_return_error_when_user_does_not_exist( def test_it_does_not_return_error_when_user_does_not_exist(
self, app: Flask self, app: Flask
@ -1040,7 +1040,7 @@ class TestPasswordResetRequest:
assert response.status_code == 200 assert response.status_code == 200
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'Password reset request processed.' assert data['message'] == 'password reset request processed'
def test_it_returns_error_on_invalid_payload(self, app: Flask) -> None: def test_it_returns_error_on_invalid_payload(self, app: Flask) -> None:
client = app.test_client() client = app.test_client()
@ -1053,7 +1053,7 @@ class TestPasswordResetRequest:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
assert data['status'] == 'error' assert data['status'] == 'error'
def test_it_returns_error_on_empty_payload(self, app: Flask) -> None: def test_it_returns_error_on_empty_payload(self, app: Flask) -> None:
@ -1067,7 +1067,7 @@ class TestPasswordResetRequest:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
assert data['status'] == 'error' assert data['status'] == 'error'
@ -1089,7 +1089,7 @@ class TestPasswordUpdate:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
def test_it_returns_error_if_token_is_missing(self, app: Flask) -> None: def test_it_returns_error_if_token_is_missing(self, app: Flask) -> None:
client = app.test_client() client = app.test_client()
@ -1108,7 +1108,7 @@ class TestPasswordUpdate:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
def test_it_returns_error_if_password_is_missing(self, app: Flask) -> None: def test_it_returns_error_if_password_is_missing(self, app: Flask) -> None:
client = app.test_client() client = app.test_client()
@ -1127,7 +1127,7 @@ class TestPasswordUpdate:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
def test_it_returns_error_if_password_confirmation_is_missing( def test_it_returns_error_if_password_confirmation_is_missing(
self, app: Flask self, app: Flask
@ -1148,7 +1148,7 @@ class TestPasswordUpdate:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
def test_it_returns_error_if_token_is_invalid(self, app: Flask) -> None: def test_it_returns_error_if_token_is_invalid(self, app: Flask) -> None:
token = get_user_token(1) token = get_user_token(1)
@ -1169,7 +1169,7 @@ class TestPasswordUpdate:
assert response.status_code == 401 assert response.status_code == 401
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid token. Please request a new token.' assert data['message'] == 'invalid token, please request a new token'
def test_it_returns_error_if_token_is_expired( def test_it_returns_error_if_token_is_expired(
self, app: Flask, user_1: User self, app: Flask, user_1: User
@ -1195,7 +1195,7 @@ class TestPasswordUpdate:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] == 'Invalid token. Please request a new token.' data['message'] == 'invalid token, please request a new token'
) )
def test_it_returns_error_if_password_is_invalid( def test_it_returns_error_if_password_is_invalid(
@ -1219,7 +1219,7 @@ class TestPasswordUpdate:
assert response.status_code == 400 assert response.status_code == 400
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Password: 8 characters required.\n' assert data['message'] == 'password: 8 characters required\n'
def test_it_update_password(self, app: Flask, user_1: User) -> None: def test_it_update_password(self, app: Flask, user_1: User) -> None:
token = get_user_token(user_1.id, password_reset=True) token = get_user_token(user_1.id, password_reset=True)
@ -1240,4 +1240,4 @@ class TestPasswordUpdate:
assert response.status_code == 200 assert response.status_code == 200
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'success' assert data['status'] == 'success'
assert data['message'] == 'Password updated.' assert data['message'] == 'password updated'

View File

@ -102,7 +102,7 @@ class TestGetUser(ApiTestCaseMixin):
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'User does not exist.' in data['message'] assert 'user does not exist' in data['message']
class TestGetUsers(ApiTestCaseMixin): class TestGetUsers(ApiTestCaseMixin):
@ -800,7 +800,7 @@ class TestGetUserPicture:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'User does not exist.' in data['message'] assert 'user does not exist' in data['message']
class TestUpdateUser(ApiTestCaseMixin): class TestUpdateUser(ApiTestCaseMixin):
@ -866,7 +866,7 @@ class TestUpdateUser(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
def test_it_returns_error_if_payload_for_admin_rights_is_invalid( def test_it_returns_error_if_payload_for_admin_rights_is_invalid(
self, app: Flask, user_1_admin: User, user_2: User self, app: Flask, user_1_admin: User, user_2: User
@ -886,7 +886,7 @@ class TestUpdateUser(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
@ -905,7 +905,7 @@ class TestUpdateUser(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
class TestDeleteUser(ApiTestCaseMixin): class TestDeleteUser(ApiTestCaseMixin):
@ -977,7 +977,7 @@ class TestDeleteUser(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_it_returns_error_when_deleting_non_existing_user( def test_it_returns_error_when_deleting_non_existing_user(
self, app: Flask, user_1: User self, app: Flask, user_1: User
@ -992,7 +992,7 @@ class TestDeleteUser(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'User does not exist.' in data['message'] assert 'user does not exist' in data['message']
def test_admin_can_delete_another_user_account( def test_admin_can_delete_another_user_account(
self, app: Flask, user_1_admin: User, user_2: User self, app: Flask, user_1_admin: User, user_2: User
@ -1103,4 +1103,4 @@ class TestDeleteUser(ApiTestCaseMixin):
assert response.status_code == 403 assert response.status_code == 403
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Error. Registration is disabled.' assert data['message'] == 'error, registration is disabled'

View File

@ -296,7 +296,7 @@ class TestUpdateSport(ApiTestCaseMixin):
assert response.status_code == 403 assert response.status_code == 403
assert 'success' not in data['status'] assert 'success' not in data['status']
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_returns_error_if_payload_is_invalid( def test_returns_error_if_payload_is_invalid(
self, app: Flask, user_1_admin: User self, app: Flask, user_1_admin: User
@ -315,7 +315,7 @@ class TestUpdateSport(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
def test_it_returns_error_if_sport_does_not_exist( def test_it_returns_error_if_sport_does_not_exist(
self, app: Flask, user_1_admin: User self, app: Flask, user_1_admin: User

View File

@ -37,7 +37,7 @@ class TestGetStatsByTime(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'User does not exist.' in data['message'] assert 'user does not exist' in data['message']
def test_it_returns_error_if_date_format_is_invalid( def test_it_returns_error_if_date_format_is_invalid(
self, self,
@ -62,7 +62,7 @@ class TestGetStatsByTime(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
@ -867,7 +867,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'User does not exist.' in data['message'] assert 'user does not exist' in data['message']
def test_it_returns_error_if_sport_does_not_exist( def test_it_returns_error_if_sport_does_not_exist(
self, self,
@ -888,7 +888,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'Sport does not exist.' in data['message'] assert 'sport does not exist' in data['message']
def test_it_returns_error_if_sport_id_is_invalid( def test_it_returns_error_if_sport_id_is_invalid(
self, self,
@ -910,7 +910,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
@ -988,4 +988,4 @@ class TestGetAllStats(ApiTestCaseMixin):
assert response.status_code == 403 assert response.status_code == 403
assert 'success' not in data['status'] assert 'success' not in data['status']
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']

View File

@ -94,7 +94,7 @@ class TestGetWorkouts(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 401 assert response.status_code == 401
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Provide a valid auth token.' in data['message'] assert 'provide a valid auth token' in data['message']
class TestGetWorkoutsWithPagination(ApiTestCaseMixin): class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
@ -228,7 +228,7 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
@ -707,7 +707,7 @@ class TestGetWorkout(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_it_returns_404_if_workout_does_not_exist( def test_it_returns_404_if_workout_does_not_exist(
self, app: Flask, user_1: User self, app: Flask, user_1: User
@ -738,7 +738,7 @@ class TestGetWorkout(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert f'Workout not found (id: {random_short_id})' in data['message'] assert f'workout not found (id: {random_short_id})' in data['message']
assert data['data']['gpx'] == '' assert data['data']['gpx'] == ''
def test_it_returns_404_on_getting_chart_data_if_workout_does_not_exist( def test_it_returns_404_on_getting_chart_data_if_workout_does_not_exist(
@ -755,7 +755,7 @@ class TestGetWorkout(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert f'Workout not found (id: {random_short_id})' in data['message'] assert f'workout not found (id: {random_short_id})' in data['message']
assert data['data']['chart_data'] == '' assert data['data']['chart_data'] == ''
def test_it_returns_404_on_getting_gpx_if_workout_have_no_gpx( def test_it_returns_404_on_getting_gpx_if_workout_have_no_gpx(
@ -777,7 +777,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert ( assert (
f'No gpx file for this workout (id: {workout_short_id})' f'no gpx file for this workout (id: {workout_short_id})'
in data['message'] in data['message']
) )
@ -800,7 +800,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert ( assert (
f'No gpx file for this workout (id: {workout_short_id})' f'no gpx file for this workout (id: {workout_short_id})'
in data['message'] in data['message']
) )
@ -823,7 +823,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
assert 'data' not in data assert 'data' not in data
@ -847,7 +847,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
assert 'data' not in data assert 'data' not in data

View File

@ -468,7 +468,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert data['status'] == 'fail' assert data['status'] == 'fail'
assert data['message'] == 'File extension not allowed.' assert data['message'] == 'file extension not allowed'
def test_it_returns_400_if_sport_id_is_not_provided( def test_it_returns_400_if_sport_id_is_not_provided(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
@ -489,7 +489,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert data['status'] == 'error' assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.' assert data['message'] == 'invalid payload'
def test_it_returns_500_if_sport_id_does_not_exists( def test_it_returns_500_if_sport_id_does_not_exists(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
@ -530,7 +530,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert data['status'] == 'fail' assert data['status'] == 'fail'
assert data['message'] == 'No file part.' assert data['message'] == 'no file part'
def test_it_returns_error_if_file_size_exceeds_limit( def test_it_returns_error_if_file_size_exceeds_limit(
self, self,
@ -605,7 +605,7 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
def test_it_returns_500_if_workout_format_is_invalid( def test_it_returns_500_if_workout_format_is_invalid(
self, app: Flask, user_1: User, sport_1_cycling: Sport self, app: Flask, user_1: User, sport_1_cycling: Sport
@ -911,7 +911,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
assert data['status'] == 'error' assert data['status'] == 'error'
assert ( assert (
data['message'] data['message']
== 'Error. Please try again or contact the administrator.' == 'error, please try again or contact the administrator'
) )
def test_it_gets_an_workout_created_with_gpx( def test_it_gets_an_workout_created_with_gpx(
@ -1025,7 +1025,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert data['message'] == 'You do not have permissions.' assert data['message'] == 'you do not have permissions'
def test_it_returns_500_on_invalid_segment_id( def test_it_returns_500_on_invalid_segment_id(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str

View File

@ -173,7 +173,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_it_updates_sport( def test_it_updates_sport(
self, self,
@ -217,7 +217,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
def test_it_raises_500_if_sport_does_not_exists( def test_it_raises_500_if_sport_does_not_exists(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
@ -236,7 +236,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
@ -405,7 +405,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_it_updates_an_workout_wo_gpx_with_timezone( def test_it_updates_an_workout_wo_gpx_with_timezone(
self, self,
@ -564,7 +564,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 400 assert response.status_code == 400
assert 'error' in data['status'] assert 'error' in data['status']
assert 'Invalid payload.' in data['message'] assert 'invalid payload' in data['message']
def test_it_returns_500_if_date_format_is_invalid( def test_it_returns_500_if_date_format_is_invalid(
self, self,
@ -593,7 +593,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )

View File

@ -58,7 +58,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']
def test_it_returns_404_if_workout_does_not_exist( def test_it_returns_404_if_workout_does_not_exist(
self, app: Flask, user_1: User self, app: Flask, user_1: User
@ -91,7 +91,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
assert response.status_code == 500 assert response.status_code == 500
assert 'error' in data['status'] assert 'error' in data['status']
assert ( assert (
'Error. Please try again or contact the administrator.' 'error, please try again or contact the administrator'
in data['message'] in data['message']
) )
@ -137,4 +137,4 @@ class TestDeleteWorkoutWithoutGpx(ApiTestCaseMixin):
assert response.status_code == 403 assert response.status_code == 403
assert 'error' in data['status'] assert 'error' in data['status']
assert 'You do not have permissions.' in data['message'] assert 'you do not have permissions' in data['message']

View File

@ -52,7 +52,7 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
{ {
"auth_token": "JSON Web Token", "auth_token": "JSON Web Token",
"message": "Successfully registered.", "message": "successfully registered",
"status": "success" "status": "success"
} }
@ -64,7 +64,7 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "Errors: Valid email must be provided.\\n", "message": "Errors: email: valid email must be provided\\n",
"status": "error" "status": "error"
} }
@ -73,23 +73,23 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
:<json string password: password (8 characters required) :<json string password: password (8 characters required)
:<json string password_conf: password confirmation :<json string password_conf: password confirmation
:statuscode 201: Successfully registered. :statuscode 201: successfully registered
:statuscode 400: :statuscode 400:
- Invalid payload. - invalid payload
- Sorry. That user already exists. - sorry, that user already exists
- Errors: - Errors:
- 3 to 12 characters required for usernanme. - username: 3 to 12 characters required
- Valid email must be provided. - email: valid email must be provided
- Password and password confirmation don't match. - password: password and password confirmation don't match
- 8 characters required for password. - password: 8 characters required
:statuscode 403: :statuscode 403:
Error. Registration is disabled. error, registration is disabled
:statuscode 500: :statuscode 500:
Error. Please try again or contact the administrator. error, please try again or contact the administrator
""" """
if not current_app.config.get('is_registration_enabled'): if not current_app.config.get('is_registration_enabled'):
return ForbiddenErrorResponse('Error. Registration is disabled.') return ForbiddenErrorResponse('error, registration is disabled')
# get post data # get post data
post_data = request.get_json() post_data = request.get_json()
@ -121,7 +121,7 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
).first() ).first()
if user: if user:
return InvalidPayloadErrorResponse( return InvalidPayloadErrorResponse(
'Sorry. That user already exists.' 'sorry, that user already exists'
) )
# add new user to db # add new user to db
@ -133,7 +133,7 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
auth_token = new_user.encode_auth_token(new_user.id) auth_token = new_user.encode_auth_token(new_user.id)
return { return {
'status': 'success', 'status': 'success',
'message': 'Successfully registered.', 'message': 'successfully registered',
'auth_token': auth_token, 'auth_token': auth_token,
}, 201 }, 201
# handler errors # handler errors
@ -164,7 +164,7 @@ def login_user() -> Union[Dict, HttpResponse]:
{ {
"auth_token": "JSON Web Token", "auth_token": "JSON Web Token",
"message": "Successfully logged in.", "message": "successfully logged in",
"status": "success" "status": "success"
} }
@ -176,17 +176,17 @@ def login_user() -> Union[Dict, HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "Invalid credentials.", "message": "invalid credentials",
"status": "error" "status": "error"
} }
:<json string email: user email :<json string email: user email
:<json string password_conf: password confirmation :<json string password_conf: password confirmation
:statuscode 200: Successfully logged in. :statuscode 200: successfully logged in
:statuscode 400: Invalid payload. :statuscode 400: invalid payload
:statuscode 401: Invalid credentials. :statuscode 401: invalid credentials
:statuscode 500: Error. Please try again or contact the administrator. :statuscode 500: error, please try again or contact the administrator
""" """
# get post data # get post data
@ -203,10 +203,10 @@ def login_user() -> Union[Dict, HttpResponse]:
auth_token = user.encode_auth_token(user.id) auth_token = user.encode_auth_token(user.id)
return { return {
'status': 'success', 'status': 'success',
'message': 'Successfully logged in.', 'message': 'successfully logged in',
'auth_token': auth_token, 'auth_token': auth_token,
} }
return UnauthorizedErrorResponse('Invalid credentials.') return UnauthorizedErrorResponse('invalid credentials')
# handler errors # handler errors
except (exc.IntegrityError, exc.OperationalError, ValueError) as e: except (exc.IntegrityError, exc.OperationalError, ValueError) as e:
return handle_error_and_return_response(e, db=db) return handle_error_and_return_response(e, db=db)
@ -235,7 +235,7 @@ def logout_user(auth_user_id: int) -> Union[Dict, HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "Successfully logged out.", "message": "successfully logged out",
"status": "success" "status": "success"
} }
@ -247,20 +247,20 @@ def logout_user(auth_user_id: int) -> Union[Dict, HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "Provide a valid auth token.", "message": "provide a valid auth token",
"status": "error" "status": "error"
} }
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
:statuscode 200: Successfully logged out. :statuscode 200: successfully logged out
:statuscode 401: Provide a valid auth token. :statuscode 401: provide a valid auth token
""" """
# get auth token # get auth token
auth_header = request.headers.get('Authorization') auth_header = request.headers.get('Authorization')
if not auth_header: if not auth_header:
return UnauthorizedErrorResponse('Provide a valid auth token.') return UnauthorizedErrorResponse('provide a valid auth token')
auth_token = auth_header.split(' ')[1] auth_token = auth_header.split(' ')[1]
resp = User.decode_auth_token(auth_token) resp = User.decode_auth_token(auth_token)
@ -269,7 +269,7 @@ def logout_user(auth_user_id: int) -> Union[Dict, HttpResponse]:
return { return {
'status': 'success', 'status': 'success',
'message': 'Successfully logged out.', 'message': 'successfully logged out',
} }
@ -365,9 +365,9 @@ def get_authenticated_user_profile(
:statuscode 200: success. :statuscode 200: success.
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
""" """
user = User.query.filter_by(id=auth_user_id).first() user = User.query.filter_by(id=auth_user_id).first()
@ -457,7 +457,7 @@ def edit_user(auth_user_id: int) -> Union[Dict, HttpResponse]:
"username": "sam" "username": "sam"
"weekm": true, "weekm": true,
}, },
"message": "User profile updated.", "message": "user profile updated",
"status": "success" "status": "success"
} }
@ -471,15 +471,15 @@ def edit_user(auth_user_id: int) -> Union[Dict, HttpResponse]:
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
:statuscode 200: User profile updated. :statuscode 200: user profile updated
:statuscode 400: :statuscode 400:
- Invalid payload. - invalid payload
- Password and password confirmation don't match. - password: password and password confirmation don't match
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 500: Error. Please try again or contact the administrator. :statuscode 500: error, please try again or contact the administrator
""" """
# get post data # get post data
@ -527,7 +527,7 @@ def edit_user(auth_user_id: int) -> Union[Dict, HttpResponse]:
return { return {
'status': 'success', 'status': 'success',
'message': 'User profile updated.', 'message': 'user profile updated',
'data': user.serialize(), 'data': user.serialize(),
} }
@ -619,7 +619,7 @@ def edit_user_preferences(auth_user_id: int) -> Union[Dict, HttpResponse]:
"username": "sam" "username": "sam"
"weekm": true, "weekm": true,
}, },
"message": "User preferences updated.", "message": "user preferences updated",
"status": "success" "status": "success"
} }
@ -629,15 +629,15 @@ def edit_user_preferences(auth_user_id: int) -> Union[Dict, HttpResponse]:
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
:statuscode 200: User profile updated. :statuscode 200: user preferences updated
:statuscode 400: :statuscode 400:
- Invalid payload. - invalid payload
- Password and password confirmation don't match. - password: password and password confirmation don't match
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 500: Error. Please try again or contact the administrator. :statuscode 500: error, please try again or contact the administrator
""" """
# get post data # get post data
@ -663,7 +663,7 @@ def edit_user_preferences(auth_user_id: int) -> Union[Dict, HttpResponse]:
return { return {
'status': 'success', 'status': 'success',
'message': 'User preferences updated.', 'message': 'user preferences updated',
'data': user.serialize(), 'data': user.serialize(),
} }
@ -693,7 +693,7 @@ def edit_picture(auth_user_id: int) -> Union[Dict, HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "User picture updated.", "message": "user picture updated",
"status": "success" "status": "success"
} }
@ -701,18 +701,18 @@ def edit_picture(auth_user_id: int) -> Union[Dict, HttpResponse]:
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
:statuscode 200: User picture updated. :statuscode 200: user picture updated
:statuscode 400: :statuscode 400:
- Invalid payload. - invalid payload
- No file part. - no file part
- No selected file. - no selected file
- File extension not allowed. - file extension not allowed
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 413: Error during picture update: file size exceeds 1.0MB. :statuscode 413: error during picture update: file size exceeds 1.0MB
:statuscode 500: Error during picture update. :statuscode 500: error during picture update
""" """
try: try:
@ -750,12 +750,12 @@ def edit_picture(auth_user_id: int) -> Union[Dict, HttpResponse]:
db.session.commit() db.session.commit()
return { return {
'status': 'success', 'status': 'success',
'message': 'User picture updated.', 'message': 'user picture updated',
} }
except (exc.IntegrityError, ValueError) as e: except (exc.IntegrityError, ValueError) as e:
return handle_error_and_return_response( return handle_error_and_return_response(
e, message='Error during picture update.', status='fail', db=db e, message='error during picture update', status='fail', db=db
) )
@ -783,10 +783,10 @@ def del_picture(auth_user_id: int) -> Union[Tuple[Dict, int], HttpResponse]:
:statuscode 204: picture deleted :statuscode 204: picture deleted
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 500: Error during picture deletion. :statuscode 500: error during picture deletion
""" """
try: try:
@ -799,7 +799,7 @@ def del_picture(auth_user_id: int) -> Union[Tuple[Dict, int], HttpResponse]:
return {'status': 'no content'}, 204 return {'status': 'no content'}, 204
except (exc.IntegrityError, ValueError) as e: except (exc.IntegrityError, ValueError) as e:
return handle_error_and_return_response( return handle_error_and_return_response(
e, message='Error during picture deletion.', status='fail', db=db e, message='error during picture deletion', status='fail', db=db
) )
@ -823,14 +823,14 @@ def request_password_reset() -> Union[Dict, HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "Password reset request processed.", "message": "password reset request processed",
"status": "success" "status": "success"
} }
:<json string email: user email :<json string email: user email
:statuscode 200: Password reset request processed. :statuscode 200: password reset request processed
:statuscode 400: Invalid payload. :statuscode 400: invalid payload
""" """
post_data = request.get_json() post_data = request.get_json()
@ -862,7 +862,7 @@ def request_password_reset() -> Union[Dict, HttpResponse]:
reset_password_email.send(user_data, email_data) reset_password_email.send(user_data, email_data)
return { return {
'status': 'success', 'status': 'success',
'message': 'Password reset request processed.', 'message': 'password reset request processed',
} }
@ -886,7 +886,7 @@ def update_password() -> Union[Dict, HttpResponse]:
Content-Type: application/json Content-Type: application/json
{ {
"message": "Password updated.", "message": "password updated",
"status": "success" "status": "success"
} }
@ -894,10 +894,10 @@ def update_password() -> Union[Dict, HttpResponse]:
:<json string password_conf: password confirmation :<json string password_conf: password confirmation
:<json string token: password reset token :<json string token: password reset token
:statuscode 200: Password updated. :statuscode 200: password updated
:statuscode 400: Invalid payload. :statuscode 400: invalid payload
:statuscode 401: Invalid token. :statuscode 401: invalid token, please request a new token
:statuscode 500: Error. Please try again or contact the administrator. :statuscode 500: error, please try again or contact the administrator
""" """
post_data = request.get_json() post_data = request.get_json()
@ -931,7 +931,7 @@ def update_password() -> Union[Dict, HttpResponse]:
db.session.commit() db.session.commit()
return { return {
'status': 'success', 'status': 'success',
'message': 'Password updated.', 'message': 'password updated',
} }
except (exc.OperationalError, ValueError) as e: except (exc.OperationalError, ValueError) as e:
return handle_error_and_return_response(e, db=db) return handle_error_and_return_response(e, db=db)

View File

@ -86,9 +86,9 @@ class User(BaseModel):
try: try:
return decode_user_token(auth_token) return decode_user_token(auth_token)
except jwt.ExpiredSignatureError: except jwt.ExpiredSignatureError:
return 'Signature expired. Please log in again.' return 'signature expired, please log in again'
except jwt.InvalidTokenError: except jwt.InvalidTokenError:
return 'Invalid token. Please log in again.' return 'invalid token, please log in again'
@hybrid_property @hybrid_property
def workouts_count(self) -> int: def workouts_count(self) -> int:

View File

@ -155,9 +155,9 @@ def get_users(auth_user_id: int) -> Dict:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
""" """
params = request.args.copy() params = request.args.copy()
@ -310,11 +310,11 @@ def get_single_user(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: :statuscode 404:
- User does not exist. - user does not exist
""" """
try: try:
user = User.query.filter_by(username=user_name).first() user = User.query.filter_by(username=user_name).first()
@ -350,7 +350,7 @@ def get_picture(user_name: str) -> Any:
:statuscode 200: success :statuscode 200: success
:statuscode 404: :statuscode 404:
- User does not exist. - user does not exist
- No picture. - No picture.
""" """
@ -466,12 +466,12 @@ def update_user(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 403: You do not have permissions. :statuscode 403: you do not have permissions
:statuscode 404: :statuscode 404:
- User does not exist. - user does not exist
:statuscode 500: :statuscode 500:
""" """
user_data = request.get_json() user_data = request.get_json()
@ -527,15 +527,15 @@ def delete_user(
:statuscode 204: user account deleted :statuscode 204: user account deleted
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 403: :statuscode 403:
- You do not have permissions. - you do not have permissions
- You can not delete your account, no other user has admin rights. - You can not delete your account, no other user has admin rights.
:statuscode 404: :statuscode 404:
- User does not exist. - user does not exist
:statuscode 500: Error. Please try again or contact the administrator. :statuscode 500: error, please try again or contact the administrator
""" """
try: try:

View File

@ -37,9 +37,9 @@ def check_passwords(password: str, password_conf: str) -> str:
""" """
ret = '' ret = ''
if password_conf != password: if password_conf != password:
ret = 'Password and password confirmation don\'t match.\n' ret = 'password: password and password confirmation do not match\n'
if len(password) < 8: if len(password) < 8:
ret += 'Password: 8 characters required.\n' ret += 'password: 8 characters required\n'
return ret return ret
@ -53,9 +53,9 @@ def register_controls(
""" """
ret = '' ret = ''
if not 2 < len(username) < 13: if not 2 < len(username) < 13:
ret += 'Username: 3 to 12 characters required.\n' ret += 'username: 3 to 12 characters required\n'
if not is_valid_email(email): if not is_valid_email(email):
ret += 'Valid email must be provided.\n' ret += 'email: valid email must be provided\n'
ret += check_passwords(password, password_conf) ret += check_passwords(password, password_conf)
return ret return ret
@ -67,7 +67,7 @@ def verify_user(
Return user id, if the provided token is valid and if user has admin Return user id, if the provided token is valid and if user has admin
rights if 'verify_admin' is True rights if 'verify_admin' is True
""" """
default_message = 'Provide a valid auth token.' default_message = 'provide a valid auth token'
auth_header = current_request.headers.get('Authorization') auth_header = current_request.headers.get('Authorization')
if not auth_header: if not auth_header:
return UnauthorizedErrorResponse(default_message), None return UnauthorizedErrorResponse(default_message), None

View File

@ -18,11 +18,11 @@ def verify_extension_and_size(
Return error Response if file is invalid Return error Response if file is invalid
""" """
if 'file' not in req.files: if 'file' not in req.files:
return InvalidPayloadErrorResponse('No file part.', 'fail') return InvalidPayloadErrorResponse('no file part', 'fail')
file = req.files['file'] file = req.files['file']
if not file.filename or file.filename == '': if not file.filename or file.filename == '':
return InvalidPayloadErrorResponse('No selected file.', 'fail') return InvalidPayloadErrorResponse('no selected file', 'fail')
allowed_extensions = ( allowed_extensions = (
'WORKOUT_ALLOWED_EXTENSIONS' 'WORKOUT_ALLOWED_EXTENSIONS'
@ -42,7 +42,7 @@ def verify_extension_and_size(
and file_extension in current_app.config[allowed_extensions] and file_extension in current_app.config[allowed_extensions]
): ):
return InvalidPayloadErrorResponse( return InvalidPayloadErrorResponse(
'File extension not allowed.', 'fail' 'file extension not allowed', 'fail'
) )
if ( if (

View File

@ -101,9 +101,9 @@ def get_records(auth_user_id: int) -> Dict:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
""" """
records = ( records = (

View File

@ -147,9 +147,9 @@ def get_sports(auth_user_id: int) -> Dict:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
""" """
user = User.query.filter_by(id=int(auth_user_id)).first() user = User.query.filter_by(id=int(auth_user_id)).first()
@ -239,9 +239,9 @@ def get_sport(auth_user_id: int, sport_id: int) -> Union[Dict, HttpResponse]:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: sport not found :statuscode 404: sport not found
""" """
@ -319,10 +319,10 @@ def update_sport(
:statuscode 200: sport updated :statuscode 200: sport updated
:statuscode 400: invalid payload :statuscode 400: invalid payload
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 403: You do not have permissions. :statuscode 403: you do not have permissions
:statuscode 404: sport not found :statuscode 404: sport not found
:statuscode 500: :statuscode 500:

View File

@ -42,7 +42,7 @@ def get_workouts(
if sport_id: if sport_id:
sport = Sport.query.filter_by(id=sport_id).first() sport = Sport.query.filter_by(id=sport_id).first()
if not sport: if not sport:
return NotFoundErrorResponse('Sport does not exist.') return NotFoundErrorResponse('sport does not exist')
workouts = ( workouts = (
Workout.query.filter( Workout.query.filter(
@ -247,11 +247,11 @@ def get_workouts_by_time(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: :statuscode 404:
- User does not exist. - user does not exist
""" """
return get_workouts(user_name, 'by_time') return get_workouts(user_name, 'by_time')
@ -340,12 +340,12 @@ def get_workouts_by_sport(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: :statuscode 404:
- User does not exist. - user does not exist
- Sport does not exist. - sport does not exist
""" """
return get_workouts(user_name, 'by_sport') return get_workouts(user_name, 'by_sport')
@ -387,10 +387,10 @@ def get_application_stats(auth_user_id: int) -> Dict:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 403: You do not have permissions. :statuscode 403: you do not have permissions
""" """
nb_workouts = Workout.query.filter().count() nb_workouts = Workout.query.filter().count()

View File

@ -187,9 +187,9 @@ def get_workouts(auth_user_id: int) -> Union[Dict, HttpResponse]:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 500: :statuscode 500:
""" """
@ -343,10 +343,10 @@ def get_workout(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 403: You do not have permissions. :statuscode 403: you do not have permissions
:statuscode 404: workout not found :statuscode 404: workout not found
""" """
@ -377,7 +377,7 @@ def get_workout_data(
if not workout: if not workout:
return DataNotFoundErrorResponse( return DataNotFoundErrorResponse(
data_type=data_type, data_type=data_type,
message=f'Workout not found (id: {workout_short_id})', message=f'workout not found (id: {workout_short_id})',
) )
error_response = can_view_workout(auth_user_id, workout.user_id) error_response = can_view_workout(auth_user_id, workout.user_id)
@ -385,7 +385,7 @@ def get_workout_data(
return error_response return error_response
if not workout.gpx or workout.gpx == '': if not workout.gpx or workout.gpx == '':
return NotFoundErrorResponse( return NotFoundErrorResponse(
f'No gpx file for this workout (id: {workout_short_id})' f'no gpx file for this workout (id: {workout_short_id})'
) )
try: try:
@ -464,9 +464,9 @@ def get_workout_gpx(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: :statuscode 404:
- workout not found - workout not found
- no gpx file for this workout - no gpx file for this workout
@ -534,9 +534,9 @@ def get_workout_chart_data(
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: :statuscode 404:
- workout not found - workout not found
- no gpx file for this workout - no gpx file for this workout
@ -588,9 +588,9 @@ def get_segment_gpx(
:statuscode 200: success :statuscode 200: success
:statuscode 400: no gpx file for this workout :statuscode 400: no gpx file for this workout
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: workout not found :statuscode 404: workout not found
:statuscode 500: :statuscode 500:
@ -660,9 +660,9 @@ def get_segment_chart_data(
:statuscode 200: success :statuscode 200: success
:statuscode 400: no gpx file for this workout :statuscode 400: no gpx file for this workout
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: workout not found :statuscode 404: workout not found
:statuscode 500: :statuscode 500:
@ -695,9 +695,9 @@ def get_map(map_id: int) -> Any:
:statuscode 200: success :statuscode 200: success
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: map does not exist :statuscode 404: map does not exist
:statuscode 500: :statuscode 500:
@ -855,15 +855,15 @@ def post_workout(auth_user_id: int) -> Union[Tuple[Dict, int], HttpResponse]:
:statuscode 201: workout created :statuscode 201: workout created
:statuscode 400: :statuscode 400:
- Invalid payload. - invalid payload
- No file part. - no file part
- No selected file. - no selected file
- File extension not allowed. - file extension not allowed
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 413: Error during picture update: file size exceeds 1.0MB. :statuscode 413: error during picture update: file size exceeds 1.0MB
:statuscode 500: :statuscode 500:
""" """
@ -1030,9 +1030,9 @@ def post_workout_no_gpx(
:statuscode 201: workout created :statuscode 201: workout created
:statuscode 400: invalid payload :statuscode 400: invalid payload
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 500: :statuscode 500:
""" """
@ -1185,9 +1185,9 @@ def update_workout(
:statuscode 200: workout updated :statuscode 200: workout updated
:statuscode 400: invalid payload :statuscode 400: invalid payload
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: workout not found :statuscode 404: workout not found
:statuscode 500: :statuscode 500:
@ -1248,11 +1248,11 @@ def delete_workout(
:statuscode 204: workout deleted :statuscode 204: workout deleted
:statuscode 401: :statuscode 401:
- Provide a valid auth token. - provide a valid auth token
- Signature expired. Please log in again. - signature expired, please log in again
- Invalid token. Please log in again. - invalid token, please log in again
:statuscode 404: workout not found :statuscode 404: workout not found
:statuscode 500: Error. Please try again or contact the administrator. :statuscode 500: error, please try again or contact the administrator
""" """

View File

@ -356,7 +356,12 @@
} else { } else {
if (withGpx.value) { if (withGpx.value) {
if (!gpxFile) { if (!gpxFile) {
throw new Error('No file provided !!') const errorMessage = 'workouts.NO_FILE_PROVIDED'
store.commit(
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
errorMessage
)
return
} }
payload.file = gpxFile payload.file = gpxFile
store.dispatch(WORKOUTS_STORE.ACTIONS.ADD_WORKOUT, payload) store.dispatch(WORKOUTS_STORE.ACTIONS.ADD_WORKOUT, payload)

View File

@ -1,21 +1,30 @@
{ {
"ERROR": { "ERROR": {
"UNKNOWN": "Error. Please try again or contact the administrator.", "UNKNOWN": "Error. Please try again or contact the administrator.",
"Error, Please try again or contact the administrator": "Error. Please try again or contact the administrator.", "email: valid email must be provided": "Email: valid email must be provided.",
"File extension not allowed": "File extension not allowed.", "error on getting configuration": "Error on getting configuration.",
"File size is greater than the allowed size": "File size is greater than the allowed size.", "error when updating configuration": "Error when updating configuration",
"Invalid credentials": "Invalid credentials.", "error, please try again or contact the administrator": "Error, please try again or contact the administrator.",
"Invalid payload": "Invalid data.", "error, registration is disabled": "Error, registration is disabled.",
"Invalid token, Please log in again": "Invalid token. Please log in again.", "file extension not allowed": "File extension not allowed.",
"file size is greater than the allowed size": "File size is greater than the allowed size.",
"invalid credentials": "Invalid credentials.",
"invalid payload": "Provided data are invalid.",
"invalid token, please log in again": "Invalid token, please log in again.",
"invalid token, please request a new token": "Invalid token, please log in again.",
"Network Error": "Network Error.", "Network Error": "Network Error.",
"No file part": "No file provided.", "no file part": "No file provided.",
"No selected file": "No selected file.", "no selected file": "No selected file.",
"Provide a valid auth token": "Provide a valid auth token.", "password: password and password confirmation do not match": "Password: password and password confirmation don't match.",
"Password and password confirmation don't match": "Password and password confirmation don't match.", "provide a valid auth token": "Provide a valid auth token.",
"Password: 8 characters required": "Password: 8 characters required.", "password: 8 characters required": "Password: 8 characters required.",
"Signature expired, Please log in again": "Signature expired. Please log in again.", "sorry, that user already exists": "Sorry, that user already exists.",
"Username: 3 to 12 characters required": "Username: 3 to 12 characters required.", "sport does not exist": "Sport does not exist.",
"Valid email must be provided": "Valid email must be provided." "signature expired, please log in again": "Signature expired. Please log in again.",
"successfully registered": "Successfully registered.",
"user does not exist": "User does not exist.",
"username: 3 to 12 characters required": "Username: 3 to 12 characters required.",
"you do not have permissions": "You do not have permissions."
}, },
"PAGINATION": { "PAGINATION": {
"PREVIOUS": "previous", "PREVIOUS": "previous",

View File

@ -27,6 +27,7 @@
"NEXT_SEGMENT": "No next segment", "NEXT_SEGMENT": "No next segment",
"NEXT_WORKOUT": "Next workout", "NEXT_WORKOUT": "Next workout",
"NO_DATA_CLEANING": "data from gpx, without any cleaning", "NO_DATA_CLEANING": "data from gpx, without any cleaning",
"NO_FILE_PROVIDED": "No file provided",
"NO_FOLDER": "no folder inside", "NO_FOLDER": "no folder inside",
"NO_MAP": "No map", "NO_MAP": "No map",
"NO_NEXT_SEGMENT": "No next segment", "NO_NEXT_SEGMENT": "No next segment",

View File

@ -1,21 +1,30 @@
{ {
"ERROR": { "ERROR": {
"UNKNOWN": "Erreur. Veuillez réessayer ou contacter l'administrateur.", "UNKNOWN": "Erreur. Veuillez réessayer ou contacter l'administrateur.",
"Error, Please try again or contact the administrator": "Erreur. Veuillez réessayer ou contacter l'administrateur.", "email: valid email must be provided": "Email : une adresse email valide doit être fournie.",
"File extension not allowed": "Extension de fichier non autorisée.", "error on getting configuration": "Erreur lors de la récupération de la configuration.",
"File size is greater than the allowed size": "La taille du fichier est supérieure à la limite autorisée.", "error when updating configuration": "Erreur lors de la mise à jour de la configuration",
"Invalid credentials": "Identifiants invalides.", "error, please try again or contact the administrator": "Erreur, veuillez réessayer ou contacter l'administrateur.",
"Invalid payload": "Données incorrectes.", "error, registration is disabled": "Erreur, les inscriptions sont désactivées.",
"Invalid token, Please log in again": "Jeton invalide. Merci de vous reconnecter.", "file extension not allowed": "Extension de fichier non autorisée.",
"No file part": "Pas de fichier fourni.", "file size is greater than the allowed size": "La taille du fichier est supérieure à la limite autorisée.",
"No selected file": "Pas de fichier sélectionné.", "invalid credentials": "Identifiants invalides.",
"invalid payload": "Données fournies incorrectes.",
"invalid token, please log in again": "Jeton de connexion invalide, merci de vous reconnecter.",
"invalid token, please request a new token": "Jeton de connexion, merci de vous reconnecter.",
"no file part": "Pas de fichier fourni.",
"no selected file": "Pas de fichier sélectionné.",
"Network Error": "Erreur Réseau.", "Network Error": "Erreur Réseau.",
"Provide a valid auth token": "Merci de fournir un jeton valide.", "password: password and password confirmation do not match": "Mot de passe : les mots de passe saisis sont différents.",
"Password and password confirmation don't match": "Les mots de passe saisis sont différents.", "provide a valid auth token": "Merci de fournir un jeton de connexion valide.",
"Password: 8 characters required": "8 caractères minimum pour le mot de passe.", "password: 8 characters required": "Mot de passe : 8 caractères minimum.",
"Signature expired, Please log in again": "Signature expirée. Merci de vous reconnecter.", "sport does not exist": "Ce sport n'existe pas.",
"Username: 3 to 12 characters required": "3 à 12 caractères requis pour le nom.", "signature expired, please log in again": "Signature expirée. Merci de vous reconnecter.",
"Valid email must be provided": "L'email fourni n'est pas valide." "sorry, that user already exists": "Désolé, cet utilisateur existe déjà.",
"successfully registered": "Inscription validée.",
"user does not exist": "L'utilisateur n'existe pas",
"username: 3 to 12 characters required": "Nom d'utilisateur : 3 à 12 caractères requis.",
"you do not have permissions": "Vous n'avez pas les permissions nécessaires."
}, },
"PAGINATION": { "PAGINATION": {
"PREVIOUS": "précédent", "PREVIOUS": "précédent",

View File

@ -27,6 +27,7 @@
"NEXT_SEGMENT": "Segment suivant", "NEXT_SEGMENT": "Segment suivant",
"NEXT_WORKOUT": "Séance suivante", "NEXT_WORKOUT": "Séance suivante",
"NO_DATA_CLEANING": "données issues du fichier gpx, sans correction", "NO_DATA_CLEANING": "données issues du fichier gpx, sans correction",
"NO_FILE_PROVIDED": "Pas de fichier fourni",
"NO_FOLDER": "pas de répertoire", "NO_FOLDER": "pas de répertoire",
"NO_MAP": "Pas de carte", "NO_MAP": "Pas de carte",
"NO_NEXT_SEGMENT": "Pas de segment suivant", "NO_NEXT_SEGMENT": "Pas de segment suivant",

View File

@ -15,11 +15,6 @@ export const getApiUrl = (): string => {
: `${process.env.VUE_APP_API_URL}/api/` : `${process.env.VUE_APP_API_URL}/api/`
} }
// TODO: update api error messages to remove these workarounds
const removeLastEndOfLine = (text: string): string => text.replace(/\n$/gm, '')
const removeLastDot = (text: string): string => text.replace(/\.$/gm, '')
const replaceInternalDots = (text: string): string => text.replace(/\./gm, ',')
export const handleError = ( export const handleError = (
context: context:
| ActionContext<IRootState, IRootState> | ActionContext<IRootState, IRootState>
@ -31,25 +26,24 @@ export const handleError = (
error: AxiosError | null, error: AxiosError | null,
msg = 'UNKNOWN' msg = 'UNKNOWN'
): void => { ): void => {
let errorMessages = !error const errorMessages = !error
? msg ? msg
: error.response : error.response
? error.response.status === 413 ? error.response.status === 413
? 'File size is greater than the allowed size' ? 'file size is greater than the allowed size'
: error.response.data.message : error.response.data.message
? error.response.data.message ? error.response.data.message
: msg : msg
: error.message : error.message
? error.message ? error.message
: msg : msg
errorMessages = removeLastEndOfLine(errorMessages)
errorMessages = replaceInternalDots(errorMessages)
context.commit( context.commit(
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES, ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
errorMessages.includes('\n') errorMessages.includes('\n')
? errorMessages ? errorMessages
.split('\n') .split('\n')
.map((m: string) => `api.ERROR.${removeLastDot(m)}`) .filter((m: string) => m !== '')
: `api.ERROR.${removeLastDot(errorMessages)}` .map((m: string) => `api.ERROR.${m}`)
: `api.ERROR.${errorMessages}`
) )
} }