Example #1
0
    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_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_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