コード例 #1
0
 def test_availability_time(self):
     """Find the total availability 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')
     availability_time = db_utils.availability_time('r1',
                                                    start_date,
                                                    end_date)
     self.assertEqual(availability_time.seconds, 0 * 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')
     availability_time = db_utils.availability_time('r1',
                                                    start_date,
                                                    end_date)
     self.assertEqual(availability_time.seconds, 150 * 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')
     availability_time = db_utils.availability_time('r1',
                                                    start_date,
                                                    end_date)
     self.assertEqual(availability_time.seconds, 270 * 60)
コード例 #2
0
 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)