def test_run_expect(remote_connection): expected_run_expect_response = libs_pb2.RunExpectResponse() expected_run_expect_response.return_value.exit_code = 0 expected_run_expect_response.return_value.stdout = 'stdout' expected_run_expect_response.return_value.stderr = 'stderr' expected_command = 'command' expected_variables = None def mock_run_expect(actual_run_expect_request): assert actual_run_expect_request.command == expected_command actual_environment = ( actual_run_expect_request.remote_connection.environment) assert (actual_environment.name == remote_connection.environment.name) assert (actual_environment.reference == remote_connection.environment.reference) return expected_run_expect_response with mock.patch('dlpx.virtualization._engine.libs.run_expect', side_effect=mock_run_expect, create=True): actual_run_expect_result = libs.run_expect( remote_connection, expected_command, expected_variables) expected = expected_run_expect_response.return_value assert actual_run_expect_result.exit_code == expected.exit_code assert actual_run_expect_result.stdout == expected.stdout assert actual_run_expect_result.stderr == expected.stderr
def test_run_expect_with_nonactionable_error(remote_connection): response = libs_pb2.RunExpectResponse() na_error = libs_pb2.NonActionableLibraryError() response.error.non_actionable_error.CopyFrom(na_error) with mock.patch('dlpx.virtualization._engine.libs.run_expect', return_value=response, create=True): with pytest.raises(SystemExit): libs.run_expect(remote_connection, "command")
def test_run_expect_with_actionable_error(remote_connection): expected_id = 15 expected_message = 'Some message' response = libs_pb2.RunExpectResponse() response.error.actionable_error.id = expected_id response.error.actionable_error.message = expected_message with mock.patch('dlpx.virtualization._engine.libs.run_expect', return_value=response, create=True): with pytest.raises(LibraryError) as err_info: libs.run_expect(remote_connection, 'command') assert err_info.value._id == expected_id assert err_info.value.message == expected_message
def test_run_expect_check_true_exitcode_failed(remote_connection): expected_message = ( 'The script failed with exit code 1.' ' stdout : stdout and stderr : stderr' ) response = libs_pb2.RunExpectResponse() response.return_value.exit_code = 1 response.return_value.stdout = "stdout" response.return_value.stderr = "stderr" with mock.patch("dlpx.virtualization._engine.libs.run_expect", return_value=response, create=True): with pytest.raises(PluginScriptError) as info: response = libs.run_expect(remote_connection, "test_command", check=True) assert info.value.message == expected_message