class TestScheduleResource(unittest.TestCase): def setUp(self): super(TestScheduleResource, self).setUp() self.controller = ScheduleResource() @mock.patch.object(ScheduleResource, 'ok') @mock.patch('pulp.server.webservices.http.uri_path', return_value='http://foo/bar') def test_get(self, mock_path, mock_ok, mock_utils_get): call = ScheduledCall('PT1M', 'pulp.tasks.frequent') mock_utils_get.return_value = [call] ret = self.controller._get(call.id) schedule = mock_ok.call_args[0][0] self.assertEqual(ret, mock_ok.return_value) self.assertEqual(len(mock_ok.call_args[0]), 1) # spot-check the schedule self.assertEqual(schedule['_id'], call.id) self.assertEqual(schedule['schedule'], 'PT1M') self.assertEqual(schedule['task'], 'pulp.tasks.frequent') self.assertEqual(schedule['_href'], mock_path.return_value) # now check overall equality with the actual for_display value del schedule['_href'] self.assertEqual(schedule, call.for_display()) # make sure we called the manager layer correctly mock_utils_get.assert_called_once_with([call.id]) def test_missing(self, mock_utils_get): call = ScheduledCall('PT1M', 'pulp.tasks.frequent') mock_utils_get.return_value = [] self.assertRaises(exceptions.MissingResource, self.controller._get, call.id)
class TestScheduleResource(unittest.TestCase): def setUp(self): super(TestScheduleResource, self).setUp() self.controller = ScheduleResource() @mock.patch.object(ScheduleResource, 'ok') @mock.patch('pulp.server.webservices.http.uri_path', return_value='http://foo/bar') def test_get(self, mock_path, mock_ok, mock_utils_get): call = ScheduledCall('PT1M', 'pulp.tasks.frequent') mock_utils_get.return_value = [call] ret = self.controller._get(call.id) schedule = mock_ok.call_args[0][0] self.assertEqual(ret, mock_ok.return_value) self.assertEqual(len(mock_ok.call_args[0]), 1) # spot-check the schedule self.assertEqual(schedule['_id'], call.id) self.assertEqual(schedule['schedule'], 'PT1M') self.assertEqual(schedule['task'], 'pulp.tasks.frequent') self.assertEqual(schedule['_href'], mock_path.return_value) # next_run is calculated on-demand, and there is a small chance that it # will be re-calculated in the call.for_display() call as 1 second later # than it was calculated above. Thus we will test that equality here # with a tolerance of 1 second for_display = call.for_display() call_next_run = dateutils.parse_iso8601_datetime(call.next_run) display_next_run = dateutils.parse_iso8601_datetime( for_display['next_run']) self.assertTrue( display_next_run - call_next_run <= timedelta(seconds=1)) # now check overall equality with the actual for_display value del schedule['_href'] del schedule['next_run'] del for_display['next_run'] self.assertEqual(schedule, for_display) # make sure we called the manager layer correctly mock_utils_get.assert_called_once_with([call.id]) def test_missing(self, mock_utils_get): call = ScheduledCall('PT1M', 'pulp.tasks.frequent') mock_utils_get.return_value = [] self.assertRaises(exceptions.MissingResource, self.controller._get, call.id)
class TestScheduleResource(unittest.TestCase): def setUp(self): super(TestScheduleResource, self).setUp() self.controller = ScheduleResource() @mock.patch.object(ScheduleResource, 'ok') @mock.patch('pulp.server.webservices.http.uri_path', return_value='http://foo/bar') def test_get(self, mock_path, mock_ok, mock_utils_get): call = ScheduledCall('PT1M', 'pulp.tasks.frequent') mock_utils_get.return_value = [call] ret = self.controller._get(call.id) schedule = mock_ok.call_args[0][0] self.assertEqual(ret, mock_ok.return_value) self.assertEqual(len(mock_ok.call_args[0]), 1) # spot-check the schedule self.assertEqual(schedule['_id'], call.id) self.assertEqual(schedule['schedule'], 'PT1M') self.assertEqual(schedule['task'], 'pulp.tasks.frequent') self.assertEqual(schedule['_href'], mock_path.return_value) # next_run is calculated on-demand, and there is a small chance that it # will be re-calculated in the call.for_display() call as 1 second later # than it was calculated above. Thus we will test that equality here # with a tolerance of 1 second for_display = call.for_display() call_next_run = dateutils.parse_iso8601_datetime(call.next_run) display_next_run = dateutils.parse_iso8601_datetime(for_display['next_run']) self.assertTrue(display_next_run - call_next_run <= timedelta(seconds=1)) # now check overall equality with the actual for_display value del schedule['_href'] del schedule['next_run'] del for_display['next_run'] self.assertEqual(schedule, for_display) # make sure we called the manager layer correctly mock_utils_get.assert_called_once_with([call.id]) def test_missing(self, mock_utils_get): call = ScheduledCall('PT1M', 'pulp.tasks.frequent') mock_utils_get.return_value = [] self.assertRaises(exceptions.MissingResource, self.controller._get, call.id)
def setUp(self): super(TestScheduleResource, self).setUp() self.controller = ScheduleResource()