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
def test_client_invalid_interface(): with pytest.raises(ClientError): validate_client(InvalidInterfaceClient())
def test_raise_when_invalid_client(): with pytest.raises(ClientError): validate_client(InvalidClient())
def test_raise_on_none_client(): with pytest.raises(ClientError): validate_client(None)
def test_valid_es_client(): try: validate_client(Client()) except ClientError as e: pytest.fail(e)