from unittest.mock import patch
import functools
import logging


logger = logging.getLogger( 'chibi_elasticsearch.unittests' )


def patch_doc_save( func, target='elasticsearch_dsl.Document.save' ):
    """
    decorador para parchear la funcion save de los documentos de
    elasticseach dls
    """
    @functools.wraps( func )
    def wrapper( *args, **kw ):
        patcher = patch( target )
        with patcher as mock:
            func( *args, mock, **kw )
    return wrapper
