API - add uuid to activity and return it instead of id to client - #57
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import json
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
class TestGetActivities:
|
||||
@ -694,7 +695,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid.hex}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -726,7 +727,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_2.uuid.hex}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -747,7 +748,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/11',
|
||||
f'/api/activities/{uuid4().hex}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -762,6 +763,7 @@ class TestGetActivity:
|
||||
def test_it_returns_404_on_getting_gpx_if_activity_does_not_exist(
|
||||
self, app, user_1
|
||||
):
|
||||
random_uuid = uuid4().hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -770,7 +772,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/11/gpx',
|
||||
f'/api/activities/{random_uuid}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -780,12 +782,13 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
assert 'Activity not found (id: 11)' in data['message']
|
||||
assert f'Activity not found (id: {random_uuid})' in data['message']
|
||||
assert data['data']['gpx'] == ''
|
||||
|
||||
def test_it_returns_404_on_getting_chart_data_if_activity_does_not_exist(
|
||||
self, app, user_1
|
||||
):
|
||||
random_uuid = uuid4().hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -794,7 +797,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/11/chart_data',
|
||||
f'/api/activities/{random_uuid}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -804,12 +807,13 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
assert 'Activity not found (id: 11)' in data['message']
|
||||
assert f'Activity not found (id: {random_uuid})' in data['message']
|
||||
assert data['data']['chart_data'] == ''
|
||||
|
||||
def test_it_returns_404_on_getting_gpx_if_activity_have_no_gpx(
|
||||
self, app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -818,7 +822,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1/gpx',
|
||||
f'/api/activities/{activity_uuid}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -828,11 +832,15 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert 'No gpx file for this activity (id: 1)' in data['message']
|
||||
assert (
|
||||
f'No gpx file for this activity (id: {activity_uuid})'
|
||||
in data['message']
|
||||
)
|
||||
|
||||
def test_it_returns_404_if_activity_have_no_chart_data(
|
||||
self, app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -841,7 +849,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data',
|
||||
f'/api/activities/{activity_uuid}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -851,7 +859,10 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert 'No gpx file for this activity (id: 1)' in data['message']
|
||||
assert (
|
||||
f'No gpx file for this activity (id: {activity_uuid})'
|
||||
in data['message']
|
||||
)
|
||||
|
||||
def test_it_returns_500_on_getting_gpx_if_an_activity_has_invalid_gpx_pathname( # noqa
|
||||
self, app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||
@ -865,7 +876,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1/gpx',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid.hex}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -881,7 +892,7 @@ class TestGetActivity:
|
||||
def test_it_returns_500_on_getting_chart_data_if_an_activity_has_invalid_gpx_pathname( # noqa
|
||||
self, app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||
):
|
||||
activity_cycling_user_1.gpx = "some path"
|
||||
activity_cycling_user_1.gpx = 'some path'
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -890,7 +901,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid.hex}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -911,7 +922,7 @@ class TestGetActivity:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.get(
|
||||
'/api/activities/map/123',
|
||||
f'/api/activities/map/{uuid4().hex}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
|
@ -32,7 +32,7 @@ def assert_activity_data_with_gpx(data):
|
||||
assert len(data['data']['activities'][0]['segments']) == 1
|
||||
|
||||
segment = data['data']['activities'][0]['segments'][0]
|
||||
assert segment['activity_id'] == 1
|
||||
assert segment['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert segment['segment_id'] == 0
|
||||
assert segment['duration'] == '0:04:10'
|
||||
assert segment['ascent'] == 0.4
|
||||
@ -48,22 +48,22 @@ def assert_activity_data_with_gpx(data):
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[0]['value'] == 5.12
|
||||
assert records[1]['sport_id'] == 1
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[1]['value'] == '0:04:10'
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 0.32
|
||||
assert records[3]['sport_id'] == 1
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.61
|
||||
@ -97,7 +97,7 @@ def assert_activity_data_with_gpx_segments(data):
|
||||
assert len(data['data']['activities'][0]['segments']) == 2
|
||||
|
||||
segment = data['data']['activities'][0]['segments'][0]
|
||||
assert segment['activity_id'] == 1
|
||||
assert segment['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert segment['segment_id'] == 0
|
||||
assert segment['duration'] == '0:01:30'
|
||||
assert segment['ascent'] is None
|
||||
@ -111,7 +111,7 @@ def assert_activity_data_with_gpx_segments(data):
|
||||
assert segment['pauses'] is None
|
||||
|
||||
segment = data['data']['activities'][0]['segments'][1]
|
||||
assert segment['activity_id'] == 1
|
||||
assert segment['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert segment['segment_id'] == 1
|
||||
assert segment['duration'] == '0:02:25'
|
||||
assert segment['ascent'] == 0.4
|
||||
@ -127,17 +127,17 @@ def assert_activity_data_with_gpx_segments(data):
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 3
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[0]['record_type'] == 'LD'
|
||||
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[0]['value'] == '0:03:55'
|
||||
assert records[1]['sport_id'] == 1
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[1]['record_type'] == 'FD'
|
||||
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[1]['value'] == 0.3
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[2]['record_type'] == 'AS'
|
||||
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 4.59
|
||||
@ -176,22 +176,22 @@ def assert_activity_data_wo_gpx(data):
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
|
||||
assert records[0]['value'] == 10.0
|
||||
assert records[1]['sport_id'] == 1
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
|
||||
assert records[2]['value'] == 10.0
|
||||
assert records[3]['sport_id'] == 1
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
|
||||
assert records[3]['value'] == 10.0
|
||||
@ -305,7 +305,7 @@ class TestPostActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -317,17 +317,10 @@ class TestPostActivityWithGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert response.status_code == 201
|
||||
assert 'created' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'just an activity' == data['data']['activities'][0]['title']
|
||||
assert 'test activity' == data['data']['activities'][0]['notes']
|
||||
@ -766,7 +759,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -779,17 +772,9 @@ class TestPostAndGetActivityWithGpx:
|
||||
),
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert response.status_code == 201
|
||||
assert 'created' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'just an activity' == data['data']['activities'][0]['title']
|
||||
if with_segments:
|
||||
@ -797,9 +782,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
else:
|
||||
assert_activity_data_with_gpx(data)
|
||||
map_id = data['data']['activities'][0]['map']
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1/gpx',
|
||||
f'/api/activities/{activity_uuid}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -813,7 +799,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
assert len(data['data']['gpx']) != ''
|
||||
|
||||
response = client.get(
|
||||
'/api/activities/1/gpx/segment/1',
|
||||
f'/api/activities/{activity_uuid}/gpx/segment/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -836,7 +822,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
assert response.status_code == 200
|
||||
|
||||
# error case in the same test to avoid generate a new map file
|
||||
activity = Activity.query.filter_by(id=1).first()
|
||||
activity = Activity.query.filter_by(uuid=activity_uuid).first()
|
||||
activity.map = 'incorrect path'
|
||||
|
||||
assert response.status_code == 200
|
||||
@ -877,7 +863,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -889,8 +875,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data',
|
||||
f'/api/activities/{activity_uuid}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -913,7 +901,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -925,8 +913,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data/segment/1',
|
||||
f'/api/activities/{activity_uuid}/chart_data/segment/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -948,7 +938,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -960,6 +950,8 @@ class TestPostAndGetActivityWithGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -967,7 +959,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data',
|
||||
f'/api/activities/{activity_uuid}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -989,7 +981,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -1001,8 +993,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data/segment/0',
|
||||
f'/api/activities/{activity_uuid}/chart_data/segment/0',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1025,7 +1019,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
@ -1037,8 +1031,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1/chart_data/segment/999999',
|
||||
f'/api/activities/{activity_uuid}/chart_data/segment/999999',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1063,7 +1059,7 @@ class TestPostAndGetActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -1079,8 +1075,10 @@ class TestPostAndGetActivityWithoutGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1103,7 +1101,7 @@ class TestPostAndGetActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -1120,8 +1118,10 @@ class TestPostAndGetActivityWithoutGpx:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1147,7 +1147,7 @@ class TestPostAndGetActivityUsingTimezones:
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -1163,8 +1163,10 @@ class TestPostAndGetActivityUsingTimezones:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
|
@ -1,10 +1,12 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
from uuid import uuid4
|
||||
|
||||
from fittrackee.activities.models import Activity
|
||||
|
||||
from .utils import post_an_activity
|
||||
|
||||
def assert_activity_data_with_gpx(data):
|
||||
|
||||
def assert_activity_data_with_gpx(data, sport_id):
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
assert (
|
||||
'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
@ -25,23 +27,23 @@ def assert_activity_data_with_gpx(data):
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 2
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['sport_id'] == sport_id
|
||||
assert records[0]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[0]['value'] == 5.12
|
||||
assert records[1]['sport_id'] == 2
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['sport_id'] == sport_id
|
||||
assert records[1]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[1]['value'] == '0:04:10'
|
||||
assert records[2]['sport_id'] == 2
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['sport_id'] == sport_id
|
||||
assert records[2]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 0.32
|
||||
assert records[3]['sport_id'] == 2
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['sport_id'] == sport_id
|
||||
assert records[3]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.61
|
||||
@ -51,73 +53,35 @@ class TestEditActivityWithGpx:
|
||||
def test_it_updates_title_for_an_activity_with_gpx(
|
||||
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Activity test")),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 2 == data['data']['activities'][0]['sport_id']
|
||||
assert sport_2_running.id == data['data']['activities'][0]['sport_id']
|
||||
assert data['data']['activities'][0]['title'] == 'Activity test'
|
||||
assert_activity_data_with_gpx(data)
|
||||
assert_activity_data_with_gpx(data, sport_2_running.id)
|
||||
|
||||
def test_it_adds_notes_for_an_activity_with_gpx(
|
||||
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(notes="test notes")),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
@ -130,24 +94,8 @@ class TestEditActivityWithGpx:
|
||||
def test_it_raises_403_when_editing_an_activity_from_different_user(
|
||||
self, app, user_1, user_2, sport_1_cycling, sport_2_running, gpx_file
|
||||
):
|
||||
_, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
@ -155,7 +103,7 @@ class TestEditActivityWithGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Activity test")),
|
||||
headers=dict(
|
||||
@ -172,73 +120,35 @@ class TestEditActivityWithGpx:
|
||||
def test_it_updates_sport(
|
||||
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2)),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 2 == data['data']['activities'][0]['sport_id']
|
||||
assert sport_2_running.id == data['data']['activities'][0]['sport_id']
|
||||
assert data['data']['activities'][0]['title'] == 'just an activity'
|
||||
assert_activity_data_with_gpx(data)
|
||||
assert_activity_data_with_gpx(data, sport_2_running.id)
|
||||
|
||||
def test_it_returns_400_if_payload_is_empty(
|
||||
self, app, user_1, sport_1_cycling, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict()),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
@ -249,33 +159,14 @@ class TestEditActivityWithGpx:
|
||||
def test_it_raises_500_if_sport_does_not_exists(
|
||||
self, app, user_1, sport_1_cycling, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2)),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
@ -296,6 +187,7 @@ class TestEditActivityWithoutGpx:
|
||||
sport_2_running,
|
||||
activity_cycling_user_1,
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -304,7 +196,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -332,7 +224,7 @@ class TestEditActivityWithoutGpx:
|
||||
== 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == 2
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] == 'Activity test'
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
@ -352,23 +244,23 @@ class TestEditActivityWithoutGpx:
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 2
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[0]['value'] == 8.0
|
||||
assert records[1]['sport_id'] == 2
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['sport_id'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == 2
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['sport_id'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[2]['value'] == 8.0
|
||||
assert records[3]['sport_id'] == 2
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['sport_id'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[3]['value'] == 8.0
|
||||
@ -376,6 +268,7 @@ class TestEditActivityWithoutGpx:
|
||||
def test_it_adds_notes_to_an_activity_wo_gpx(
|
||||
self, app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -384,7 +277,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(notes='test notes')),
|
||||
headers=dict(
|
||||
@ -403,7 +296,7 @@ class TestEditActivityWithoutGpx:
|
||||
== 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == 1
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_1_cycling.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] is None
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
@ -423,23 +316,23 @@ class TestEditActivityWithoutGpx:
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['sport_id'] == sport_1_cycling.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[0]['value'] == 10.0
|
||||
assert records[1]['sport_id'] == 1
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['sport_id'] == sport_1_cycling.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['sport_id'] == sport_1_cycling.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[2]['value'] == 10.0
|
||||
assert records[3]['sport_id'] == 1
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['sport_id'] == sport_1_cycling.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[3]['value'] == 10.0
|
||||
@ -455,7 +348,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_2.uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -485,6 +378,7 @@ class TestEditActivityWithoutGpx:
|
||||
sport_2_running,
|
||||
activity_cycling_user_1,
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -493,7 +387,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -520,7 +414,7 @@ class TestEditActivityWithoutGpx:
|
||||
== 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == 2
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] == 'Activity test'
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
@ -536,23 +430,23 @@ class TestEditActivityWithoutGpx:
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 2
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[0]['value'] == 8.0
|
||||
assert records[1]['sport_id'] == 2
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['sport_id'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == 2
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['sport_id'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[2]['value'] == 8.0
|
||||
assert records[3]['sport_id'] == 2
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['sport_id'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[3]['value'] == 8.0
|
||||
@ -565,6 +459,7 @@ class TestEditActivityWithoutGpx:
|
||||
sport_2_running,
|
||||
activity_cycling_user_1,
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -573,7 +468,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, distance=20)),
|
||||
headers=dict(
|
||||
@ -592,7 +487,7 @@ class TestEditActivityWithoutGpx:
|
||||
== 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == 2
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] is None
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
@ -608,23 +503,23 @@ class TestEditActivityWithoutGpx:
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 2
|
||||
assert records[0]['activity_id'] == 1
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[0]['value'] == 20.0
|
||||
assert records[1]['sport_id'] == 2
|
||||
assert records[1]['activity_id'] == 1
|
||||
assert records[1]['sport_id'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == 2
|
||||
assert records[2]['activity_id'] == 1
|
||||
assert records[2]['sport_id'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[2]['value'] == 20.0
|
||||
assert records[3]['sport_id'] == 2
|
||||
assert records[3]['activity_id'] == 1
|
||||
assert records[3]['sport_id'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[3]['value'] == 20.0
|
||||
@ -640,7 +535,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict()),
|
||||
headers=dict(
|
||||
@ -664,7 +559,7 @@ class TestEditActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -689,7 +584,7 @@ class TestEditActivityWithoutGpx:
|
||||
in data['message']
|
||||
)
|
||||
|
||||
def test_it_returns_404_if_edited_activity_doens_not_exists(
|
||||
def test_it_returns_404_if_edited_activity_does_not_exists(
|
||||
self, app, user_1, sport_1_cycling
|
||||
):
|
||||
client = app.test_client()
|
||||
@ -699,7 +594,7 @@ class TestEditActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{uuid4().hex}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -725,38 +620,19 @@ class TestRefreshActivityWithGpx:
|
||||
def test_refresh_an_activity_with_gpx(
|
||||
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
# Edit some activity data
|
||||
activity = Activity.query.filter_by(id=1).first()
|
||||
activity = Activity.query.filter_by(uuid=activity_uuid).first()
|
||||
activity.ascent = 1000
|
||||
activity.min_alt = -100
|
||||
|
||||
response = client.patch(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(refresh=True)),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
import json
|
||||
import os
|
||||
from io import BytesIO
|
||||
from uuid import uuid4
|
||||
|
||||
from fittrackee.activities.models import Activity
|
||||
from fittrackee.activities.utils import get_absolute_file_path
|
||||
|
||||
from .utils import post_an_activity
|
||||
|
||||
|
||||
def get_gpx_filepath(activity_id):
|
||||
activity = Activity.query.filter_by(id=activity_id).first()
|
||||
@ -15,30 +17,12 @@ class TestDeleteActivityWithGpx:
|
||||
def test_it_deletes_an_activity_with_gpx(
|
||||
self, app, user_1, sport_1_cycling, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
response = client.delete(
|
||||
'/api/activities/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
f'/api/activities/{activity_uuid}',
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
assert response.status_code == 204
|
||||
@ -46,31 +30,16 @@ class TestDeleteActivityWithGpx:
|
||||
def test_it_returns_403_when_deleting_an_activity_from_different_user(
|
||||
self, app, user_1, user_2, sport_1_cycling, gpx_file
|
||||
):
|
||||
_, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
response = client.delete(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -91,7 +60,7 @@ class TestDeleteActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
'/api/activities/9999',
|
||||
f'/api/activities/{uuid4().hex}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -104,35 +73,15 @@ class TestDeleteActivityWithGpx:
|
||||
def test_it_returns_500_when_deleting_an_activity_with_gpx_invalid_file(
|
||||
self, app, user_1, sport_1_cycling, gpx_file
|
||||
):
|
||||
token, activity_uuid = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token'],
|
||||
),
|
||||
)
|
||||
|
||||
gpx_filepath = get_gpx_filepath(1)
|
||||
gpx_filepath = get_absolute_file_path(gpx_filepath)
|
||||
os.remove(gpx_filepath)
|
||||
|
||||
response = client.delete(
|
||||
'/api/activities/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
f'/api/activities/{activity_uuid}',
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
@ -156,7 +105,7 @@ class TestDeleteActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -174,7 +123,7 @@ class TestDeleteActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
|
@ -1,3 +1,6 @@
|
||||
from .utils import is_valid_uuid
|
||||
|
||||
|
||||
class TestActivityModel:
|
||||
def test_activity_model(
|
||||
self, app, sport_1_cycling, user_1, activity_cycling_user_1
|
||||
@ -5,6 +8,7 @@ class TestActivityModel:
|
||||
activity_cycling_user_1.title = 'Test'
|
||||
|
||||
assert 1 == activity_cycling_user_1.id
|
||||
assert activity_cycling_user_1.uuid is not None
|
||||
assert 1 == activity_cycling_user_1.user_id
|
||||
assert 1 == activity_cycling_user_1.sport_id
|
||||
assert '2018-01-01 00:00:00' == str(
|
||||
@ -18,7 +22,7 @@ class TestActivityModel:
|
||||
)
|
||||
|
||||
serialized_activity = activity_cycling_user_1.serialize()
|
||||
assert 1 == serialized_activity['id']
|
||||
assert is_valid_uuid(serialized_activity['id'])
|
||||
assert 'test' == serialized_activity['user']
|
||||
assert 1 == serialized_activity['sport_id']
|
||||
assert serialized_activity['title'] == 'Test'
|
||||
@ -55,6 +59,8 @@ class TestActivityModel:
|
||||
activity_cycling_user_1,
|
||||
activity_cycling_user_1_segment,
|
||||
):
|
||||
assert '<Segment \'0\' for activity \'1\'>' == str(
|
||||
activity_cycling_user_1_segment
|
||||
assert (
|
||||
f'<Segment \'{activity_cycling_user_1_segment.segment_id}\' '
|
||||
f'for activity \'{activity_cycling_user_1.uuid.hex}\'>'
|
||||
== str(activity_cycling_user_1_segment)
|
||||
)
|
||||
|
@ -36,8 +36,11 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
)
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 1 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
== data['data']['records'][0]['activity_id']
|
||||
)
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 'value' in data['data']['records'][0]
|
||||
|
||||
@ -46,8 +49,11 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
)
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
== data['data']['records'][1]['activity_id']
|
||||
)
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 'value' in data['data']['records'][1]
|
||||
|
||||
@ -56,8 +62,11 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
)
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 1 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
== data['data']['records'][2]['activity_id']
|
||||
)
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert 'value' in data['data']['records'][2]
|
||||
|
||||
@ -66,8 +75,11 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 1 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
== data['data']['records'][3]['activity_id']
|
||||
)
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 'value' in data['data']['records'][3]
|
||||
|
||||
@ -147,7 +159,7 @@ class TestGetRecords:
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -164,6 +176,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_1_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -182,8 +196,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 1 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -192,8 +206,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -202,8 +216,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 1 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -212,14 +226,14 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 1 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# Post activity with lower duration (same sport)
|
||||
# => 2 new records: Average speed and Max speed
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -236,6 +250,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_2_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -254,8 +270,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
@ -264,8 +280,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -274,8 +290,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 1 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -284,13 +300,13 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
# Post activity with no new records
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -307,6 +323,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_3_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -325,8 +343,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
@ -335,8 +353,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -345,8 +363,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 1 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -355,15 +373,15 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
# Edit last activity
|
||||
# 1 new record: Longest duration
|
||||
client.patch(
|
||||
'/api/activities/3',
|
||||
f'/api/activities/{activity_3_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(duration=4000)),
|
||||
headers=dict(
|
||||
@ -389,8 +407,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
@ -399,8 +417,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -409,8 +427,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 3 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -419,14 +437,14 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
# delete activity 2 => AS and MS record update
|
||||
client.delete(
|
||||
'/api/activities/2',
|
||||
f'/api/activities/{activity_2_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -450,8 +468,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 1 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -460,8 +478,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -470,8 +488,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 3 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -480,14 +498,14 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 1 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# add an activity with the same data as activity 1 except with a
|
||||
# later date => no change in record
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -504,6 +522,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_4_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -522,8 +542,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 1 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -532,8 +552,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -542,8 +562,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 3 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -552,8 +572,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 1 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -561,7 +581,7 @@ class TestGetRecords:
|
||||
# an earlier date
|
||||
# => record update (activity 5 replace activity 1)
|
||||
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -578,6 +598,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_5_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -596,8 +618,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 5 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_5_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -606,8 +628,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 5 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_5_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -616,8 +638,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 3 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -626,35 +648,35 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 5 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_5_uuid == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# delete all activities - no more records
|
||||
client.delete(
|
||||
'/api/activities/1',
|
||||
f'/api/activities/{activity_1_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
'/api/activities/3',
|
||||
f'/api/activities/{activity_3_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
'/api/activities/4',
|
||||
f'/api/activities/{activity_4_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
'/api/activities/5',
|
||||
f'/api/activities/{activity_5_uuid}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -682,7 +704,7 @@ class TestGetRecords:
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -699,7 +721,9 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.post(
|
||||
data = json.loads(response.data.decode())
|
||||
activity_1_uuid = data['data']['activities'][0]['id']
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -716,6 +740,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_2_uuid = data['data']['activities'][0]['id']
|
||||
client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
@ -733,7 +759,7 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.post(
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
@ -750,6 +776,8 @@ class TestGetRecords:
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_4_uuid = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -768,8 +796,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 1 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -778,8 +806,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 1 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -788,8 +816,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 1 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -798,8 +826,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 1 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -808,8 +836,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][4]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][4]['user']
|
||||
assert 2 == data['data']['records'][4]['sport_id']
|
||||
assert 2 == data['data']['records'][4]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][4]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][4]['activity_id']
|
||||
assert 'AS' == data['data']['records'][4]['record_type']
|
||||
assert 20.0 == data['data']['records'][4]['value']
|
||||
|
||||
@ -818,8 +846,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][5]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][5]['user']
|
||||
assert 2 == data['data']['records'][5]['sport_id']
|
||||
assert 2 == data['data']['records'][5]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][5]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][5]['activity_id']
|
||||
assert 'FD' == data['data']['records'][5]['record_type']
|
||||
assert 20.0 == data['data']['records'][5]['value']
|
||||
|
||||
@ -828,8 +856,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][6]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][6]['user']
|
||||
assert 2 == data['data']['records'][6]['sport_id']
|
||||
assert 2 == data['data']['records'][6]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][6]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][6]['activity_id']
|
||||
assert 'LD' == data['data']['records'][6]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][6]['value']
|
||||
|
||||
@ -838,13 +866,13 @@ class TestGetRecords:
|
||||
== data['data']['records'][7]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][7]['user']
|
||||
assert 2 == data['data']['records'][7]['sport_id']
|
||||
assert 2 == data['data']['records'][7]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][7]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][7]['activity_id']
|
||||
assert 'MS' == data['data']['records'][7]['record_type']
|
||||
assert 20.0 == data['data']['records'][7]['value']
|
||||
|
||||
client.patch(
|
||||
'/api/activities/2',
|
||||
f'/api/activities/{activity_2_uuid}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=1)),
|
||||
headers=dict(
|
||||
@ -870,8 +898,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][0]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert 1 == data['data']['records'][0]['sport_id']
|
||||
assert 2 == data['data']['records'][0]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 20.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -880,8 +908,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][1]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert 1 == data['data']['records'][1]['sport_id']
|
||||
assert 2 == data['data']['records'][1]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 20.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -890,8 +918,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][2]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert 1 == data['data']['records'][2]['sport_id']
|
||||
assert 1 == data['data']['records'][2]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -900,8 +928,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][3]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert 1 == data['data']['records'][3]['sport_id']
|
||||
assert 2 == data['data']['records'][3]['activity_id']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 20.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -910,8 +938,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][4]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][4]['user']
|
||||
assert 2 == data['data']['records'][4]['sport_id']
|
||||
assert 4 == data['data']['records'][4]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][4]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][4]['activity_id']
|
||||
assert 'AS' == data['data']['records'][4]['record_type']
|
||||
assert 12.0 == data['data']['records'][4]['value']
|
||||
|
||||
@ -920,8 +948,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][5]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][5]['user']
|
||||
assert 2 == data['data']['records'][5]['sport_id']
|
||||
assert 4 == data['data']['records'][5]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][5]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][5]['activity_id']
|
||||
assert 'FD' == data['data']['records'][5]['record_type']
|
||||
assert 10.0 == data['data']['records'][5]['value']
|
||||
|
||||
@ -930,8 +958,8 @@ class TestGetRecords:
|
||||
== data['data']['records'][6]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][6]['user']
|
||||
assert 2 == data['data']['records'][6]['sport_id']
|
||||
assert 4 == data['data']['records'][6]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][6]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][6]['activity_id']
|
||||
assert 'LD' == data['data']['records'][6]['record_type']
|
||||
assert '0:50:00' == data['data']['records'][6]['value']
|
||||
|
||||
@ -940,7 +968,7 @@ class TestGetRecords:
|
||||
== data['data']['records'][7]['activity_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][7]['user']
|
||||
assert 2 == data['data']['records'][7]['sport_id']
|
||||
assert 4 == data['data']['records'][7]['activity_id']
|
||||
assert sport_2_running.id == data['data']['records'][7]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][7]['activity_id']
|
||||
assert 'MS' == data['data']['records'][7]['record_type']
|
||||
assert 12.0 == data['data']['records'][7]['value']
|
||||
|
33
fittrackee/tests/activities/utils.py
Normal file
33
fittrackee/tests/activities/utils.py
Normal file
@ -0,0 +1,33 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
def is_valid_uuid(string):
|
||||
try:
|
||||
UUID(string, version=4)
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def post_an_activity(app, gpx_file):
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||||
content_type='application/json',
|
||||
)
|
||||
token = json.loads(resp_login.data.decode())['auth_token']
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data', Authorization=f'Bearer {token}'
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
return token, data['data']['activities'][0]['id']
|
@ -196,8 +196,12 @@ def activity_cycling_user_1():
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def activity_cycling_user_1_segment():
|
||||
activity_segment = ActivitySegment(activity_id=1, segment_id=0)
|
||||
def activity_cycling_user_1_segment(activity_cycling_user_1):
|
||||
activity_segment = ActivitySegment(
|
||||
activity_id=activity_cycling_user_1.id,
|
||||
activity_uuid=activity_cycling_user_1.uuid,
|
||||
segment_id=0,
|
||||
)
|
||||
activity_segment.duration = datetime.timedelta(seconds=6000)
|
||||
activity_segment.moving = activity_segment.duration
|
||||
activity_segment.distance = 5
|
||||
|
Reference in New Issue
Block a user