def setup(self): WorkoutCategoryModel("Running", True).save(commit=False) WorkoutCategoryModel("Fitness", False).save() self.running_workout_category = WorkoutCategoryModel.get_by_id(1) self.fitness_workout_category = WorkoutCategoryModel.get_by_id(2) GoalCategoryModel("Cumulative distance", "km", 1).save(commit=False) GoalCategoryModel("Number of workouts", "#", 1).save(commit=False) GoalCategoryModel("Number of workouts", "#", 2).save(commit=False) GoalCategoryModel("Cumulative climb", "m", 1).save(commit=False) GoalCategoryModel("Weight loss", "kg", None).save() self.cumulative_distance_goal_category = GoalCategoryModel.get_by_id(1) self.num_of_running_workouts_goal_category = GoalCategoryModel.get_by_id(2) self.num_of_fitness_workouts_goal_category = GoalCategoryModel.get_by_id(3) self.cumulative_climb_goal_category = GoalCategoryModel.get_by_id(4) self.weight_loss_goal_category = GoalCategoryModel.get_by_id(5) two_days_ago = dt.datetime.utcnow() - dt.timedelta(days=2) two_days_from_now = dt.datetime.utcnow() + dt.timedelta(days=2) GoalModel(self.profile_id, self.cumulative_distance_goal_category, two_days_ago, two_days_from_now, 0, 100, 0).save(commit=False) GoalModel(self.profile_id, self.num_of_running_workouts_goal_category, two_days_ago, two_days_from_now, 0, 10, 0).save(commit=False) GoalModel(self.profile_id, self.num_of_fitness_workouts_goal_category, two_days_ago, two_days_from_now, 0, 10, 0).save(commit=False) GoalModel(self.profile_id, self.cumulative_climb_goal_category, two_days_ago, two_days_from_now, 0, 500, 0).save(commit=False) GoalModel(self.profile_id, self.weight_loss_goal_category, two_days_ago, two_days_from_now, 80, 70, 78).save() self.cumulative_distance_goal = GoalModel.get_by_id(1) self.running_workouts_goal = GoalModel.get_by_id(2) self.fitness_workouts_goal = GoalModel.get_by_id(3) self.cumulative_climb_goal = GoalModel.get_by_id(4) self.weight_loss_goal = GoalModel.get_by_id(5)
def test_get_workouts_for_goal_excludes_other_users_workouts(self): # register category for goal, connected to "running" goal_category = GoalCategoryModel("Distance", "km", 1) goal_category.save() #register goal goal = GoalModel(1, goal_category, dt.datetime.utcnow() - dt.timedelta(days=4), dt.datetime.utcnow() + dt.timedelta(days=4)) goal.save() # register workout for workout category "Running", within goal limits running_category = WorkoutCategoryModel.get_by_id(1) run_workout_1 = WorkoutModel(1, running_category, "Run 1", dt.datetime.utcnow(), 1000, 200, 0, None, False) run_workout_1.save(commit=False) # register workout for workout category "Running", within goal limits, but other user run_workout_2 = WorkoutModel( 2, running_category, "Run 2", dt.datetime.utcnow() + dt.timedelta(days=1), 1000, 200, 0, None, False) run_workout_2.save(commit=True) goal_workouts = WorkoutModel.get_workouts_for_goal(goal) assert (len(goal_workouts) == 1) assert (goal_workouts[0] == run_workout_1)
def test_get_workouts_for_goal_excludes_too_old_and_too_new_workouts(self): # register category for goal, connected to "running" goal_category = GoalCategoryModel("Distance", "km", 1) goal_category.save() #register goal goal = GoalModel(1, goal_category, dt.datetime.utcnow() - dt.timedelta(days=4), dt.datetime.utcnow() + dt.timedelta(days=4)) goal.save() # register workouts for workout category "Running", within goal limits running_category = WorkoutCategoryModel.get_by_id(1) run_workout_1 = WorkoutModel(1, running_category, "Run 1", dt.datetime.utcnow(), 1000, 200, 0, None, False) run_workout_1.save(commit=False) run_workout_2 = WorkoutModel( 1, running_category, "Run 2", dt.datetime.utcnow() + dt.timedelta(days=1), 1000, 200, 0, None, False) run_workout_2.save(commit=False) # register workout completed before goal started WorkoutModel(1, running_category, "Too early", dt.datetime.utcnow() - dt.timedelta(days=5), 1000, 200, 0, None, False).save(commit=False) # register workout completed after goal ended WorkoutModel(1, running_category, "Too late", dt.datetime.utcnow() + dt.timedelta(days=5), 1000, 200, 0, None, False).save(commit=True) goal_workouts = WorkoutModel.get_workouts_for_goal(goal) assert (len(goal_workouts) == 2) assert (goal_workouts[0] == run_workout_1) assert (goal_workouts[1] == run_workout_2)
def _init_profile_with_goals(self): user = User('user', '*****@*****.**') user.save() profile = Profile(user) profile.save() goal_cat = GoalCategoryModel('demo') goal_cat.save() previous_start_at = dt.datetime.utcnow() + dt.timedelta(days=-5) current_start_at = dt.datetime.utcnow() + dt.timedelta(days=-2) later_start_at = dt.datetime.utcnow() + dt.timedelta(days=1) GoalModel(profile.id, goal_cat, current_start_at, current_start_at + dt.timedelta(days=4), 0, 10, 11).save() # completed but still active positive-going GoalModel(profile.id, goal_cat, later_start_at, later_start_at + dt.timedelta(days=4), 0, 10, 0).save() # not completed, future GoalModel(profile.id, goal_cat, previous_start_at, previous_start_at + dt.timedelta(days=4), 0, 5, 4).save() # not completed, pos.going return profile
def test_get_workouts_for_goal_excludes_other_workout_categories(self): # register category for goal, connected to "running" goal_category = GoalCategoryModel("Distance", "km", 1) goal_category.save(commit=False) # register category for goal, not connected to "running goal_category_other = GoalCategoryModel("Distance", "km", 2) goal_category_other.save() #register goal goal = GoalModel(1, goal_category, dt.datetime.utcnow() - dt.timedelta(days=4), dt.datetime.utcnow() + dt.timedelta(days=4)) goal.save() # register workout for workout category "Running", within goal limits running_category = WorkoutCategoryModel.get_by_id(1) run_workout = WorkoutModel(1, running_category, "Run", dt.datetime.utcnow(), 1000, 200, 0, None, False) run_workout.save(commit=False) # register workout for workout category "Hiking" hiking_category = WorkoutCategoryModel.get_by_id(2) hiking_workout = WorkoutModel( 1, hiking_category, "Hike", dt.datetime.utcnow() + dt.timedelta(days=1), 1000, 200, 0, None, False) hiking_workout.save(commit=True) goal_workouts = WorkoutModel.get_workouts_for_goal(goal) assert (len(goal_workouts) == 1) assert (goal_workouts[0] == run_workout)
def test_category_name_not_unique(self, db): item = GoalCategoryModel("Distance", "km", 1) item.save() item_new = GoalCategoryModel("Distance", "km", 2) item_new.save() num_items = db.session.query(GoalCategoryModel).count() assert(num_items == 2)
def test_category_workout_category_link(self, db): WorkoutCategoryModel("Running", True).save() item1 = GoalCategoryModel("Run Kms", "km", None) item1.save() item2 = GoalCategoryModel("Run Kms", "km", 1) item2.save() assert(item1.workout_category is None) assert(item2.workout_category.id == 1)
def test_goal_category_link(self): category = GoalCategoryModel.get_by_id(1) new_goal = GoalModel(1, category) new_goal.save() assert(new_goal.category.id == 1) assert(new_goal.category.name == 'RunKms') assert(new_goal.category_unit == 'km')
def test_two_goals_with_same_category_and_profile(self): category = GoalCategoryModel.get_by_id(1) new_goal1 = GoalModel(1, category) new_goal1.save() new_goal2 = GoalModel(1, category) new_goal2.save() assert(GoalModel.query.count() == 2)
def test_profile_updates_weight_loss_goals_on_new_weight(self): user = User('user', '*****@*****.**') user.save() profile = Profile(user) profile.set_weight(80) profile.save() weight_cat = GoalCategoryModel('Weight loss', 'kg') weight_cat.save() weight_goal = GoalModel(profile.id, weight_cat, dt.datetime.utcnow() - dt.timedelta(days=1), dt.datetime.utcnow() + dt.timedelta(days=1), 80, 70, 79).save() weight_goal.save() initial_start_value = weight_goal.start_value initial_current_value = weight_goal.current_value assert(initial_start_value == 80) assert(initial_current_value == 79) profile.set_weight(78) profile.save() assert(weight_goal.start_value == 80) assert(weight_goal.current_value == 78)
def test_default_start_date_and_end_date(self): category = GoalCategoryModel.get_by_id(1) now = dt.datetime.utcnow() item = GoalModel(1, category) item.save() assert((now - dt.timedelta(minutes=1)) < item.start_at) assert((now + dt.timedelta(minutes=1)) > item.start_at) assert((item.end_at - item.start_at).seconds <= 1) assert(item.duration == 1)
def test_future_goals_sorting(self): # should be sorted with those which have start date in closest future first profile = self._init_profile_with_goals() adjusted_now = dt.datetime.utcnow() + dt.timedelta(days=-10) cat = GoalCategoryModel('new').save() GoalModel(profile.id, cat, adjusted_now + dt.timedelta(days=1), adjusted_now + dt.timedelta(days=20)).save() goals = profile.get_future_goals(adjusted_now) assert(len(goals) == 4) assert(goals[0].start_at < goals[1].start_at < goals[2].start_at < goals[3].start_at)
def test_start_date_duration(self): category = GoalCategoryModel.get_by_id(1) start_at = dt.datetime.utcnow() + dt.timedelta(days=3) end_at = start_at + dt.timedelta(days=7) item = GoalModel(1, category, start_at, end_at) item.save() assert(item.start_at == start_at) assert(item.end_at == end_at) assert(item.duration == 7.0000)
def test_previous_goals_sorting(self): # should be sorted with those which ended in closest past first profile = self._init_profile_with_goals() adjusted_now = dt.datetime.utcnow() + dt.timedelta(days=10) cat = GoalCategoryModel('new').save() GoalModel(profile.id, cat, adjusted_now + dt.timedelta(days=-20), adjusted_now + dt.timedelta(days=-1)).save() goals = profile.get_expired_goals(adjusted_now) assert(len(goals) == 4) assert(goals[0].end_at > goals[1].end_at > goals[2].end_at > goals[3].end_at)
def test_active_goals_sorting(self): # should be sorted with those which ends in closest future first profile = self._init_profile_with_goals() adjusted_now = dt.datetime.utcnow() + dt.timedelta(days=-2, minutes=1) cat = GoalCategoryModel('new').save() GoalModel(profile.id, cat, start_at=adjusted_now + dt.timedelta(days=-20), end_at=adjusted_now + dt.timedelta(days=20)).save() goals = profile.get_active_goals(adjusted_now) assert(len(goals) == 3) assert(goals[0].end_at < goals[1].end_at < goals[2].end_at)
def setup(self): # register some goals cat1 = GoalCategoryModel('RunDistance', 'km') cat1.save(commit=False) cat2 = GoalCategoryModel('CrawlDistance', 'm') cat2.save() now = dt.datetime.utcnow() future_goal = GoalModel(1, cat1, now + dt.timedelta(days=2), now + dt.timedelta(days=3), 0, 2, 0) future_goal.save(commit=False) active_goal = GoalModel(1, cat1, now + dt.timedelta(days=-2), now + dt.timedelta(days=1), 0, 2, 1) active_goal.save(commit=False) expired_goal = GoalModel(1, cat1, now + dt.timedelta(days=-10), now + dt.timedelta(days=-2), 0, 2, 0) expired_goal.save()
def test_category_name_and_workout_category_unique(self, db): item = GoalCategoryModel("Distance", "km", 1) item.save() try: item_new = GoalCategoryModel("Distance", "km", 1) item_new.save() except: db.session.rollback() num_items = db.session.query(GoalCategoryModel).count() assert(num_items == 1)
def test_get_incompleted_goals(self): # sorted with most recently ended first profile = self._init_profile_with_goals() cat = GoalCategoryModel('new').save() start_at = dt.datetime.utcnow() + dt.timedelta(days=-5) GoalModel(profile.id, cat, start_at, start_at + dt.timedelta(days=2), 10, 2, 3).save() # not completed, positive-going goals = profile.get_incompleted_goals() assert(len(goals) == 2) assert(goals[0].end_at > goals[1].end_at) assert(goals[0].id == 3) assert(goals[1].id == 4)
def test_misc_durations(self): category = GoalCategoryModel.get_by_id(1) start_at = dt.datetime(2020, 1, 1, 0, 0, 0) end_at = dt.datetime(2020, 1, 1, 13, 0, 0) item = GoalModel(1, category, start_at, end_at) expected_duration = round(13*60*60 / 86400, 4) assert(item.duration == expected_duration) end_at = dt.datetime(2021, 1, 1, 13, 0, 0) item = GoalModel(1, category, start_at, end_at) expected_duration = 366 + round(13*60*60 / 86400, 4) assert(item.duration == expected_duration)
def test_get_completed_goals(self): # sorted with most recently ended first profile = self._init_profile_with_goals() cat = GoalCategoryModel('new').save() start_at = dt.datetime.utcnow() + dt.timedelta(days=-5) GoalModel(profile.id, cat, start_at, start_at + dt.timedelta(days=2), 10, 2, 2).save() # completed, negative-going GoalModel(profile.id, cat, start_at, start_at + dt.timedelta(days=3), 2, 10, 11).save() # completed, positive-going GoalModel(profile.id, cat, start_at + dt.timedelta(days=6), start_at + dt.timedelta(days=8), 10, 2, 2).save() # completed per se, but in future goals = profile.get_completed_goals() assert(len(goals) == 2) assert(goals[0].end_at > goals[1].end_at) assert(goals[0].id == 5) assert(goals[1].id == 4)
def setup(self): # register some goals cat1 = GoalCategoryModel('RunDistance', 'km') cat1.save(commit=False) cat2 = GoalCategoryModel('Weight target', 'kg') cat2.save() now = dt.datetime.utcnow() future_goal = GoalModel(1, cat1, now + dt.timedelta(days=2), now + dt.timedelta(days=3), 0, 2, 0) future_goal.save(commit=False) active_goal1 = GoalModel(1, cat1, now + dt.timedelta(days=-2), now + dt.timedelta(days=1), 0, 2, 1) active_goal2 = GoalModel(1, cat2, now + dt.timedelta(days=-2), now + dt.timedelta(days=2), 70, 68, 68) active_goal1.save(commit=False) active_goal2.save(commit=False) expired_goal1 = GoalModel(1, cat1, now + dt.timedelta(days=-10), now + dt.timedelta(days=-2), 0, 2, 0) # incomplete expired_goal2 = GoalModel(1, cat1, now + dt.timedelta(days=-8), now + dt.timedelta(days=-3), 0, 2, 2) # complete expired_goal1.save(commit=False) expired_goal2.save()
def test_get_workouts_for_goal(self, api, client): run_cat = GoalCategoryModel("Cumulative distance", "km", 1) run_cat.save(commit=False) hike_cat = GoalCategoryModel("Cumulative distance", "km", 2) hike_cat.save() now = dt.datetime.utcnow() run_goal = GoalModel(1, run_cat, now - dt.timedelta(days=4), now - dt.timedelta(days=1)) run_goal.save(commit=False) hike_goal = GoalModel(1, hike_cat, now - dt.timedelta(days=3), now) hike_goal.save(commit=False) run_goal_no_workouts = GoalModel( 1, run_cat, now, now + dt.timedelta(days=1)) # no workouts in goal period run_goal_no_workouts.save() token, _ = register_and_login_confirmed_user(api, client, "jonny", "*****@*****.**", "jonny") url_goal_1 = api.url_for(ProfileWorkoutListResource, username="******", goalID=1) response_1 = client.get(url_goal_1, headers=get_authorization_header(token)) response_json_1 = get_response_json(response_1.data) assert (response_1.status_code == 200) assert (len(response_json_1) == 2) assert (response_json_1[0]['name'] == "Run 1") assert (response_json_1[1]['name'] == "Run 2") url_goal_2 = api.url_for(ProfileWorkoutListResource, username="******", goalID=2) response_2 = client.get(url_goal_2, headers=get_authorization_header(token)) response_json_2 = get_response_json(response_2.data) assert (response_2.status_code == 200) assert (len(response_json_2) == 1) assert (response_json_2[0]['name'] == "Hike 1") url_goal_3 = api.url_for(ProfileWorkoutListResource, username="******", goalID=3) response_3 = client.get(url_goal_3, headers=get_authorization_header(token)) response_json_3 = get_response_json(response_3.data) assert (response_3.status_code == 200) assert (len(response_json_3) == 0)
def test_get_by_id(self): category = GoalCategoryModel.get_by_id(1) new_goal = GoalModel(1, category) new_goal.save() retrieved_goal = GoalModel.get_by_id(new_goal.id) assert(retrieved_goal == new_goal)
def test_values(self): category = GoalCategoryModel.get_by_id(1) item = GoalModel(3, category, start_value=1, current_value=2, target_value=3) assert(item.start_value==1) assert(item.current_value==2) assert(item.target_value==3)
def test_category_unit(self, db): item = GoalCategoryModel("Run Kms", "km") item.save() assert(item.unit == 'km')
def setup(self): WorkoutCategoryModel("Running", True).save() GoalCategoryModel("RunKms", "km", 1).save(commit=False) GoalCategoryModel("WeightTarget").save()
def init_database_test_data(): print('Deleting database data ...') from run4it.app.database import db # noqa from run4it.api.user import User, UserConfirmation # noqa from run4it.api.profile import Profile, ProfileWeightHistory # noqa from run4it.api.token import TokenRegistry # noqa from run4it.api.discipline import DisciplineModel # noqa from run4it.api.goal import GoalModel, GoalCategoryModel # noqa from run4it.api.workout import WorkoutCategoryModel, WorkoutModel #noqa from run4it.api.polar import PolarUserModel, PolarWebhookExerciseModel # delete most stuff rows = User.query.delete(False) if rows > 0: print('Deleted {0} rows from User table'.format(rows)) rows = Profile.query.delete(False) if rows > 0: print('Deleted {0} rows from Profile table'.format(rows)) rows = UserConfirmation.query.delete(False) if rows > 0: print('Deleted {0} rows from UserConfirmation table'.format(rows)) rows = TokenRegistry.query.delete(False) if rows > 0: print('Deleted {0} rows from TokenRegistry table'.format(rows)) rows = ProfileWeightHistory.query.delete(False) if rows > 0: print('Deleted {0} rows from ProfileWeightHistory table'.format(rows)) rows = DisciplineModel.query.delete(False) if rows > 0: print('Deleted {0} rows from Discipline table'.format(rows)) rows = GoalModel.query.delete(False) if rows > 0: print('Deleted {0} rows from Goal table'.format(rows)) rows = GoalCategoryModel.query.delete(False) if rows > 0: print('Deleted {0} rows from GoalCategory table'.format(rows)) rows = WorkoutModel.query.delete(False) if rows > 0: print('Deleted {0} rows from Workout table'.format(rows)) rows = WorkoutCategoryModel.query.delete(False) if rows > 0: print('Deleted {0} rows from WorkoutCategory table'.format(rows)) rows = PolarUserModel.query.delete(False) if rows > 0: print('Deleted {0} rows from PolarUser table'.format(rows)) rows = PolarWebhookExerciseModel.query.delete(False) if rows > 0: print('Deleted {0} rows from PolarWebhookExercise table'.format(rows)) db.session.commit() # create test items user = User('existing', '*****@*****.**', 'pwd') #not confirmed profile = Profile(user) user.save(commit=False) profile.save(commit=False) print("Added {0}".format(user)) user = User('JonnyIT', '*****@*****.**', 'pwd') user.confirmed = True profile = Profile(user) profile.set_weight(79.1) profile.set_height(176) profile.set_birth_date(1979, 5, 1) user.save(commit=False) profile.save(commit=False) print("Added {0}".format(user)) user = User('confirm', '*****@*****.**', 'pwd') profile = Profile(user) profile.set_weight(70.1) user.save(commit=False) profile.save(commit=False) print("Added {0}".format(user)) confirmation = UserConfirmation('confirm', 'correct') confirmation.save(commit=False) print("Added {0}".format(confirmation)) discipline = DisciplineModel('10,000m', 10000) discipline.save(commit=False) print("Added {0}".format(discipline)) discipline = DisciplineModel('5,000m', 5000) discipline.save(commit=False) print("Added {0}".format(discipline)) discipline = DisciplineModel('1,500m', 1500) discipline.save(commit=False) print("Added {0}".format(discipline)) workout_cat_run = WorkoutCategoryModel('Running', True) workout_cat_run.save(commit=False) print("Added {0}".format(workout_cat_run)) workout_cat = WorkoutCategoryModel('Cross-country skiing', True) workout_cat.save(commit=False) print("Added {0}".format(workout_cat)) workout_cat = WorkoutCategoryModel('Roller skiing', True) workout_cat.save(commit=False) print("Added {0}".format(workout_cat)) workout_cat_fitness = WorkoutCategoryModel('Fitness', False) workout_cat_fitness.save(commit=False) print("Added {0}".format(workout_cat_fitness)) db.session.commit() goalCatCumRun = GoalCategoryModel('Cumulative distance', 'km', 1) goalCatCumRun.save(commit=False) print("Added {0}".format(goalCatCumRun)) goalCatWeightLoss = GoalCategoryModel('Weight loss', 'kg') goalCatWeightLoss.save(commit=False) print("Added {0}".format(goalCatWeightLoss)) goalCatSkiingCount = GoalCategoryModel('Workout count', '#', 2) goalCatSkiingCount.save(commit=False) print("Added {0}".format(goalCatSkiingCount)) goalCatFitnessCount = GoalCategoryModel('Workout count', '#', 4) goalCatFitnessCount.save(commit=False) print("Added {0}".format(goalCatFitnessCount)) goalCatCumClimb = GoalCategoryModel('Cumulative climb', 'm', 1) # running goalCatCumClimb.save(commit=False) print("Added {0}".format(goalCatCumClimb)) db.session.commit() now = dt.datetime.utcnow() next_january = dt.datetime(now.year + 1, 1, 1) prev_january = dt.datetime(now.year, 1, 1) this_month_first = dt.datetime(now.year, now.month, 1) next_month_first = this_month_first + dt.timedelta(days=monthrange(this_month_first.year, this_month_first.month)[1]) last_day_prev_month = this_month_first + dt.timedelta(days=-1) prev_month_first = this_month_first + dt.timedelta(days=-monthrange(last_day_prev_month.year, last_day_prev_month.month)[1]) prev_monday = dt.datetime(now.year, now.month, now.day) + dt.timedelta(days=-now.weekday()) # future goal goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatSkiingCount, next_january, next_january + dt.timedelta(days=100), 0, 30, 0) goal.save(commit=False) print("Added {0}".format(goal)) goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatCumRun, next_month_first, next_month_first + dt.timedelta(days=monthrange(next_month_first.year, next_month_first.month)[1]), 0, 100, 0) goal.save(commit=False) print("Added {0}".format(goal)) # active goals goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatWeightLoss, prev_monday, prev_monday + dt.timedelta(days=8), 79, 76, 77) goal.save(commit=False) print("Added {0}".format(goal)) goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatCumRun, this_month_first, next_month_first, 0, 100, 22.666) goal.save(commit=False) print("Added {0}".format(goal)) goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatFitnessCount, prev_january, next_january, 0, 20, 4) goal.save(commit=False) print("Added {0}".format(goal)) goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatCumClimb, prev_january - dt.timedelta(days=10), next_january, 0, 8848, 2174) goal.save(commit=False) print("Added {0}".format(goal)) # expired goals goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatCumRun, prev_month_first, this_month_first, 0, 100, 98) goal.save(commit=False) print("Added {0}".format(goal)) goal = GoalModel(User.find_by_username('JonnyIT').profile.id, goalCatWeightLoss, prev_month_first, this_month_first, 82, 80, 79) goal.save(commit=False) print("Added {0}".format(goal)) db.session.commit() # Workouts workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_run, "Åsen run 3", dt.datetime.utcnow(), 7321, 1921, 430) workout.save(commit=False) print("Added {0}".format(workout)) workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_run, "Åsen run 2", dt.datetime.utcnow()-dt.timedelta(seconds=90000), 3000, 658, 621, 'C:/mydev/run4it_backend/run4it/uploads/gpx/test.tcx', 1) workout.save(commit=False) print("Added {0}".format(workout)) workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_run, "Åsen run 1", dt.datetime.utcnow()-dt.timedelta(seconds=180000), 12345, 658, 1123, 'C:/mydev/run4it_backend/run4it/uploads/gpx/test2.tcx', 1) workout.save(commit=False) print("Added {0}".format(workout)) db.session.commit() workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_fitness, "Fitness 1", dt.datetime.utcnow()-dt.timedelta(days=20), 0, 3600, 0) workout.save(commit=False) print("Added {0}".format(workout)) workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_fitness, "Fitness 2", dt.datetime.utcnow()-dt.timedelta(days=17), 0, 3600, 0) workout.save(commit=False) print("Added {0}".format(workout)) workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_fitness, "Fitness 3", dt.datetime.utcnow()-dt.timedelta(days=15), 0, 3600, 0) workout.save(commit=False) print("Added {0}".format(workout)) workout = WorkoutModel(User.find_by_username('JonnyIT').profile.id, workout_cat_fitness, "Fitness 4", dt.datetime.utcnow(), 0, 3600, 0) workout.save(commit=False) print("Added {0}".format(workout)) db.session.commit() print('Application data initialized!') return 0
def test_goal_category_workout_id(self): category1 = GoalCategoryModel.get_by_id(1) category2 = GoalCategoryModel.get_by_id(2) assert(category1.workout_category_id == 1) assert(category2.workout_category_id is None)
def test_goal_category_unit_none_gives_empty_string(self): category = GoalCategoryModel.get_by_id(2) new_goal = GoalModel(1, category) new_goal.save() assert(new_goal.category.id == 2) assert(new_goal.category_unit == '')
def test_get_by_id(self): new_item = GoalCategoryModel("Run Kms") new_item.save() retrieved_item = GoalCategoryModel.get_by_id(new_item.id) assert(retrieved_item == new_item)