FitTrackee/fittrackee/tests/activities/test_activities_model.py

76 lines
3.0 KiB
Python
Raw Normal View History

2020-12-30 22:07:43 +01:00
from uuid import UUID
2021-01-02 19:28:03 +01:00
from fittrackee.activities.models import Activity, Sport
2020-12-30 22:07:43 +01:00
from fittrackee.activities.utils_id import decode_short_id
2021-01-02 19:28:03 +01:00
from fittrackee.users.models import User
from flask import Flask
2020-05-10 15:55:56 +02:00
class TestActivityModel:
def test_activity_model(
2021-01-02 19:28:03 +01:00
self,
app: Flask,
sport_1_cycling: Sport,
user_1: User,
activity_cycling_user_1: Activity,
) -> None:
2020-05-10 15:55:56 +02:00
activity_cycling_user_1.title = 'Test'
2018-05-12 19:13:59 +02:00
2020-05-10 15:55:56 +02:00
assert 1 == activity_cycling_user_1.id
assert activity_cycling_user_1.uuid is not None
2020-05-10 15:55:56 +02:00
assert 1 == activity_cycling_user_1.user_id
assert 1 == activity_cycling_user_1.sport_id
assert '2018-01-01 00:00:00' == str(
activity_cycling_user_1.activity_date
)
assert 10.0 == float(activity_cycling_user_1.distance)
assert '1:00:00' == str(activity_cycling_user_1.duration)
assert 'Test' == activity_cycling_user_1.title
assert '<Activity \'Cycling\' - 2018-01-01 00:00:00>' == str(
activity_cycling_user_1
)
2018-05-14 13:25:00 +02:00
2020-05-10 15:55:56 +02:00
serialized_activity = activity_cycling_user_1.serialize()
2020-12-30 22:07:43 +01:00
assert isinstance(decode_short_id(serialized_activity['id']), UUID)
2020-05-10 15:55:56 +02:00
assert 'test' == serialized_activity['user']
assert 1 == serialized_activity['sport_id']
assert serialized_activity['title'] == 'Test'
assert 'creation_date' in serialized_activity
assert serialized_activity['modification_date'] is not None
assert (
str(serialized_activity['activity_date']) == '2018-01-01 00:00:00'
)
assert serialized_activity['duration'] == '1:00:00'
assert serialized_activity['pauses'] is None
assert serialized_activity['moving'] == '1:00:00'
assert serialized_activity['distance'] == 10.0
assert serialized_activity['max_alt'] is None
assert serialized_activity['descent'] is None
assert serialized_activity['ascent'] is None
assert serialized_activity['max_speed'] == 10.0
assert serialized_activity['ave_speed'] == 10.0
assert serialized_activity['with_gpx'] is False
assert serialized_activity['bounds'] == []
assert serialized_activity['previous_activity'] is None
assert serialized_activity['next_activity'] is None
assert serialized_activity['segments'] == []
assert serialized_activity['records'] != []
assert serialized_activity['map'] is None
assert serialized_activity['weather_start'] is None
assert serialized_activity['weather_end'] is None
assert serialized_activity['notes'] is None
2020-05-10 15:55:56 +02:00
def test_activity_segment_model(
self,
2021-01-02 19:28:03 +01:00
app: Flask,
sport_1_cycling: Sport,
user_1: User,
activity_cycling_user_1: Activity,
activity_cycling_user_1_segment: Activity,
) -> None:
assert (
f'<Segment \'{activity_cycling_user_1_segment.segment_id}\' '
2020-12-30 22:07:43 +01:00
f'for activity \'{activity_cycling_user_1.short_id}\'>'
== str(activity_cycling_user_1_segment)
2020-05-10 15:55:56 +02:00
)