def test_reservation_time(self): """Find the total reserved time.""" self._setup_leases() start_date = datetime.datetime.strptime('2030-01-01 09:15', '%Y-%m-%d %H:%M') end_date = datetime.datetime.strptime('2030-01-01 10:15', '%Y-%m-%d %H:%M') reservation_time = db_utils.reservation_time('r1', start_date, end_date) self.assertEqual(reservation_time.seconds, 60 * 60) start_date = datetime.datetime.strptime('2030-01-01 09:15', '%Y-%m-%d %H:%M') end_date = datetime.datetime.strptime('2030-01-01 13:45', '%Y-%m-%d %H:%M') reservation_time = db_utils.reservation_time('r1', start_date, end_date) self.assertEqual(reservation_time.seconds, 120 * 60) start_date = datetime.datetime.strptime('2030-01-01 08:00', '%Y-%m-%d %H:%M') end_date = datetime.datetime.strptime('2030-01-01 15:00', '%Y-%m-%d %H:%M') reservation_time = db_utils.reservation_time('r1', start_date, end_date) self.assertEqual(reservation_time.seconds, 150 * 60)
def test_reservation_ratio(self): """Find the reservation ratio.""" self._setup_leases() start_date = datetime.datetime.strptime('2030-01-01 09:15', '%Y-%m-%d %H:%M') end_date = datetime.datetime.strptime('2030-01-01 14:30', '%Y-%m-%d %H:%M') reservation_time = db_utils.reservation_time('r1', start_date, end_date) availability_time = db_utils.availability_time('r1', start_date, end_date) reservation_ratio = db_utils.reservation_ratio('r1', start_date, end_date) self.assertEqual( reservation_ratio, float(reservation_time.seconds) / (end_date - start_date).seconds) self.assertEqual( reservation_ratio, float((end_date - start_date - availability_time).seconds) / (end_date - start_date).seconds)