Example #1
0
    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)
Example #2
0
    def test_pull_by_goal_timeframes(self):
        ci = self.get_test_check_in()
        timeframes = [ci.timeframe]
        ci.persist()
        for x in range(0, 7):
            tf = ci.timeframe_obj
            new_tf = Timeframe(tf.frequency_name, tf.start + datetime.timedelta(1))
            timeframes.append(new_tf.get_id())
            ci = CheckIn(ci.goal_obj, new_tf, x)
            ci.persist() 
            

        cis = CheckIn.pull_by_goal_timeframes(ci.goal, timeframes)
        self.assertEqual(len(cis), 8)
Example #3
0
    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())