API - return activity shorter id - #57
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import json
|
||||
from uuid import uuid4
|
||||
|
||||
from .utils import get_random_short_id
|
||||
|
||||
|
||||
class TestGetActivities:
|
||||
def test_it_gets_all_activities_for_authenticated_user(
|
||||
@ -695,7 +697,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid.hex}',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -727,7 +729,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_cycling_user_2.uuid.hex}',
|
||||
f'/api/activities/{activity_cycling_user_2.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -748,7 +750,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{uuid4().hex}',
|
||||
f'/api/activities/{get_random_short_id()}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -763,7 +765,7 @@ class TestGetActivity:
|
||||
def test_it_returns_404_on_getting_gpx_if_activity_does_not_exist(
|
||||
self, app, user_1
|
||||
):
|
||||
random_uuid = uuid4().hex
|
||||
random_short_id = get_random_short_id()
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -772,7 +774,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{random_uuid}/gpx',
|
||||
f'/api/activities/{random_short_id}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -782,13 +784,13 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
assert f'Activity not found (id: {random_uuid})' in data['message']
|
||||
assert f'Activity not found (id: {random_short_id})' 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
|
||||
random_short_id = get_random_short_id()
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -797,7 +799,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{random_uuid}/chart_data',
|
||||
f'/api/activities/{random_short_id}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -807,13 +809,13 @@ class TestGetActivity:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
assert f'Activity not found (id: {random_uuid})' in data['message']
|
||||
assert f'Activity not found (id: {random_short_id})' 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
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -822,7 +824,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/gpx',
|
||||
f'/api/activities/{activity_short_id}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -833,14 +835,14 @@ class TestGetActivity:
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert (
|
||||
f'No gpx file for this activity (id: {activity_uuid})'
|
||||
f'No gpx file for this activity (id: {activity_short_id})'
|
||||
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
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -849,7 +851,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/chart_data',
|
||||
f'/api/activities/{activity_short_id}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -860,7 +862,7 @@ class TestGetActivity:
|
||||
assert response.status_code == 404
|
||||
assert 'error' in data['status']
|
||||
assert (
|
||||
f'No gpx file for this activity (id: {activity_uuid})'
|
||||
f'No gpx file for this activity (id: {activity_short_id})'
|
||||
in data['message']
|
||||
)
|
||||
|
||||
@ -876,7 +878,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid.hex}/gpx',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -901,7 +903,7 @@ class TestGetActivity:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid.hex}/chart_data',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
|
@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from io import BytesIO
|
||||
|
||||
from fittrackee.activities.models import Activity
|
||||
from fittrackee.activities.utils_id import decode_short_id
|
||||
|
||||
|
||||
def assert_activity_data_with_gpx(data):
|
||||
@ -782,10 +783,10 @@ class TestPostAndGetActivityWithGpx:
|
||||
else:
|
||||
assert_activity_data_with_gpx(data)
|
||||
map_id = data['data']['activities'][0]['map']
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/gpx',
|
||||
f'/api/activities/{activity_short_id}/gpx',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -799,7 +800,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
assert len(data['data']['gpx']) != ''
|
||||
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/gpx/segment/1',
|
||||
f'/api/activities/{activity_short_id}/gpx/segment/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -822,6 +823,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
assert response.status_code == 200
|
||||
|
||||
# error case in the same test to avoid generate a new map file
|
||||
activity_uuid = decode_short_id(activity_short_id)
|
||||
activity = Activity.query.filter_by(uuid=activity_uuid).first()
|
||||
activity.map = 'incorrect path'
|
||||
|
||||
@ -876,9 +878,9 @@ class TestPostAndGetActivityWithGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/chart_data',
|
||||
f'/api/activities/{activity_short_id}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -914,9 +916,9 @@ class TestPostAndGetActivityWithGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/chart_data/segment/1',
|
||||
f'/api/activities/{activity_short_id}/chart_data/segment/1',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -951,7 +953,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -959,7 +961,7 @@ class TestPostAndGetActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/chart_data',
|
||||
f'/api/activities/{activity_short_id}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -994,9 +996,9 @@ class TestPostAndGetActivityWithGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/chart_data/segment/0',
|
||||
f'/api/activities/{activity_short_id}/chart_data/segment/0',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1032,9 +1034,9 @@ class TestPostAndGetActivityWithGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}/chart_data/segment/999999',
|
||||
f'/api/activities/{activity_short_id}/chart_data/segment/999999',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1076,9 +1078,9 @@ class TestPostAndGetActivityWithoutGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1119,9 +1121,9 @@ class TestPostAndGetActivityWithoutGpx:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -1164,9 +1166,9 @@ class TestPostAndGetActivityUsingTimezones:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_uuid = data['data']['activities'][0]['id']
|
||||
activity_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
|
@ -1,9 +1,9 @@
|
||||
import json
|
||||
from uuid import uuid4
|
||||
|
||||
from fittrackee.activities.models import Activity
|
||||
from fittrackee.activities.utils_id import decode_short_id
|
||||
|
||||
from .utils import post_an_activity
|
||||
from .utils import get_random_short_id, post_an_activity
|
||||
|
||||
|
||||
def assert_activity_data_with_gpx(data, sport_id):
|
||||
@ -53,11 +53,11 @@ 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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Activity test")),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -74,11 +74,11 @@ class TestEditActivityWithGpx:
|
||||
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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(notes="test notes")),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -94,7 +94,7 @@ 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)
|
||||
_, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -103,7 +103,7 @@ class TestEditActivityWithGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Activity test")),
|
||||
headers=dict(
|
||||
@ -120,11 +120,11 @@ 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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -141,11 +141,11 @@ class TestEditActivityWithGpx:
|
||||
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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict()),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -159,11 +159,11 @@ 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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -187,7 +187,7 @@ class TestEditActivityWithoutGpx:
|
||||
sport_2_running,
|
||||
activity_cycling_user_1,
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -196,7 +196,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -245,22 +245,22 @@ class TestEditActivityWithoutGpx:
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
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
|
||||
@ -268,7 +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
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -277,7 +277,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(notes='test notes')),
|
||||
headers=dict(
|
||||
@ -317,22 +317,22 @@ class TestEditActivityWithoutGpx:
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_1_cycling.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
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'] == sport_1_cycling.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
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'] == sport_1_cycling.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
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'] == sport_1_cycling.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
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
|
||||
@ -348,7 +348,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_cycling_user_2.uuid}',
|
||||
f'/api/activities/{activity_cycling_user_2.short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -378,7 +378,7 @@ class TestEditActivityWithoutGpx:
|
||||
sport_2_running,
|
||||
activity_cycling_user_1,
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -387,7 +387,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -431,22 +431,22 @@ class TestEditActivityWithoutGpx:
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
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
|
||||
@ -459,7 +459,7 @@ class TestEditActivityWithoutGpx:
|
||||
sport_2_running,
|
||||
activity_cycling_user_1,
|
||||
):
|
||||
activity_uuid = activity_cycling_user_1.uuid.hex
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -468,7 +468,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, distance=20)),
|
||||
headers=dict(
|
||||
@ -504,22 +504,22 @@ class TestEditActivityWithoutGpx:
|
||||
records = data['data']['activities'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_uuid
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_uuid
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_uuid
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
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'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_uuid
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
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
|
||||
@ -535,7 +535,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict()),
|
||||
headers=dict(
|
||||
@ -559,7 +559,7 @@ class TestEditActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -594,7 +594,7 @@ class TestEditActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.patch(
|
||||
f'/api/activities/{uuid4().hex}',
|
||||
f'/api/activities/{get_random_short_id()}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
@ -620,7 +620,8 @@ 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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
activity_uuid = decode_short_id(activity_short_id)
|
||||
client = app.test_client()
|
||||
|
||||
# Edit some activity data
|
||||
@ -629,7 +630,7 @@ class TestRefreshActivityWithGpx:
|
||||
activity.min_alt = -100
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(refresh=True)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
|
@ -1,11 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
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
|
||||
from .utils import get_random_short_id, post_an_activity
|
||||
|
||||
|
||||
def get_gpx_filepath(activity_id):
|
||||
@ -17,11 +16,11 @@ 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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
@ -30,7 +29,7 @@ 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)
|
||||
_, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -39,7 +38,7 @@ class TestDeleteActivityWithGpx:
|
||||
)
|
||||
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -60,7 +59,7 @@ class TestDeleteActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
f'/api/activities/{uuid4().hex}',
|
||||
f'/api/activities/{get_random_short_id()}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -73,14 +72,14 @@ 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)
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
client = app.test_client()
|
||||
gpx_filepath = get_gpx_filepath(1)
|
||||
gpx_filepath = get_absolute_file_path(gpx_filepath)
|
||||
os.remove(gpx_filepath)
|
||||
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_uuid}',
|
||||
f'/api/activities/{activity_short_id}',
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
@ -105,7 +104,7 @@ class TestDeleteActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -123,7 +122,7 @@ class TestDeleteActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_cycling_user_1.uuid}',
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
|
@ -1,4 +1,6 @@
|
||||
from .utils import is_valid_uuid
|
||||
from uuid import UUID
|
||||
|
||||
from fittrackee.activities.utils_id import decode_short_id
|
||||
|
||||
|
||||
class TestActivityModel:
|
||||
@ -22,7 +24,7 @@ class TestActivityModel:
|
||||
)
|
||||
|
||||
serialized_activity = activity_cycling_user_1.serialize()
|
||||
assert is_valid_uuid(serialized_activity['id'])
|
||||
assert isinstance(decode_short_id(serialized_activity['id']), UUID)
|
||||
assert 'test' == serialized_activity['user']
|
||||
assert 1 == serialized_activity['sport_id']
|
||||
assert serialized_activity['title'] == 'Test'
|
||||
@ -61,6 +63,6 @@ class TestActivityModel:
|
||||
):
|
||||
assert (
|
||||
f'<Segment \'{activity_cycling_user_1_segment.segment_id}\' '
|
||||
f'for activity \'{activity_cycling_user_1.uuid.hex}\'>'
|
||||
f'for activity \'{activity_cycling_user_1.short_id}\'>'
|
||||
== str(activity_cycling_user_1_segment)
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ class TestGetRecords:
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][0]['activity_id']
|
||||
)
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
@ -51,7 +51,7 @@ class TestGetRecords:
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][1]['activity_id']
|
||||
)
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
@ -64,7 +64,7 @@ class TestGetRecords:
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][2]['activity_id']
|
||||
)
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
@ -77,7 +77,7 @@ class TestGetRecords:
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.uuid.hex
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][3]['activity_id']
|
||||
)
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
@ -177,7 +177,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_1_uuid = data['data']['activities'][0]['id']
|
||||
activity_1_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -197,7 +197,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -207,7 +207,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -217,7 +217,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -227,7 +227,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -251,7 +251,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_2_uuid = data['data']['activities'][0]['id']
|
||||
activity_2_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -271,7 +271,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
@ -281,7 +281,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -291,7 +291,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -301,7 +301,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
@ -324,7 +324,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_3_uuid = data['data']['activities'][0]['id']
|
||||
activity_3_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -344,7 +344,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
@ -354,7 +354,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -364,7 +364,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -374,14 +374,14 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == 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(
|
||||
f'/api/activities/{activity_3_uuid}',
|
||||
f'/api/activities/{activity_3_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(duration=4000)),
|
||||
headers=dict(
|
||||
@ -408,7 +408,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
@ -418,7 +418,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -428,7 +428,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -438,13 +438,13 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == 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(
|
||||
f'/api/activities/{activity_2_uuid}',
|
||||
f'/api/activities/{activity_2_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -469,7 +469,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -479,7 +479,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -489,7 +489,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -499,7 +499,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -523,7 +523,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_4_uuid = data['data']['activities'][0]['id']
|
||||
activity_4_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -543,7 +543,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -553,7 +553,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -563,7 +563,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -573,7 +573,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -599,7 +599,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_5_uuid = data['data']['activities'][0]['id']
|
||||
activity_5_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -619,7 +619,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_5_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_5_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -629,7 +629,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_5_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_5_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -639,7 +639,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
@ -649,34 +649,34 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_5_uuid == data['data']['records'][3]['activity_id']
|
||||
assert activity_5_short_id == 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(
|
||||
f'/api/activities/{activity_1_uuid}',
|
||||
f'/api/activities/{activity_1_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
f'/api/activities/{activity_3_uuid}',
|
||||
f'/api/activities/{activity_3_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
f'/api/activities/{activity_4_uuid}',
|
||||
f'/api/activities/{activity_4_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
f'/api/activities/{activity_5_uuid}',
|
||||
f'/api/activities/{activity_5_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -722,7 +722,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_1_uuid = data['data']['activities'][0]['id']
|
||||
activity_1_short_id = data['data']['activities'][0]['id']
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
@ -741,7 +741,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_2_uuid = data['data']['activities'][0]['id']
|
||||
activity_2_short_id = data['data']['activities'][0]['id']
|
||||
client.post(
|
||||
'/api/activities/no_gpx',
|
||||
content_type='application/json',
|
||||
@ -777,7 +777,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_4_uuid = data['data']['activities'][0]['id']
|
||||
activity_4_short_id = data['data']['activities'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -797,7 +797,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -807,7 +807,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -817,7 +817,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -827,7 +827,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][3]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -837,7 +837,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][4]['user']
|
||||
assert sport_2_running.id == data['data']['records'][4]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][4]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][4]['activity_id']
|
||||
assert 'AS' == data['data']['records'][4]['record_type']
|
||||
assert 20.0 == data['data']['records'][4]['value']
|
||||
|
||||
@ -847,7 +847,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][5]['user']
|
||||
assert sport_2_running.id == data['data']['records'][5]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][5]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][5]['activity_id']
|
||||
assert 'FD' == data['data']['records'][5]['record_type']
|
||||
assert 20.0 == data['data']['records'][5]['value']
|
||||
|
||||
@ -857,7 +857,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][6]['user']
|
||||
assert sport_2_running.id == data['data']['records'][6]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][6]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][6]['activity_id']
|
||||
assert 'LD' == data['data']['records'][6]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][6]['value']
|
||||
|
||||
@ -867,12 +867,12 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][7]['user']
|
||||
assert sport_2_running.id == data['data']['records'][7]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][7]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][7]['activity_id']
|
||||
assert 'MS' == data['data']['records'][7]['record_type']
|
||||
assert 20.0 == data['data']['records'][7]['value']
|
||||
|
||||
client.patch(
|
||||
f'/api/activities/{activity_2_uuid}',
|
||||
f'/api/activities/{activity_2_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=1)),
|
||||
headers=dict(
|
||||
@ -899,7 +899,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][0]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 20.0 == data['data']['records'][0]['value']
|
||||
|
||||
@ -909,7 +909,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][1]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][1]['activity_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 20.0 == data['data']['records'][1]['value']
|
||||
|
||||
@ -919,7 +919,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_uuid == data['data']['records'][2]['activity_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
@ -929,7 +929,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_2_uuid == data['data']['records'][3]['activity_id']
|
||||
assert activity_2_short_id == data['data']['records'][3]['activity_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 20.0 == data['data']['records'][3]['value']
|
||||
|
||||
@ -939,7 +939,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][4]['user']
|
||||
assert sport_2_running.id == data['data']['records'][4]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][4]['activity_id']
|
||||
assert activity_4_short_id == data['data']['records'][4]['activity_id']
|
||||
assert 'AS' == data['data']['records'][4]['record_type']
|
||||
assert 12.0 == data['data']['records'][4]['value']
|
||||
|
||||
@ -949,7 +949,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][5]['user']
|
||||
assert sport_2_running.id == data['data']['records'][5]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][5]['activity_id']
|
||||
assert activity_4_short_id == data['data']['records'][5]['activity_id']
|
||||
assert 'FD' == data['data']['records'][5]['record_type']
|
||||
assert 10.0 == data['data']['records'][5]['value']
|
||||
|
||||
@ -959,7 +959,7 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][6]['user']
|
||||
assert sport_2_running.id == data['data']['records'][6]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][6]['activity_id']
|
||||
assert activity_4_short_id == data['data']['records'][6]['activity_id']
|
||||
assert 'LD' == data['data']['records'][6]['record_type']
|
||||
assert '0:50:00' == data['data']['records'][6]['value']
|
||||
|
||||
@ -969,6 +969,6 @@ class TestGetRecords:
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][7]['user']
|
||||
assert sport_2_running.id == data['data']['records'][7]['sport_id']
|
||||
assert activity_4_uuid == data['data']['records'][7]['activity_id']
|
||||
assert activity_4_short_id == data['data']['records'][7]['activity_id']
|
||||
assert 'MS' == data['data']['records'][7]['record_type']
|
||||
assert 12.0 == data['data']['records'][7]['value']
|
||||
|
@ -1,14 +1,12 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
from uuid import UUID
|
||||
from uuid import uuid4
|
||||
|
||||
from fittrackee.activities.utils_id import encode_uuid
|
||||
|
||||
|
||||
def is_valid_uuid(string):
|
||||
try:
|
||||
UUID(string, version=4)
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
def get_random_short_id():
|
||||
return encode_uuid(uuid4())
|
||||
|
||||
|
||||
def post_an_activity(app, gpx_file):
|
||||
|
Reference in New Issue
Block a user