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 test_persist(self): ## Test that data persists to the database tf = Timeframe("yearly", datetime.datetime(2016, 1, 1)) tf.persist() self.assertTrue(tf.exists()) check_tf = Timeframe.pull_by_start_end(tf.start, tf.end).to_dict() for key, val in tf.to_dict().iteritems(): self.assertEqual(check_tf[key], val) ## Test that you can persist the same one twice without duplicate key, etc errors tf.persist()
def test_pull_by_start_end(self): ## Pulling by start / end should return None if none exists: self.assertIsNone(Timeframe.pull_by_start_end(datetime.datetime(2016, 1, 1), datetime.datetime(2017, 1, 1))) tf = Timeframe("yearly", datetime.datetime(2016, 1, 1)) tf.persist() self.assertTrue(tf.exists()) check_tf = Timeframe.pull_by_start_end(tf.start, tf.end).to_dict() for key, val in tf.to_dict().iteritems(): self.assertEqual(check_tf[key], val) ## Should *not* pull if the start is right and end is wrong or vice versa: self.assertIsNone(Timeframe.pull_by_start_end(tf.start, datetime.datetime(2016, 2, 1))) self.assertIsNone(Timeframe.pull_by_start_end(datetime.datetime(2016, 2, 1), tf.end))