def test_last_scheduled_run_no_first_run(self): call = ScheduledCall('PT1H', 'pulp.tasks.dosomething') last_scheduled_run_s = call._calculate_times()[4] first_run_s = call._calculate_times()[1] self.assertEqual(last_scheduled_run_s, first_run_s)
def test_run_every(self): call = ScheduledCall('2014-01-03T10:15Z/PT1H', 'pulp.tasks.dosomething') run_every_s = call._calculate_times()[3] # 1 hour, as specified in the ISO8601 string above self.assertEqual(run_every_s, 3600)
def test_since_first(self): call = ScheduledCall('2014-01-03T10:15Z/PT1H', 'pulp.tasks.dosomething') since_first = call._calculate_times()[2] now = time.time() self.assertTrue(since_first + 1388744100 - now < 1)
def test_first_run_now(self): call = ScheduledCall('PT1M', 'pulp.tasks.dosomething') first_run_s = call._calculate_times()[1] # make sure this gives us a timestamp that reasonably represents "now" self.assertTrue(time.time() - first_run_s < 1)
def test_last_scheduled_run_with_first_run(self, mock_time): # specify a start time and current time such that we know the difference mock_time.return_value = 1389307330.966561 call = ScheduledCall('2014-01-09T17:15Z/PT1H', 'pulp.tasks.dosomething') last_scheduled_run_s = call._calculate_times()[4] self.assertEqual(last_scheduled_run_s, 1389305700)
def test_first_run_scheduled(self): call = ScheduledCall('2014-01-03T10:15Z/PT1H', 'pulp.tasks.dosomething') first_run_s = call._calculate_times()[1] # make sure this gives us a timestamp for the date and time # specified above self.assertEqual(first_run_s, 1388744100)
def test_expected_runs_positive(self, mock_time): # specify a start time and current time such that we know the difference mock_time.return_value = 1389307330.966561 call = ScheduledCall('2014-01-09T17:15Z/PT1H', 'pulp.tasks.dosomething') expected_runs = call._calculate_times()[5] # we know that it's been more than 5 hours since the first scheduled run self.assertEqual(expected_runs, 5)
def test_expected_runs_future(self, mock_time): # specify a start time and current time such that the start appears to # be in the future mock_time.return_value = 1389307330.966561 call = ScheduledCall('2014-01-19T17:15Z/PT1H', 'pulp.tasks.dosomething') expected_runs = call._calculate_times()[5] # the first run is scheduled in the future (relative to the mock time), # so there should not be any runs. self.assertEqual(expected_runs, 0)
def test_first_run_saved(self): """ Test that when the first run is passed in from historical data. """ call = ScheduledCall('PT1H', 'pulp.tasks.dosomething', first_run='2014-01-03T10:15Z') first_run_s = call._calculate_times()[1] # make sure this gives us a timestamp for the date and time # specified above self.assertEqual(first_run_s, 1388744100)
def test_expected_runs_zero(self): call = ScheduledCall('PT1H', 'pulp.tasks.dosomething') expected_runs = call._calculate_times()[5] self.assertEqual(expected_runs, 0)