def test_run_source_missing_skips(self): mock_task = mock.MagicMock() mock_task.async_val = None mock_task.action = "timestamp_file" mock_task.args = dict(path='foo.log') mock_connection = mock.MagicMock() play_context = PlayContext() action = timestamp_file.ActionModule(mock_task, mock_connection, play_context, None, None, None) mock_datetime = mock.MagicMock() mock_datetime.return_value = 'foo' action._get_date_string = mock_datetime mock_execute = mock.MagicMock() mock_execute.side_effect = [{'stat': {'exists': False}}] action._execute_module = mock_execute self.assertRaises(AnsibleActionSkip, action.run) execute_calls = [ mock.call(module_args={'path': 'foo.log'}, module_name='stat', task_vars={}) ] self.assertEqual(1, mock_execute.call_count) mock_execute.assert_has_calls(execute_calls)
def test_run(self): mock_task = mock.MagicMock() mock_task.async_val = None mock_task.action = "timestamp_file" mock_task.args = dict(path='foo.log') mock_connection = mock.MagicMock() play_context = PlayContext() action = timestamp_file.ActionModule(mock_task, mock_connection, play_context, None, None, None) mock_datetime = mock.MagicMock() mock_datetime.return_value = 'foo' action._get_date_string = mock_datetime mock_execute = mock.MagicMock() mock_execute.side_effect = [{ 'stat': { 'exists': True } }, { 'stat': { 'exists': False } }, { 'dest': 'foo.log.foo', 'failed': False, 'changed': True }] action._execute_module = mock_execute result = action.run() execute_calls = [ mock.call(module_args={'path': 'foo.log'}, module_name='stat', task_vars={}), mock.call(module_args={'path': 'foo.log.foo'}, module_name='stat', task_vars={}), mock.call(module_args={ 'src': 'foo.log', 'dest': 'foo.log.foo', 'remote_src': True }, module_name='copy', task_vars={}) ] self.assertEqual(3, mock_execute.call_count) mock_execute.assert_has_calls(execute_calls) expected_result = {'dest': 'foo.log.foo', 'changed': True} self.assertEqual(expected_result, result)