Example #1
0
    def test_pull_by_goal_start_end(self):
        ci = self.get_test_check_in()
        ci.persist()
        for x in range(0, 7):
            tf = ci.timeframe_obj
            new_tf = Timeframe(tf.frequency_name, tf.start + datetime.timedelta(1))
            ci = CheckIn(ci.goal_obj, new_tf, x)
            ci.persist() 
            

        cis = CheckIn.pull_by_goal_start_end(ci.goal, datetime.datetime(2016, 1, 1), datetime.datetime(2016, 1, 8))
        self.assertEqual(len(cis), 7)
Example #2
0
def get_by_time(id):
    goal = Goal.pull_by_id(id)
    if (not goal):
        raise NotFoundError()
    
    if goal.user != current_user.get_id():
        raise UnauthorizedError

    if (not 'start' in request.args or not 'end' in request.args):
        raise InvalidRequest(["start and end are required parameters"])

    try:
        start = datetime.datetime.strptime(request.args['start'], "%Y-%m-%d %H:%M:%S")
        end = datetime.datetime.strptime(request.args['end'], "%Y-%m-%d %H:%M:%S")
    except ValueError as e:
        raise InvalidRequest([e.message])

    check_ins = CheckIn.pull_by_goal_start_end(id, start, end)

    return jsonify({"check-ins": [check_in.to_dict() for check_in in check_ins]}), 200