class FailTests(base.PulpServerTests): def setUp(self): self.call_request = CallRequest(fail) self.call_report = CallReport() self.task = Task(self.call_request, self.call_report) def tearDown(self): self.call_request = None self.call_report = None self.task = None def test_failed(self): self.task._run() self.assertTrue(self.call_report.state is dispatch_constants.CALL_ERROR_STATE, self.call_report.state) self.assertTrue(isinstance(self.call_report.exception, RuntimeError), str(type(self.call_report.exception))) self.assertTrue(isinstance(self.call_report.traceback, types.TracebackType)) def test_error_execution_hook(self): hook = mock.Mock() self.call_request.add_life_cycle_callback(dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, hook) self.task._run() self.assertTrue(hook.call_count == 1) self.assertTrue(hook.call_args[0][0] is self.call_request) self.assertTrue(hook.call_args[0][1] is self.call_report)
class FailTests(base.PulpServerTests): def setUp(self): self.call_request = CallRequest(fail) self.call_report = CallReport() self.task = Task(self.call_request, self.call_report) def tearDown(self): self.call_request = None self.call_report = None self.task = None def test_failed(self): self.task._run() self.assertTrue( self.call_report.state is dispatch_constants.CALL_ERROR_STATE, self.call_report.state) self.assertTrue(isinstance(self.call_report.exception, RuntimeError), str(type(self.call_report.exception))) self.assertTrue( isinstance(self.call_report.traceback, types.TracebackType)) def test_error_execution_hook(self): hook = mock.Mock() self.call_request.add_life_cycle_callback( dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, hook) self.task._run() self.assertTrue(hook.call_count == 1) self.assertTrue(hook.call_args[0][0] is self.call_request) self.assertTrue(hook.call_args[0][1] is self.call_report)
def test_task_archival(self): task = Task(CallRequest(call_without_callbacks, archive=True)) try: task._run() except: self.fail(traceback.format_exc()) collection = ArchivedCall.get_collection() archived_call = collection.find_one({'serialized_call_report.call_request_id': task.call_request.id}) self.assertFalse(archived_call is None)
def test_task_archival(self): task = Task(CallRequest(call_without_callbacks, archive=True)) try: task._run() except: self.fail(traceback.format_exc()) collection = ArchivedCall.get_collection() archived_call = collection.find_one( {'serialized_call_report.call_request_id': task.call_request.id}) self.assertFalse(archived_call is None)
class TaskTests(base.PulpServerTests): def setUp(self): super(TaskTests, self).setUp() self.call_request = CallRequest(Call(), call_args, call_kwargs) self.call_report = CallReport() self.task = Task(self.call_request, self.call_report) def tearDown(self): super(TaskTests, self).tearDown() self.call_request = None self.call_report = None self.task = None def test_run(self): self.assertTrue(self.call_report.state is dispatch_constants.CALL_WAITING_STATE) self.task._run() self.assertTrue(self.call_request.call.call_count == 1) self.assertTrue(self.call_request.call.call_args[0] == call_args, '%s != %s' % (str(self.call_request.call.call_args[0]), str(call_args))) self.assertTrue(self.call_request.call.call_args[1] == call_kwargs) self.assertTrue(self.call_report.state is dispatch_constants.CALL_FINISHED_STATE) def test_complete(self): now = datetime.datetime.now(dateutils.utc_tz()) self.task._run() self.assertTrue(self.call_report.finish_time > now) def test_complete_callback(self): callback = mock.Mock() self.task.complete_callback = callback self.task._run() self.assertTrue(callback.call_count == 1) self.assertTrue(callback.call_args[0][0] is self.task) def test_cancel_control_hook(self): callback = mock.Mock() self.call_request.add_control_hook(dispatch_constants.CALL_CANCEL_CONTROL_HOOK, callback) self.call_report.state = dispatch_constants.CALL_RUNNING_STATE try: self.task.cancel() except: self.fail(traceback.format_exc()) self.assertTrue(callback.call_count == 1) self.assertTrue(callback.call_args[0][0] is self.call_request) self.assertTrue(callback.call_args[0][1] is self.call_report) self.assertTrue(self.call_report.state is dispatch_constants.CALL_CANCELED_STATE, self.call_report.state) def test_finish_execution_hook(self): hooks = [mock.Mock(), mock.Mock()] for h in hooks: self.call_request.add_life_cycle_callback(dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, h) self.task._run() for h in hooks: self.assertTrue(h.call_count == 1) self.assertTrue(h.call_args[0][0] is self.call_request) self.assertTrue(h.call_args[0][1] is self.call_report) def test_complete_execution_hook(self): hooks = [mock.Mock(), mock.Mock()] for h in hooks: self.call_request.add_life_cycle_callback(dispatch_constants.CALL_COMPLETE_LIFE_CYCLE_CALLBACK, h) self.task._run() for h in hooks: self.assertTrue(h.call_count == 1)
def test_set_principal(self): user = User('test-user', 'test-password') task = Task(CallRequest(self.principal_manager.get_principal, principal=user)) task._run() self.assertEqual(user, task.call_report.result)
class TaskTests(base.PulpServerTests): def setUp(self): super(TaskTests, self).setUp() self.call_request = CallRequest(Call(), call_args, call_kwargs) self.call_report = CallReport() self.task = Task(self.call_request, self.call_report) def tearDown(self): super(TaskTests, self).tearDown() self.call_request = None self.call_report = None self.task = None def test_run(self): self.assertTrue( self.call_report.state is dispatch_constants.CALL_WAITING_STATE) self.task._run() self.assertTrue(self.call_request.call.call_count == 1) self.assertTrue( self.call_request.call.call_args[0] == call_args, '%s != %s' % (str(self.call_request.call.call_args[0]), str(call_args))) self.assertTrue(self.call_request.call.call_args[1] == call_kwargs) self.assertTrue( self.call_report.state is dispatch_constants.CALL_FINISHED_STATE) def test_complete(self): now = datetime.datetime.now(dateutils.utc_tz()) self.task._run() self.assertTrue(self.call_report.finish_time > now) def test_complete_callback(self): callback = mock.Mock() self.task.complete_callback = callback self.task._run() self.assertTrue(callback.call_count == 1) self.assertTrue(callback.call_args[0][0] is self.task) def test_cancel_control_hook(self): callback = mock.Mock() self.call_request.add_control_hook( dispatch_constants.CALL_CANCEL_CONTROL_HOOK, callback) self.call_report.state = dispatch_constants.CALL_RUNNING_STATE try: self.task.cancel() except: self.fail(traceback.format_exc()) self.assertTrue(callback.call_count == 1) self.assertTrue(callback.call_args[0][0] is self.call_request) self.assertTrue(callback.call_args[0][1] is self.call_report) self.assertTrue( self.call_report.state is dispatch_constants.CALL_CANCELED_STATE, self.call_report.state) def test_finish_execution_hook(self): hooks = [mock.Mock(), mock.Mock()] for h in hooks: self.call_request.add_life_cycle_callback( dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, h) self.task._run() for h in hooks: self.assertTrue(h.call_count == 1) self.assertTrue(h.call_args[0][0] is self.call_request) self.assertTrue(h.call_args[0][1] is self.call_report) def test_complete_execution_hook(self): hooks = [mock.Mock(), mock.Mock()] for h in hooks: self.call_request.add_life_cycle_callback( dispatch_constants.CALL_COMPLETE_LIFE_CYCLE_CALLBACK, h) self.task._run() for h in hooks: self.assertTrue(h.call_count == 1)
def test_set_principal(self): user = User('test-user', 'test-password') task = Task( CallRequest(self.principal_manager.get_principal, principal=user)) task._run() self.assertEqual(user, task.call_report.result)