def test_persist(self): ## also tests exists, really -- and pull_by_id ci = self.get_test_check_in() self.assertFalse(ci.exists()) ci.persist() self.assertTrue(ci.exists()) self.assertIsNotNone(ci.get_id()) self.assertEqual(ci.to_dict(), CheckIn.pull_by_id(ci.get_id()).to_dict()) ## now if you overwrite that it should still work. ci = CheckIn(self.test_numeric_goal, self.test_tf, 60) self.assertTrue(ci.exists()) ci.persist() test_ci = CheckIn.pull_by_id(ci.get_id()) self.assertEqual(ci.to_dict(), test_ci.to_dict()) self.assertEqual(test_ci.value, 60)
def check_in(id): validate_form(request.form, ["value"]) goal = Goal.pull_by_id(id) if (not goal): raise NotFoundError() if goal.user != current_user.get_id(): raise UnauthorizedError if ('timeframe' in request.form): timeframe = Timeframe.pull_by_id(request.form['timeframe']) else: timeframe = Timeframe.get_current_timeframe(goal.check_in_frequency_name) check_in = CheckIn(goal, timeframe, request.form['value']) return_code = 200 if check_in.exists() else 201 check_in.persist() return check_in.to_json(), return_code