def test_run_sync_with_nonactionable_error(remote_connection): response = libs_pb2.RunSyncResponse() na_error = libs_pb2.NonActionableLibraryError() response.error.non_actionable_error.CopyFrom(na_error) with mock.patch('dlpx.virtualization._engine.libs.run_sync', return_value=response, create=True): with pytest.raises(SystemExit): libs.run_sync(remote_connection, "dir")
def test_run_sync_bad_rsync_user(remote_connection): source_directory = 'sourceDirectory' # Set the rsync_user be an int instead of a string. rsync_user = 10 exclude_paths = ['/path1', '/path2'] sym_links_to_follow = ['/path3', '/path4'] with pytest.raises(IncorrectArgumentTypeError) as err_info: libs.run_sync(remote_connection, source_directory, rsync_user, exclude_paths, sym_links_to_follow) assert err_info.value.message == ( "The function run_sync's argument 'rsync_user' was" " type 'int' but should be of type 'basestring' if defined.")
def test_run_sync_bad_sym_links_to_follow(remote_connection): source_directory = 'sourceDirectory' rsync_user = '******' exclude_paths = ['/path1', '/path2'] # Set the sym_links_to_follow list to be int instead of a string. sym_links_to_follow = ['/path3', 10] with pytest.raises(IncorrectArgumentTypeError) as err_info: libs.run_sync(remote_connection, source_directory, rsync_user, exclude_paths, sym_links_to_follow) assert err_info.value.message == ( "The function run_sync's argument 'sym_links_to_follow' was" " a list of [type 'str', type 'int'] but should be of" " type 'list of basestring' if defined.")
def test_run_sync_exclude_paths_not_list(remote_connection): source_directory = 'sourceDirectory' rsync_user = '******' # Set the exclude_paths be an string instead of a list. exclude_paths = '/path' sym_links_to_follow = ['/path3', '/path4'] with pytest.raises(IncorrectArgumentTypeError) as err_info: libs.run_sync(remote_connection, source_directory, rsync_user, exclude_paths, sym_links_to_follow) assert err_info.value.message == ( "The function run_sync's argument 'exclude_paths' was" " type 'str' but should be of" " type 'list of basestring' if defined.")
def test_run_sync_with_actionable_error(remote_connection): expected_id = 15 expected_message = 'Some message' response = libs_pb2.RunSyncResponse() response.error.actionable_error.id = expected_id response.error.actionable_error.message = expected_message with mock.patch('dlpx.virtualization._engine.libs.run_sync', return_value=response, create=True): with pytest.raises(LibraryError) as err_info: libs.run_sync(remote_connection, 'dir') assert err_info.value._id == expected_id assert err_info.value.message == expected_message
def test_run_sync(remote_connection): expected_run_sync_response = libs_pb2.RunSyncResponse() expected_source_directory = 'sourceDirectory' expected_rsync_user = '******' expected_exclude_paths = ['/path1', '/path2'] expected_sym_links_to_follow = ['/path3', '/path4'] def mock_run_sync(actual_run_sync_request): assert (actual_run_sync_request.source_directory == expected_source_directory) actual_environment = ( actual_run_sync_request.remote_connection.environment) assert ( actual_environment.name == remote_connection.environment.name) assert (actual_environment.reference == remote_connection.environment.reference) assert actual_run_sync_request.rsync_user == expected_rsync_user assert (actual_run_sync_request.exclude_paths == expected_exclude_paths) assert (actual_run_sync_request.sym_links_to_follow == expected_sym_links_to_follow) return expected_run_sync_response with mock.patch('dlpx.virtualization._engine.libs.run_sync', side_effect=mock_run_sync, create=True): actual_runsync_response = libs.run_sync( remote_connection, expected_source_directory, expected_rsync_user, expected_exclude_paths, expected_sym_links_to_follow) assert actual_runsync_response is None
def test_run_sync_bad_remote_connection(): # Set the connection be a string instead of a RemoteConnection. connection = 'BadRemoteConnection' source_directory = 'sourceDirectory' rsync_user = '******' exclude_paths = ['/path1', '/path2'] sym_links_to_follow = ['/path3', '/path4'] with pytest.raises(IncorrectArgumentTypeError) as err_info: libs.run_sync(connection, source_directory, rsync_user, exclude_paths, sym_links_to_follow) assert err_info.value.message == ( "The function run_sync's argument 'remote_connection' was" " type 'str' but should be of" " class 'dlpx.virtualization.common._common_classes.RemoteConnection'." )