Exemple #1
0
    def get_es(cls, es):
        """
        This proxy-method allows the client overwrite
        and the use of a default client for a document.
        Document transport methods should use cls.get_es(es).method()
        This method also validades that the connection is a valid ES client.

        :param es: The Es client or None
        :return: elasticsearch.ElasticSearch() instance or equivalent client
        """
        if not es and hasattr(cls, '_es'):
            es = cls._es if not callable(cls._es) else cls._es()
        validate_client(es)
        return es
Exemple #2
0
    def get_es(cls, es):
        """
        This proxy-method allows the client overwrite
        and the use of a default client for a document.
        Document transport methods should use cls.get_es(es).method()
        This method also validades that the connection is a valid ES client.

        :param es: The Es client or None
        :return: elasticsearch.ElasticSearch() instance or equivalent client
        """
        if not es and hasattr(cls, '_es'):
            es = cls._es if not callable(cls._es) else cls._es()
        validate_client(es)
        return es
Exemple #3
0
def test_client_invalid_interface():
    with pytest.raises(ClientError):
        validate_client(InvalidInterfaceClient())
Exemple #4
0
def test_raise_when_invalid_client():
    with pytest.raises(ClientError):
        validate_client(InvalidClient())
Exemple #5
0
def test_raise_on_none_client():
    with pytest.raises(ClientError):
        validate_client(None)
Exemple #6
0
def test_valid_es_client():
    try:
        validate_client(Client())
    except ClientError as e:
        pytest.fail(e)