API - fix new sports addition

- add data migration and fix data init for new instances
- update and fix tests
This commit is contained in:
Sam
2021-09-01 14:05:45 +02:00
parent 69467d8a6b
commit 1881165b57
7 changed files with 197 additions and 53 deletions

View File

@ -108,8 +108,11 @@ def seven_workouts_user_1() -> Workout:
)
workout.ave_speed = float(workout.distance) / (1024 / 3600)
workout.moving = workout.duration
workout.ascent = 120
workout.descent = 200
db.session.add(workout)
db.session.flush()
workout = Workout(
user_id=1,
sport_id=1,
@ -119,8 +122,11 @@ def seven_workouts_user_1() -> Workout:
)
workout.ave_speed = float(workout.distance) / (3456 / 3600)
workout.moving = workout.duration
workout.ascent = 100
workout.descent = 80
db.session.add(workout)
db.session.flush()
workout = Workout(
user_id=1,
sport_id=1,
@ -130,8 +136,11 @@ def seven_workouts_user_1() -> Workout:
)
workout.ave_speed = float(workout.distance) / (1024 / 3600)
workout.moving = workout.duration
workout.ascent = 80
workout.descent = 100
db.session.add(workout)
db.session.flush()
workout = Workout(
user_id=1,
sport_id=1,
@ -141,8 +150,11 @@ def seven_workouts_user_1() -> Workout:
)
workout.ave_speed = float(workout.distance) / (600 / 3600)
workout.moving = workout.duration
workout.ascent = 120
workout.descent = 180
db.session.add(workout)
db.session.flush()
workout = Workout(
user_id=1,
sport_id=1,
@ -152,8 +164,11 @@ def seven_workouts_user_1() -> Workout:
)
workout.ave_speed = float(workout.distance) / (1000 / 3600)
workout.moving = workout.duration
workout.ascent = 100
workout.descent = 200
db.session.add(workout)
db.session.flush()
workout = Workout(
user_id=1,
sport_id=1,
@ -163,8 +178,11 @@ def seven_workouts_user_1() -> Workout:
)
workout.ave_speed = float(workout.distance) / (6000 / 3600)
workout.moving = workout.duration
workout.ascent = 40
workout.descent = 20
db.session.add(workout)
db.session.flush()
workout = Workout(
user_id=1,
sport_id=1,

View File

@ -110,6 +110,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017': {
'1': {
'nb_workouts': 2,
'total_ascent': 220.0,
'total_descent': 280.0,
'total_distance': 15.0,
'total_duration': 4480,
}
@ -117,11 +119,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018': {
'1': {
'nb_workouts': 5,
'total_ascent': 340.0,
'total_descent': 500.0,
'total_distance': 39.0,
'total_duration': 11624,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -151,11 +157,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -186,11 +196,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -220,6 +234,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017': {
'1': {
'nb_workouts': 2,
'total_ascent': 220.0,
'total_descent': 280.0,
'total_distance': 15.0,
'total_duration': 4480,
}
@ -227,11 +243,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018': {
'1': {
'nb_workouts': 5,
'total_ascent': 340.0,
'total_descent': 500.0,
'total_distance': 39.0,
'total_duration': 11624,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -261,11 +281,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -296,11 +320,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -330,6 +358,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-03': {
'1': {
'nb_workouts': 1,
'total_ascent': 120.0,
'total_descent': 200.0,
'total_distance': 5.0,
'total_duration': 1024,
}
@ -337,6 +367,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-06': {
'1': {
'nb_workouts': 1,
'total_ascent': 100.0,
'total_descent': 80.0,
'total_distance': 10.0,
'total_duration': 3456,
}
@ -344,6 +376,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-01': {
'1': {
'nb_workouts': 1,
'total_ascent': 80.0,
'total_descent': 100.0,
'total_distance': 10.0,
'total_duration': 1024,
}
@ -351,6 +385,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-02': {
'1': {
'nb_workouts': 2,
'total_ascent': 220.0,
'total_descent': 380.0,
'total_distance': 11.0,
'total_duration': 1600,
}
@ -358,11 +394,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-04': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -370,6 +410,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-05': {
'1': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 10.0,
'total_duration': 3000,
}
@ -399,6 +441,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-03': {
'1': {
'nb_workouts': 1,
'total_ascent': 120.0,
'total_descent': 200.0,
'total_distance': 5.0,
'total_duration': 1024,
}
@ -406,6 +450,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-06': {
'1': {
'nb_workouts': 1,
'total_ascent': 100.0,
'total_descent': 80.0,
'total_distance': 10.0,
'total_duration': 3456,
}
@ -413,6 +459,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-01': {
'1': {
'nb_workouts': 1,
'total_ascent': 80.0,
'total_descent': 100.0,
'total_distance': 10.0,
'total_duration': 1024,
}
@ -420,6 +468,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-02': {
'1': {
'nb_workouts': 2,
'total_ascent': 220.0,
'total_descent': 380.0,
'total_distance': 11.0,
'total_duration': 1600,
}
@ -427,11 +477,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-04': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -439,6 +493,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-05': {
'1': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 10.0,
'total_duration': 3000,
}
@ -468,11 +524,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-04': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -502,6 +562,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-03-19': {
'1': {
'nb_workouts': 1,
'total_ascent': 120.0,
'total_descent': 200.0,
'total_distance': 5.0,
'total_duration': 1024,
}
@ -509,6 +571,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-05-28': {
'1': {
'nb_workouts': 1,
'total_ascent': 100.0,
'total_descent': 80.0,
'total_distance': 10.0,
'total_duration': 3456,
}
@ -516,6 +580,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-12-31': {
'1': {
'nb_workouts': 1,
'total_ascent': 80.0,
'total_descent': 100.0,
'total_distance': 10.0,
'total_duration': 1024,
}
@ -523,6 +589,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-02-18': {
'1': {
'nb_workouts': 2,
'total_ascent': 220.0,
'total_descent': 380.0,
'total_distance': 11.0,
'total_duration': 1600,
}
@ -530,11 +598,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-04-01': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -542,6 +614,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-05-06': {
'1': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 10.0,
'total_duration': 3000,
}
@ -571,11 +645,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-04-01': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -605,6 +683,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-03-20': {
'1': {
'nb_workouts': 1,
'total_ascent': 120.0,
'total_descent': 200.0,
'total_distance': 5.0,
'total_duration': 1024,
}
@ -612,6 +692,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2017-05-29': {
'1': {
'nb_workouts': 1,
'total_ascent': 100.0,
'total_descent': 80.0,
'total_distance': 10.0,
'total_duration': 3456,
}
@ -619,6 +701,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-01-01': {
'1': {
'nb_workouts': 1,
'total_ascent': 80.0,
'total_descent': 100.0,
'total_distance': 10.0,
'total_duration': 1024,
}
@ -626,6 +710,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-02-19': {
'1': {
'nb_workouts': 2,
'total_ascent': 220.0,
'total_descent': 380.0,
'total_distance': 11.0,
'total_duration': 1600,
}
@ -633,11 +719,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-03-26': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -645,6 +735,8 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-05-07': {
'1': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 10.0,
'total_duration': 3000,
}
@ -674,11 +766,15 @@ class TestGetStatsByTime(ApiTestCaseMixin):
'2018-03-26': {
'1': {
'nb_workouts': 1,
'total_ascent': 40.0,
'total_descent': 20.0,
'total_distance': 8.0,
'total_duration': 6000,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -709,11 +805,15 @@ class TestGetStatsBySport(ApiTestCaseMixin):
assert data['data']['statistics'] == {
'1': {
'nb_workouts': 7,
'total_ascent': 560.0,
'total_descent': 780.0,
'total_distance': 54.0,
'total_duration': 16104,
},
'2': {
'nb_workouts': 1,
'total_ascent': 0.0,
'total_descent': 0.0,
'total_distance': 12.0,
'total_duration': 6000,
},
@ -741,6 +841,8 @@ class TestGetStatsBySport(ApiTestCaseMixin):
assert data['data']['statistics'] == {
'1': {
'nb_workouts': 7,
'total_ascent': 560.0,
'total_descent': 780.0,
'total_distance': 54.0,
'total_duration': 16104,
}