API - refactor api responses
This commit is contained in:
@ -833,7 +833,7 @@ class TestGetActivity:
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert 'not found' in data['status']
|
||||
assert (
|
||||
f'No gpx file for this activity (id: {activity_short_id})'
|
||||
in data['message']
|
||||
@ -860,7 +860,7 @@ class TestGetActivity:
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert 'not found' in data['status']
|
||||
assert (
|
||||
f'No gpx file for this activity (id: {activity_short_id})'
|
||||
in data['message']
|
||||
@ -888,7 +888,10 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 500
|
||||
assert 'error' in data['status']
|
||||
assert 'internal error' in data['message']
|
||||
assert (
|
||||
'Error. Please try again or contact the administrator.'
|
||||
in data['message']
|
||||
)
|
||||
assert 'data' not in data
|
||||
|
||||
def test_it_returns_500_on_getting_chart_data_if_an_activity_has_invalid_gpx_pathname( # noqa
|
||||
@ -913,7 +916,10 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 500
|
||||
assert 'error' in data['status']
|
||||
assert 'internal error' in data['message']
|
||||
assert (
|
||||
'Error. Please try again or contact the administrator.'
|
||||
in data['message']
|
||||
)
|
||||
assert 'data' not in data
|
||||
|
||||
def test_it_returns_404_if_activity_has_no_map(self, app, user_1):
|
||||
@ -933,5 +939,5 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert 'not found' in data['status']
|
||||
assert 'Map does not exist' in data['message']
|
||||
|
@ -843,7 +843,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
|
||||
assert response.status_code == 500
|
||||
assert data['status'] == 'error'
|
||||
assert data['message'] == 'internal error.'
|
||||
assert (
|
||||
data['message']
|
||||
== 'Error. Please try again or contact the administrator.'
|
||||
)
|
||||
|
||||
def test_it_gets_an_activity_created_with_gpx(
|
||||
self, app, user_1, sport_1_cycling, gpx_file
|
||||
|
@ -162,7 +162,7 @@ class TestUserRegistration:
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_it_returns_error_if_paylaod_is_invalid(self, app):
|
||||
def test_it_returns_error_if_payload_is_invalid(self, app):
|
||||
client = app.test_client()
|
||||
response = client.post(
|
||||
'/api/auth/register',
|
||||
@ -278,43 +278,49 @@ class TestUserRegistration:
|
||||
class TestUserLogin:
|
||||
def test_user_can_register(self, app, user_1):
|
||||
client = app.test_client()
|
||||
|
||||
response = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'success'
|
||||
assert data['message'] == 'Successfully logged in.'
|
||||
assert data['auth_token']
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_it_returns_error_if_user_does_not_exists(self, app):
|
||||
client = app.test_client()
|
||||
|
||||
response = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 401
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert data['message'] == 'Invalid credentials.'
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_it_returns_error_on_invalid_payload(self, app):
|
||||
client = app.test_client()
|
||||
|
||||
response = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict()),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert data['message'] == 'Invalid payload.'
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_it_returns_error_if_password_is_invalid(self, app, user_1):
|
||||
client = app.test_client()
|
||||
@ -325,11 +331,11 @@ class TestUserLogin:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 401
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'error'
|
||||
assert data['message'] == 'Invalid credentials.'
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
class TestUserLogout:
|
||||
|
@ -111,7 +111,7 @@ class TestGetUser:
|
||||
data = json.loads(response.data.decode())
|
||||
|
||||
assert response.status_code == 404
|
||||
assert 'fail' in data['status']
|
||||
assert 'not found' in data['status']
|
||||
assert 'User does not exist.' in data['message']
|
||||
|
||||
|
||||
@ -972,7 +972,7 @@ class TestGetUserPicture:
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'fail' in data['status']
|
||||
assert 'not found' in data['status']
|
||||
assert 'User does not exist.' in data['message']
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user