def test_pull_by_id(self): ## Test that a timeframe that exists can be pulled by ID self.assertIsNone(Timeframe.pull_by_id(0)) tf = Timeframe("yearly", datetime.datetime(2016, 1, 1)) tf.persist() self.assertTrue(tf.exists()) check_tf = Timeframe.pull_by_id(tf.get_id()).to_dict() for key, val in tf.to_dict().iteritems(): self.assertEqual(check_tf[key], val)
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
def test_get_id(self): ## Test that a Timeframe that has just been persisted returns an ID tf = Timeframe("yearly", datetime.datetime(2016, 1, 1)) tf.persist() self.assertIsNotNone(tf.get_id()) ## Test that a timeframe pulled by id returns same id check_tf = Timeframe.pull_by_id(tf.get_id()) self.assertEqual(check_tf.get_id(), tf.get_id()) ## Test that a timeframe created by start / end persistes, then returns an ID tf = Timeframe("monthly", datetime.datetime(2016, 1, 1)) self.assertIsNotNone(tf.get_id()) self.assertTrue(tf.exists()) self.assertNotEqual(tf.get_id(), check_tf.get_id()) ## Test that a timeframe pulled by start / end returns an ID check_tf = Timeframe.pull_by_start_end(tf.start, tf.end) self.assertEqual(check_tf.get_id(), tf.get_id())
def reconstruct(self): self.goal_obj = Goal.pull_by_id(self.goal) self.timeframe_obj = Timeframe.pull_by_id(self.timeframe)