def test_general_api(): """The slightly more easy API.""" def curl_func(week): return "{} x 10".format(week) # Create a 4-week program program = Program("My first program!", duration=8) # Create some dynamic and static exercises bench = DynamicExercise("Bench press", 60, 70) squats = DynamicExercise("Squats", 80, 90) curls = StaticExercise("Curls", curl_func) day = Day(exercises=[bench, squats, curls]) # Variable reference to days are added assert bench.day is not None assert squats.day is not None assert len(day.dynamic_exercises) == 2 # Add day(s) to program and render it program.add_days(day) assert day.program is not None assert len(program.days) == 1 assert not program._rendered program.render() assert program._rendered
def test_verbose_api(duration): """The oldest, most verbose API.""" def curl_func(week): return "{} x 10".format(week) # Create a 4-week program program = Program("My first program!", duration=duration) # Create some dynamic and static exercises bench = DynamicExercise("Bench press", 60, 60 * (1 + 0.01 * duration)) squats = DynamicExercise("Squats", 80, 80 * (1 + 0.01 * duration)) curls = StaticExercise("Curls", curl_func) day = Day() day.add_exercises(bench, squats, curls) assert len(day.dynamic_exercises) == 2 # Add day(s) to program and render it program.add_days(day) assert len(program.days) == 1 assert not program._rendered program.render() assert program._rendered
def test_exercisedescription_program(): with temporary_db("tempfile.db", delete=False): engine = create_engine("sqlite:///tempfile.db", echo=True) Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() ed = ExerciseDescription(name="Bench press", description="Let's see if this works!") session.add(ed) session.commit() #del session # Create a 4-week program program = Program('My first program!', duration=4) # Create some dynamic and static exercises bench = DynamicExercise('Bench press', start_weight=60, final_weight=80) squats = DynamicExercise('Squats', start_weight=80, final_weight=95) curls = StaticExercise('Curls', '3 x 12') day = Day(exercises=[bench, squats, curls]) # Add day(s) to program and render it program.add_days(day) program.render() p = program_to_sql(program, engine=engine) #session = Session() session.commit() return program, p
def test_dynamic_exercises_are_not_mutated(): """Creating a program should not mutate an exercise.""" # Create an exercise exercise = DynamicExercise("Bench press", start_weight=100) exercise_dict = exercise.serialize() # Create a program, add the day and render it program = Program() day = Day("Monday") day.add_exercises(exercise) program.add_days(day) program.render() assert exercise.serialize() == exercise_dict
def test_single_program(): session = create_memory_session() # Create a 4-week program program = Program('My first program!', duration=4) # Create some dynamic and static exercises bench = DynamicExercise('Bench press', start_weight=60, final_weight=80) squats = DynamicExercise('Squats', start_weight=80, final_weight=95) curls = StaticExercise('Curls', '3 x 12') day = Day(exercises=[bench, squats, curls]) # Add day(s) to program and render it program.add_days(day) program.render() p = program_to_sql(program) return session, program, p