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 500: Error on getting configuration.
:statuscode 500: error on getting configuration
"""
try:
@ -57,7 +57,7 @@ def get_application_config() -> Union[Dict, HttpResponse]:
return {'status': 'success', 'data': config.serialize()}
except (MultipleResultsFound, NoResultFound) as e:
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 400: invalid payload
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
:statuscode 403: You do not have permissions.
:statuscode 500: Error on updating configuration.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 403: you do not have permissions
:statuscode 500: error when updating configuration
"""
config_data = request.get_json()
if not config_data:
@ -145,7 +145,7 @@ def update_application_config(auth_user_id: int) -> Union[Dict, HttpResponse]:
except Exception as e:
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"
},
{
"revision": "2cfd100ce4c5acaf0068499df96fa840",
"revision": "45170abcbb428b727d6c19c2ad2b035e",
"url": "/index.html"
},
{
@ -80,7 +80,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/admin.c784857e.css"
},
{
"revision": "d9bfacb8dc8f5a151839",
"revision": "08e51982ad17cd69b5d3",
"url": "/static/css/app.6f17ce7a.css"
},
{
@ -108,8 +108,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/reset.528e2916.css"
},
{
"revision": "71aefc8221f9e9fcf5c2",
"url": "/static/css/workouts.80ddc1b5.css"
"revision": "37e775456654cbd24e0b",
"url": "/static/css/workouts.105c79ea.css"
},
{
"revision": "e719f9244c69e28e7d00e725ca1e280e",
@ -196,8 +196,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/admin.b2c267a7.js"
},
{
"revision": "d9bfacb8dc8f5a151839",
"url": "/static/js/app.da2a9740.js"
"revision": "08e51982ad17cd69b5d3",
"url": "/static/js/app.cbc2c869.js"
},
{
"revision": "bd7d183c9f68e5f4027d",
@ -240,7 +240,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/reset.607f183f.js"
},
{
"revision": "71aefc8221f9e9fcf5c2",
"url": "/static/js/workouts.850179fa.js"
"revision": "37e775456654cbd24e0b",
"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(
"/precache-manifest.2993d681f0886c270e7f04b02d8ff7c6.js"
"/precache-manifest.2384a8066007a7b5a9dea87ccb53b3f8.js"
);
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,
status: Optional[str] = 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)
@ -84,7 +84,7 @@ class DataInvalidPayloadErrorResponse(HttpResponse):
class UnauthorizedErrorResponse(GenericErrorResponse):
def __init__(self, message: Optional[str] = None) -> None:
message = (
'Invalid token. Please request a new token.'
'invalid token, please request a new token'
if message is None
else message
)
@ -93,9 +93,7 @@ class UnauthorizedErrorResponse(GenericErrorResponse):
class ForbiddenErrorResponse(GenericErrorResponse):
def __init__(self, message: Optional[str] = None) -> None:
message = (
'You do not have permissions.' if message is None else message
)
message = 'you do not have permissions' if message is None else message
super().__init__(status_code=403, message=message)
@ -106,7 +104,7 @@ class NotFoundErrorResponse(GenericErrorResponse):
class UserNotFoundErrorResponse(NotFoundErrorResponse):
def __init__(self) -> None:
super().__init__(message='User does not exist.')
super().__init__(message='user does not exist')
class DataNotFoundErrorResponse(HttpResponse):
@ -142,7 +140,7 @@ class InternalServerErrorResponse(GenericErrorResponse):
self, message: Optional[str] = None, status: Optional[str] = None
):
message = (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
if message is None
else message
)

View File

@ -48,7 +48,7 @@ class TestGetConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 500
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(
self, app: Flask, app_config: Flask, user_1_admin: User
@ -66,7 +66,7 @@ class TestGetConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 500
assert 'error' in data['status']
assert 'Error on getting configuration.' in data['message']
assert 'error on getting configuration' in data['message']
class TestUpdateConfig(ApiTestCaseMixin):
@ -138,7 +138,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
assert response.status_code == 403
assert 'success' not 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(
self, app: Flask, user_1_admin: User
@ -157,7 +157,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
self, app_no_config: Flask, user_1_admin: User
@ -176,7 +176,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 500
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(
self, app: Flask, user_1_admin: User

View File

@ -32,7 +32,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'Successfully registered.'
assert data['message'] == 'successfully registered'
assert data['auth_token']
assert response.content_type == 'application/json'
assert response.status_code == 201
@ -55,7 +55,7 @@ class TestUserRegistration:
)
data = json.loads(response.data.decode())
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.status_code == 400
@ -79,7 +79,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode())
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.status_code == 400
@ -101,7 +101,7 @@ class TestUserRegistration:
)
data = json.loads(response.data.decode())
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.status_code == 400
@ -123,7 +123,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode())
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.status_code == 400
@ -147,7 +147,7 @@ class TestUserRegistration:
data = json.loads(response.data.decode())
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.status_code == 400
@ -171,7 +171,7 @@ class TestUserRegistration:
assert data['status'] == 'error'
assert (
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.status_code == 400
@ -185,7 +185,7 @@ class TestUserRegistration:
)
data = json.loads(response.data.decode())
assert response.status_code, 400
assert 'Invalid payload.', data['message']
assert 'invalid payload', data['message']
assert 'error', data['status']
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())
assert response.status_code == 400
assert 'Invalid payload.' in data['message']
assert 'invalid payload' in data['message']
assert 'error' in data['status']
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())
assert response.status_code == 400
assert 'Invalid payload.' in data['message']
assert 'invalid payload' in data['message']
assert 'error' in data['status']
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())
assert response.status_code == 400
assert 'Invalid payload.', data['message']
assert 'invalid payload', data['message']
assert 'error', data['status']
def test_it_returns_error_if_password_confirmation_is_missing(
@ -263,7 +263,7 @@ class TestUserRegistration:
)
data = json.loads(response.data.decode())
assert response.status_code == 400
assert 'Invalid payload.' in data['message']
assert 'invalid payload' in data['message']
assert 'error' in data['status']
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())
assert response.status_code == 500
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
assert 'error' in data['status']
@ -305,7 +305,7 @@ class TestUserLogin:
assert response.status_code == 200
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'Successfully logged in.'
assert data['message'] == 'successfully logged in'
assert data['auth_token']
def test_it_returns_error_if_user_does_not_exists(
@ -323,7 +323,7 @@ class TestUserLogin:
assert response.status_code == 401
data = json.loads(response.data.decode())
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:
client = app.test_client()
@ -338,7 +338,7 @@ class TestUserLogin:
assert response.status_code == 400
data = json.loads(response.data.decode())
assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.'
assert data['message'] == 'invalid payload'
def test_it_returns_error_if_password_is_invalid(
self, app: Flask, user_1: User
@ -355,7 +355,7 @@ class TestUserLogin:
assert response.status_code == 401
data = json.loads(response.data.decode())
assert data['status'] == 'error'
assert data['message'] == 'Invalid credentials.'
assert data['message'] == 'invalid credentials'
class TestUserLogout(ApiTestCaseMixin):
@ -370,7 +370,7 @@ class TestUserLogout(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'Successfully logged out.'
assert data['message'] == 'successfully logged out'
assert response.status_code == 200
def test_it_returns_error_with_expired_token(
@ -386,7 +386,7 @@ class TestUserLogout(ApiTestCaseMixin):
)
data = json.loads(response.data.decode())
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
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())
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
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())
data = json.loads(response.data.decode())
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
@ -509,7 +509,7 @@ class TestUserProfile(ApiTestCaseMixin):
)
data = json.loads(response.data.decode())
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
@ -536,7 +536,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'User profile updated.'
assert data['message'] == 'user profile updated'
assert response.status_code == 200
assert data['data']['username'] == 'test'
assert data['data']['email'] == 'test@test.com'
@ -579,7 +579,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'User profile updated.'
assert data['message'] == 'user profile updated'
assert response.status_code == 200
assert data['data']['username'] == 'test'
assert data['data']['email'] == 'test@test.com'
@ -614,7 +614,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.'
assert data['message'] == 'invalid payload'
assert response.status_code == 400
def test_it_returns_error_if_payload_is_empty(
@ -631,7 +631,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
assert 'Invalid payload.' in data['message']
assert 'invalid payload' in data['message']
assert 'error' in data['status']
def test_it_returns_error_if_passwords_mismatch(
@ -660,7 +660,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
assert data['status'] == 'error'
assert (
data['message']
== 'Password and password confirmation don\'t match.\n'
== 'password: password and password confirmation do not match\n'
)
assert response.status_code == 400
@ -689,7 +689,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
assert data['status'] == 'error'
assert (
data['message']
== 'Password and password confirmation don\'t match.\n'
== 'password: password and password confirmation do not match\n'
)
assert response.status_code == 400
@ -715,7 +715,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'User preferences updated.'
assert data['message'] == 'user preferences updated'
assert response.status_code == 200
assert data['data']['username'] == 'test'
assert data['data']['email'] == 'test@test.com'
@ -750,7 +750,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.'
assert data['message'] == 'invalid payload'
assert response.status_code == 400
def test_it_returns_error_if_payload_is_empty(
@ -767,7 +767,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
assert 'Invalid payload.' in data['message']
assert 'invalid payload' in data['message']
assert 'error' in data['status']
@ -786,7 +786,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'User picture updated.'
assert data['message'] == 'user picture updated'
assert response.status_code == 200
assert 'avatar.png' in user_1.picture
@ -801,7 +801,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'success'
assert data['message'] == 'User picture updated.'
assert data['message'] == 'user picture updated'
assert response.status_code == 200
assert 'avatar.png' not in user_1.picture
assert 'avatar2.png' in user_1.picture
@ -821,7 +821,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'fail'
assert data['message'] == 'No file part.'
assert data['message'] == 'no file part'
assert response.status_code == 400
def test_it_returns_error_if_file_is_invalid(
@ -840,7 +840,7 @@ class TestUserPicture(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert data['status'] == 'fail'
assert data['message'] == 'File extension not allowed.'
assert data['message'] == 'file extension not allowed'
assert response.status_code == 400
def test_it_returns_error_if_image_size_exceeds_file_limit(
@ -935,7 +935,7 @@ class TestRegistrationConfiguration:
assert response.status_code == 403
data = json.loads(response.data.decode())
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(
self,
@ -973,7 +973,7 @@ class TestRegistrationConfiguration:
assert response.status_code == 403
data = json.loads(response.data.decode())
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(
self,
@ -1024,7 +1024,7 @@ class TestPasswordResetRequest:
assert response.status_code == 200
data = json.loads(response.data.decode())
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(
self, app: Flask
@ -1040,7 +1040,7 @@ class TestPasswordResetRequest:
assert response.status_code == 200
data = json.loads(response.data.decode())
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:
client = app.test_client()
@ -1053,7 +1053,7 @@ class TestPasswordResetRequest:
assert response.status_code == 400
data = json.loads(response.data.decode())
assert data['message'] == 'Invalid payload.'
assert data['message'] == 'invalid payload'
assert data['status'] == 'error'
def test_it_returns_error_on_empty_payload(self, app: Flask) -> None:
@ -1067,7 +1067,7 @@ class TestPasswordResetRequest:
assert response.status_code == 400
data = json.loads(response.data.decode())
assert data['message'] == 'Invalid payload.'
assert data['message'] == 'invalid payload'
assert data['status'] == 'error'
@ -1089,7 +1089,7 @@ class TestPasswordUpdate:
assert response.status_code == 400
data = json.loads(response.data.decode())
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:
client = app.test_client()
@ -1108,7 +1108,7 @@ class TestPasswordUpdate:
assert response.status_code == 400
data = json.loads(response.data.decode())
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:
client = app.test_client()
@ -1127,7 +1127,7 @@ class TestPasswordUpdate:
assert response.status_code == 400
data = json.loads(response.data.decode())
assert data['status'] == 'error'
assert data['message'] == 'Invalid payload.'
assert data['message'] == 'invalid payload'
def test_it_returns_error_if_password_confirmation_is_missing(
self, app: Flask
@ -1148,7 +1148,7 @@ class TestPasswordUpdate:
assert response.status_code == 400
data = json.loads(response.data.decode())
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:
token = get_user_token(1)
@ -1169,7 +1169,7 @@ class TestPasswordUpdate:
assert response.status_code == 401
data = json.loads(response.data.decode())
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(
self, app: Flask, user_1: User
@ -1195,7 +1195,7 @@ class TestPasswordUpdate:
data = json.loads(response.data.decode())
assert data['status'] == 'error'
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(
@ -1219,7 +1219,7 @@ class TestPasswordUpdate:
assert response.status_code == 400
data = json.loads(response.data.decode())
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:
token = get_user_token(user_1.id, password_reset=True)
@ -1240,4 +1240,4 @@ class TestPasswordUpdate:
assert response.status_code == 200
data = json.loads(response.data.decode())
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 'not found' in data['status']
assert 'User does not exist.' in data['message']
assert 'user does not exist' in data['message']
class TestGetUsers(ApiTestCaseMixin):
@ -800,7 +800,7 @@ class TestGetUserPicture:
data = json.loads(response.data.decode())
assert response.status_code == 404
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):
@ -866,7 +866,7 @@ class TestUpdateUser(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
self, app: Flask, user_1_admin: User, user_2: User
@ -886,7 +886,7 @@ class TestUpdateUser(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
@ -905,7 +905,7 @@ class TestUpdateUser(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 403
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):
@ -977,7 +977,7 @@ class TestDeleteUser(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 403
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(
self, app: Flask, user_1: User
@ -992,7 +992,7 @@ class TestDeleteUser(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 404
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(
self, app: Flask, user_1_admin: User, user_2: User
@ -1103,4 +1103,4 @@ class TestDeleteUser(ApiTestCaseMixin):
assert response.status_code == 403
data = json.loads(response.data.decode())
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 'success' not 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(
self, app: Flask, user_1_admin: User
@ -315,7 +315,7 @@ class TestUpdateSport(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
self, app: Flask, user_1_admin: User

View File

@ -37,7 +37,7 @@ class TestGetStatsByTime(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 404
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(
self,
@ -62,7 +62,7 @@ class TestGetStatsByTime(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
@ -867,7 +867,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 404
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(
self,
@ -888,7 +888,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 404
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(
self,
@ -910,7 +910,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
@ -988,4 +988,4 @@ class TestGetAllStats(ApiTestCaseMixin):
assert response.status_code == 403
assert 'success' not 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())
assert response.status_code == 401
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):
@ -228,7 +228,7 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
@ -707,7 +707,7 @@ class TestGetWorkout(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 403
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(
self, app: Flask, user_1: User
@ -738,7 +738,7 @@ class TestGetWorkout(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 404
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'] == ''
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())
assert response.status_code == 404
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'] == ''
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 'not found' in data['status']
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']
)
@ -800,7 +800,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 404
assert 'not found' in data['status']
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']
)
@ -823,7 +823,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
assert 'data' not in data
@ -847,7 +847,7 @@ class TestGetWorkout(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
assert 'data' not in data

View File

@ -468,7 +468,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
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())
assert response.status_code == 400
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(
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())
assert response.status_code == 400
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(
self,
@ -605,7 +605,7 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
self, app: Flask, user_1: User, sport_1_cycling: Sport
@ -911,7 +911,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
assert data['status'] == 'error'
assert (
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(
@ -1025,7 +1025,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 403
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(
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())
assert response.status_code == 403
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(
self,
@ -217,7 +217,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
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 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)
@ -405,7 +405,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 403
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(
self,
@ -564,7 +564,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
data = json.loads(response.data.decode())
assert response.status_code == 400
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(
self,
@ -593,7 +593,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
assert response.status_code == 500
assert 'error' in data['status']
assert (
'Error. Please try again or contact the administrator.'
'error, please try again or contact the administrator'
in data['message']
)

View File

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

View File

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

View File

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

View File

@ -37,9 +37,9 @@ def check_passwords(password: str, password_conf: str) -> str:
"""
ret = ''
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:
ret += 'Password: 8 characters required.\n'
ret += 'password: 8 characters required\n'
return ret
@ -53,9 +53,9 @@ def register_controls(
"""
ret = ''
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):
ret += 'Valid email must be provided.\n'
ret += 'email: valid email must be provided\n'
ret += check_passwords(password, password_conf)
return ret
@ -67,7 +67,7 @@ def verify_user(
Return user id, if the provided token is valid and if user has admin
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')
if not auth_header:
return UnauthorizedErrorResponse(default_message), None

View File

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

View File

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

View File

@ -147,9 +147,9 @@ def get_sports(auth_user_id: int) -> Dict:
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
"""
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 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404: sport not found
"""
@ -319,10 +319,10 @@ def update_sport(
:statuscode 200: sport updated
:statuscode 400: invalid payload
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
:statuscode 403: You do not have permissions.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 403: you do not have permissions
:statuscode 404: sport not found
:statuscode 500:

View File

@ -42,7 +42,7 @@ def get_workouts(
if sport_id:
sport = Sport.query.filter_by(id=sport_id).first()
if not sport:
return NotFoundErrorResponse('Sport does not exist.')
return NotFoundErrorResponse('sport does not exist')
workouts = (
Workout.query.filter(
@ -247,11 +247,11 @@ def get_workouts_by_time(
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404:
- User does not exist.
- user does not exist
"""
return get_workouts(user_name, 'by_time')
@ -340,12 +340,12 @@ def get_workouts_by_sport(
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404:
- User does not exist.
- Sport does not exist.
- user does not exist
- sport does not exist
"""
return get_workouts(user_name, 'by_sport')
@ -387,10 +387,10 @@ def get_application_stats(auth_user_id: int) -> Dict:
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
:statuscode 403: You do not have permissions.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 403: you do not have permissions
"""
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 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 500:
"""
@ -343,10 +343,10 @@ def get_workout(
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
:statuscode 403: You do not have permissions.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 403: you do not have permissions
:statuscode 404: workout not found
"""
@ -377,7 +377,7 @@ def get_workout_data(
if not workout:
return DataNotFoundErrorResponse(
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)
@ -385,7 +385,7 @@ def get_workout_data(
return error_response
if not workout.gpx or workout.gpx == '':
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:
@ -464,9 +464,9 @@ def get_workout_gpx(
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404:
- workout not found
- no gpx file for this workout
@ -534,9 +534,9 @@ def get_workout_chart_data(
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404:
- workout not found
- no gpx file for this workout
@ -588,9 +588,9 @@ def get_segment_gpx(
:statuscode 200: success
:statuscode 400: no gpx file for this workout
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404: workout not found
:statuscode 500:
@ -660,9 +660,9 @@ def get_segment_chart_data(
:statuscode 200: success
:statuscode 400: no gpx file for this workout
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404: workout not found
:statuscode 500:
@ -695,9 +695,9 @@ def get_map(map_id: int) -> Any:
:statuscode 200: success
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404: map does not exist
:statuscode 500:
@ -855,15 +855,15 @@ def post_workout(auth_user_id: int) -> Union[Tuple[Dict, int], HttpResponse]:
:statuscode 201: workout created
:statuscode 400:
- Invalid payload.
- No file part.
- No selected file.
- File extension not allowed.
- invalid payload
- no file part
- no selected file
- file extension not allowed
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
:statuscode 413: Error during picture update: file size exceeds 1.0MB.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 413: error during picture update: file size exceeds 1.0MB
:statuscode 500:
"""
@ -1030,9 +1030,9 @@ def post_workout_no_gpx(
:statuscode 201: workout created
:statuscode 400: invalid payload
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 500:
"""
@ -1185,9 +1185,9 @@ def update_workout(
:statuscode 200: workout updated
:statuscode 400: invalid payload
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
:statuscode 404: workout not found
:statuscode 500:
@ -1248,11 +1248,11 @@ def delete_workout(
:statuscode 204: workout deleted
:statuscode 401:
- Provide a valid auth token.
- Signature expired. Please log in again.
- Invalid token. Please log in again.
- provide a valid auth token
- signature expired, please log in again
- invalid token, please log in again
: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 {
if (withGpx.value) {
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
store.dispatch(WORKOUTS_STORE.ACTIONS.ADD_WORKOUT, payload)

View File

@ -1,21 +1,30 @@
{
"ERROR": {
"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.",
"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": "Invalid data.",
"Invalid token, Please log in again": "Invalid token. Please log in again.",
"email: valid email must be provided": "Email: valid email must be provided.",
"error on getting configuration": "Error on getting configuration.",
"error when updating configuration": "Error when updating configuration",
"error, please try again or contact the administrator": "Error, please try again or contact the administrator.",
"error, registration is disabled": "Error, registration is disabled.",
"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.",
"No file part": "No file provided.",
"No selected file": "No selected file.",
"Provide a valid auth token": "Provide a valid auth token.",
"Password and password confirmation don't match": "Password and password confirmation don't match.",
"Password: 8 characters required": "Password: 8 characters required.",
"Signature expired, Please log in again": "Signature expired. Please log in again.",
"Username: 3 to 12 characters required": "Username: 3 to 12 characters required.",
"Valid email must be provided": "Valid email must be provided."
"no file part": "No file provided.",
"no selected file": "No selected file.",
"password: password and password confirmation do not match": "Password: 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.",
"sorry, that user already exists": "Sorry, that user already exists.",
"sport does not exist": "Sport does not exist.",
"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": {
"PREVIOUS": "previous",

View File

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

View File

@ -1,21 +1,30 @@
{
"ERROR": {
"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.",
"File extension not allowed": "Extension de fichier non autorisée.",
"File size is greater than the allowed size": "La taille du fichier est supérieure à la limite autorisée.",
"Invalid credentials": "Identifiants invalides.",
"Invalid payload": "Données incorrectes.",
"Invalid token, Please log in again": "Jeton invalide. Merci de vous reconnecter.",
"No file part": "Pas de fichier fourni.",
"No selected file": "Pas de fichier sélectionné.",
"email: valid email must be provided": "Email : une adresse email valide doit être fournie.",
"error on getting configuration": "Erreur lors de la récupération de la configuration.",
"error when updating configuration": "Erreur lors de la mise à jour de la configuration",
"error, please try again or contact the administrator": "Erreur, veuillez réessayer ou contacter l'administrateur.",
"error, registration is disabled": "Erreur, les inscriptions sont désactivées.",
"file extension not allowed": "Extension de fichier non autorisée.",
"file size is greater than the allowed size": "La taille du fichier est supérieure à la limite autorisée.",
"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.",
"Provide a valid auth token": "Merci de fournir un jeton valide.",
"Password and password confirmation don't match": "Les mots de passe saisis sont différents.",
"Password: 8 characters required": "8 caractères minimum pour le mot de passe.",
"Signature expired, Please log in again": "Signature expirée. Merci de vous reconnecter.",
"Username: 3 to 12 characters required": "3 à 12 caractères requis pour le nom.",
"Valid email must be provided": "L'email fourni n'est pas valide."
"password: password and password confirmation do not match": "Mot de passe : 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": "Mot de passe : 8 caractères minimum.",
"sport does not exist": "Ce sport n'existe pas.",
"signature expired, please log in again": "Signature expirée. Merci de vous reconnecter.",
"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": {
"PREVIOUS": "précédent",

View File

@ -27,6 +27,7 @@
"NEXT_SEGMENT": "Segment suivant",
"NEXT_WORKOUT": "Séance suivante",
"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_MAP": "Pas de carte",
"NO_NEXT_SEGMENT": "Pas de segment suivant",

View File

@ -15,11 +15,6 @@ export const getApiUrl = (): string => {
: `${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 = (
context:
| ActionContext<IRootState, IRootState>
@ -31,25 +26,24 @@ export const handleError = (
error: AxiosError | null,
msg = 'UNKNOWN'
): void => {
let errorMessages = !error
const errorMessages = !error
? msg
: error.response
? 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
: msg
: error.message
? error.message
: msg
errorMessages = removeLastEndOfLine(errorMessages)
errorMessages = replaceInternalDots(errorMessages)
context.commit(
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
errorMessages.includes('\n')
? errorMessages
.split('\n')
.map((m: string) => `api.ERROR.${removeLastDot(m)}`)
: `api.ERROR.${removeLastDot(errorMessages)}`
.filter((m: string) => m !== '')
.map((m: string) => `api.ERROR.${m}`)
: `api.ERROR.${errorMessages}`
)
}