Esempio n. 1
0
 def test_last_workout_session(self):
     u = User(username = '******', password = '******', email = '*****@*****.**')
     db.session.add(u)
     db.session.commit()
    
     w = Workout(user_id= u.id, 
                 name="super buff up",
                 level="Medium",
                 is_public=False,
                 is_likeable=False,
                 is_commentable=False)
     
     db.session.add(w)
     db.session.commit()
     
     d = date(2013, 02, 13)
     t = time(2, 52)
     
     wh = WorkoutHistory(user_id = u.id,
                         workout_id = w.id,
                         date = datetime.combine(d, t),
                         is_completed = True)
     
     db.session.add(wh)
     db.session.commit()
     
     wh1 = WorkoutHistory.find_last_workout_session(u.id)
     assert wh1.id == wh.id
     
     d = date(2013, 02, 13)
     t = time(2, 53)
     
     wh = WorkoutHistory(user_id = u.id,
                         workout_id = w.id,
                         date = datetime.combine(d, t),
                         is_completed = True)
     
     db.session.add(wh)
     db.session.commit()
     
     wh2 = WorkoutHistory.find_last_workout_session(u.id)
     assert wh2.id == wh.id
     
     d = date(2013, 02, 13)
     t = time(2, 51)
     
     wh = WorkoutHistory(user_id = u.id,
                         workout_id = w.id,
                         date = datetime.combine(d, t),
                         is_completed = True)
     
     db.session.add(wh)
     db.session.commit()
     
     wh3 = WorkoutHistory.find_last_workout_session(u.id)
     assert wh3.id == wh2.id
Esempio n. 2
0
 def test_get_completed_workouts(self):
     u = User(username = '******', password = '******', email = '*****@*****.**')
     u2 = User(username = '******', password = '******', email = '*****@*****.**')
     db.session.add(u)
     db.session.add(u2)
     db.session.commit()
     print u.id
     print u2.id
    
     w1 = Workout(user_id= u.id, name="super buff up", level="Medium", is_public=False, is_likeable=False, is_commentable=False)
     w2 = Workout(user_id= u.id, name="runners high", level="Medium", is_public=False, is_likeable=False, is_commentable=False)
     w3 = Workout(user_id= u.id, name="hack the riper", level="Medium", is_public=False, is_likeable=False, is_commentable=False)
     db.session.add(w1)
     db.session.add(w2)
     db.session.add(w3)
     db.session.commit()
     
     
     d = date(2013, 02, 10)
     t = time(2, 51)
     wh1 = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh1)
     db.session.commit()
     
     wh = WorkoutHistory.get_completed_workouts(u.id)
     assert wh[0].id == wh1.id
     
     d = date(2013, 02, 10)
     t = time(2, 52)
     wh2 = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = False)
     db.session.add(wh2)
     db.session.commit()
     
     wh = WorkoutHistory.get_completed_workouts(u.id)
     assert wh[0].id == wh1.id
     
     d = date(2013, 02, 12)
     t = time(2, 51)
     wh3 = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh3)
     db.session.commit()
     
     d = date(2013, 02, 11)
     t = time(2, 51)
     wh4 = WorkoutHistory(user_id = u2.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh4)
     db.session.commit()
     
     wh = WorkoutHistory.get_completed_workouts(u.id)
     assert wh[0].id == wh3.id
     assert wh[1].id == wh1.id
     
     wh = WorkoutHistory.get_completed_workouts(u2.id);
     assert wh[0].id == wh4.id
Esempio n. 3
0
 def test_get_workout_sessions(self):
     u = User(username = '******', password = '******', email = '*****@*****.**')
     db.session.add(u)
     db.session.commit()
    
     w1 = Workout(user_id= u.id, name="super buff up", level="Medium", is_public=False, is_likeable=False, is_commentable=False)
     db.session.add(w1)
     db.session.commit()
     
     w2 = Workout(user_id= u.id, name="runners riff", level="Easy", is_public=False, is_likeable=False, is_commentable=False)
     db.session.add(w2)
     db.session.commit()
     
     d = date(2013, 02, 13)
     t = time(2, 52)
     wh1 = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh1)
     db.session.commit()
     
     wh = WorkoutHistory.get_workout_settions(u.id, w1.id)
     assert wh[0].id == wh1.id
     
     d = date(2013, 02, 10)
     t = time(2, 51)
     wh2 = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh2)
     db.session.commit()
     
     wh = WorkoutHistory.get_workout_settions(u.id, w1.id)
     assert wh[0].id == wh2.id
     assert wh[1].id == wh1.id
     
     d = date(2013, 02, 11)
     t = time(2, 51)
     wh3 = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh3)
     db.session.commit()
     
     wh = WorkoutHistory.get_workout_settions(u.id, w1.id)
     assert wh[0].id == wh2.id
     assert wh[1].id == wh3.id
     assert wh[2].id == wh1.id
     
     d = date(2010, 02, 13)
     t = time(2, 52)
     wh5 = WorkoutHistory(user_id = u.id, workout_id = w2.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh5)
     db.session.commit()
     
     wh = WorkoutHistory.get_workout_settions(u.id, w2.id)
     assert wh[0].id == wh5.id
def submit_workout_history():
    wName = request.form['wName']
    date = request.form['date']
    desc = request.form['desc']
    user = User.find_by_username(request.form['user'])
    workout = Workout.find_single_workout_by_name_(wName)
    if(workout == None):
        return jsonify(result="errorName", content=" The workout name you have entered may not exist. Please double check the spelling of the workout name. Thank you")
    if(date == ""):
        return jsonify(result="errorDate", content=" Please enter the date and time of the completed workout")
    
    wh = WorkoutHistory(user.id, workout.id, datetime.strptime(date, "%m/%d/%Y %I:%M:%S %p"), desc, True)
    WorkoutHistory.save_to_db(wh)
       
    feed = "comleted "+wName+" on "+date+" - "+desc;
    user.add_newsfeed(feed);
    return jsonify(result="success");
Esempio n. 5
0
def getWorkoutHistory():
    results = []
    uName = request.args.get('name')
    
    current_user = User.find_by_username(uName)
    if current_user is None:
        w = {"Result":"BAD"}
        return jsonify(w)
    
    completed = WorkoutHistory.get_completed_workouts(current_user.id)
    
    for item in completed:
        name = Workout.find_by_id(item.workout_id).name
        results.append(item.toHash(name))

    w = {"Result":"OK", "Contents":results, "User":current_user.username}
    return jsonify(w)
Esempio n. 6
0
 def test_find_last_session(self):
     u = User(username = '******', password = '******', email = '*****@*****.**')
     db.session.add(u)
     db.session.commit()
    
     w1 = Workout(user_id= u.id, 
                 name="super buff up",
                 level="Medium",
                 is_public=False,
                 is_likeable=False,
                 is_commentable=False)
     w2 = Workout(user_id= u.id, 
                 name="runners high",
                 level="Medium",
                 is_public=False,
                 is_likeable=False,
                 is_commentable=False)
     w3 = Workout(user_id= u.id, 
                 name="hack the riper",
                 level="Medium",
                 is_public=False,
                 is_likeable=False,
                 is_commentable=False)
     
     
     db.session.add(w1)
     db.session.add(w2)
     db.session.add(w3)
     db.session.commit()
     
     d = date(2013, 02, 13)
     t = time(2, 52)
     wh = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh)
     db.session.commit()
     
     wh1 = WorkoutHistory.find_last_session(u.id, w1.id)
     assert wh1.id == wh.id
     
     d = date(2013, 02, 13)
     t = time(4, 52)
     wh = WorkoutHistory(user_id = u.id,  workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh)
     db.session.commit()
     
     wh2 = WorkoutHistory.find_last_session(u.id, w1.id)
     assert wh2.id == wh.id
     
     d = date(2013, 02, 13)
     t = time(3, 52)
     wh = WorkoutHistory(user_id = u.id, workout_id = w2.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh)
     db.session.commit()
     
     wh3 = WorkoutHistory.find_last_session(u.id, w1.id)
     assert wh3.id == wh2.id
     wh4 = WorkoutHistory.find_last_session(u.id, w2.id)
     assert wh4.id == wh.id
     
     d = date(2015, 02, 13)
     t = time(2, 52)
     wh = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh)
     db.session.commit()
     
     wh5 = WorkoutHistory.find_last_session(u.id, w1.id)
     assert wh5.id == wh.id
     
     d = date(2015, 02, 13)
     t = time(2, 52)
     wh = WorkoutHistory(user_id = u.id, workout_id = w3.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh)
     db.session.commit()
     
     wh6 = WorkoutHistory.find_last_session(u.id, w3.id)
     assert wh6.id == wh.id
     
     d = date(2013, 02, 13)
     t = time(3, 52)
     wh = WorkoutHistory(user_id = u.id, workout_id = w1.id, date = datetime.combine(d, t), is_completed = True)
     db.session.add(wh)
     db.session.commit()
     
     wh7 = WorkoutHistory.find_last_session(u.id, w1.id)
     assert wh7.id == wh5.id