def test_workflow_starting_with_masked_tenant( self, mock_update_execution_status, mock_workflow_cancelled, mock_rest_client, *args, **kwargs): workflow_handler = dispatch.WorkflowHandler( cloudify_context={'task_name': 'test'}, args=(), kwargs={}) _normal_func = workflow_handler._func _normal_ctx = workflow_handler._ctx workflow_handler._func = type('MockFunc', (object,), { 'workflow_system_wide': True, '__call__': func2}) workflow_handler._ctx = type('MockWorkflowContext', (object,), { 'local': False, 'logger': MagicMock(), 'internal': MagicMock(), 'execution_id': 'test_execution_id', 'workflow_id': 'test_workflow_id', 'dry_run': False, 'resume': False }) workflow_handler._ctx._context = {'tenant': { 'name': 'yes', 'original_name': 'masquerade'}} workflow_handler._ctx.tenant_name = 'yes' try: workflow_handler.handle() mock_rest_client.assert_called_once_with(tenant='masquerade') finally: workflow_handler._func = _normal_func workflow_handler._ctx = _normal_ctx
def test_workflow_update_execution_status_set_to_false( self, mock_update_execution_status, *args, **kwargs): workflow_handler = dispatch.WorkflowHandler( cloudify_context={ 'task_name': 'test', 'update_execution_status': False }, args=(), kwargs={}) _normal_func = workflow_handler._func _normal_ctx = workflow_handler._ctx workflow_handler._func = func2 workflow_handler._ctx = type('MockWorkflowContext', (object,), { 'local': False, 'logger': MagicMock(), 'internal': MagicMock(), 'execution_id': 'test_execution_id', 'workflow_id': 'test_workflow_id', 'dry_run': False, 'resume': False }) # this is for making the implementation go the "local" way despite # ctx.local == false as execution status is only updated in remote # mode. workflow_handler._handle_remote_workflow = \ workflow_handler._handle_local_workflow try: workflow_handler.handle() self.assertEqual(0, mock_update_execution_status.call_count) finally: workflow_handler._func = _normal_func workflow_handler._ctx = _normal_ctx
def test_workflow_starting_with_execution_cancelled( self, mock_update_execution_status, mock_workflow_cancelled, *args, **kwargs): workflow_handler = dispatch.WorkflowHandler( cloudify_context={'task_name': 'test'}, args=(), kwargs={}) _normal_func = workflow_handler._func _normal_ctx = workflow_handler._ctx workflow_handler._func = type('MockFunc', (object,), { 'workflow_system_wide': True, '__call__': func2}) workflow_handler._ctx = type('MockWorkflowContext', (object,), { 'local': False, 'logger': MagicMock(), 'internal': MagicMock(), 'execution_id': 'test_execution_id', 'workflow_id': 'test_workflow_id', 'dry_run': False, 'resume': False }) workflow_handler._ctx._context = {'tenant': {'name': 'yes'}} workflow_handler._ctx.tenant_name = 'yes' try: workflow_handler.handle() mock_update_execution_status.assert_called_with( 'test_execution_id', 'started', None) mock_workflow_cancelled.assert_called_with() self.assertEqual(3, mock_update_execution_status.call_count) finally: workflow_handler._func = _normal_func workflow_handler._ctx = _normal_ctx