def test_pull_by_goal_timeframe(self): ci = CheckIn.pull_by_goal_timeframe(self.test_numeric_goal.get_id(), self.test_tf.get_id()) self.assertIsNone(ci) ci = self.get_test_check_in() ci.persist() test_ci = CheckIn.pull_by_goal_timeframe(self.test_numeric_goal.get_id(), self.test_tf.get_id()) self.assertEqual(ci.to_dict(), test_ci.to_dict())
def get_check_in(id, tfid): """Get the check-in for a given timeframe. Returns 404 if there is no check-in for that timeframe""" goal = Goal.pull_by_id(id) if (not goal): raise NotFoundError() if goal.user != current_user.get_id(): raise UnauthorizedError check_in = CheckIn.pull_by_goal_timeframe(id, tfid) if (not check_in): raise NotFoundError() return check_in.to_json(), 200
def get_current_check_in(id): """Get the current check-in for a given goal. Returns 404 if the current check-in or goal does not exist""" goal = Goal.pull_by_id(id) if (not goal): raise NotFoundError() if goal.user != current_user.get_id(): raise UnauthorizedError check_in = CheckIn.pull_by_goal_timeframe(id, Timeframe.get_current_timeframe(goal.check_in_frequency_name).get_id()) if (not check_in): raise NotFoundError() return check_in.to_json(), 200