def test_event_callback_interface_has_ident(rc): rc.ident = "testident" runner = Runner(config=rc, remove_partials=False) runner.event_handler = mock.Mock() with mock.patch('codecs.open', mock.mock_open(read_data=json.dumps(dict(event="test")))): runner.event_callback(dict(uuid="testuuid", counter=0)) assert runner.event_handler.call_count == 1 runner.event_handler.assert_called_with(dict(runner_ident='testident', counter=0, uuid='testuuid', event='test')) runner.status_callback("running")
def test_event_callback_data_check(rc, mocker): rc.ident = "testident" rc.check_job_event_data = True runner = Runner(config=rc, remove_partials=False) runner.event_handler = mocker.Mock() with pytest.raises(AnsibleRunnerException) as exc: runner.event_callback(dict(uuid="testuuid", counter=0)) assert "Failed to open ansible stdout callback plugin partial data" in str( exc)
def test_event_callback_interface_has_ident(rc, mocker): rc.ident = "testident" runner = Runner(config=rc, remove_partials=False) runner.event_handler = mocker.Mock() mocker.patch('codecs.open', mocker.mock_open(read_data=json.dumps(dict(event="test")))) chmod = mocker.patch('os.chmod', mocker.Mock()) mocker.patch('os.mkdir', mocker.Mock()) runner.event_callback(dict(uuid="testuuid", counter=0)) assert runner.event_handler.call_count == 1 runner.event_handler.assert_called_with( dict(runner_ident='testident', counter=0, uuid='testuuid', event='test', created=mocker.ANY)) chmod.assert_called_once() runner.status_callback("running")