Esempio n. 1
0
def uptasticsearch_factory(url, retries=5, backoff_factor=0.1):
    http_client = HttpClient(retries=retries, backoff_factor=backoff_factor)
    es_url = _format_es_url(url)
    cluster_version = http_client.get(es_url).json()['version']['number'].split('.')[0]

    return {"1": Uptasticsearch1,
            "2": Uptasticsearch2,
            "5": Uptasticsearch5,
            "6": Uptasticsearch6}[cluster_version](es_url, http_client)
 def test_nonsense(self):
     """test that it fails with nonsense
     """
     with pytest.raises(ValueError):
         _format_es_url("some garbage string")
     with pytest.raises(ValueError):
         _format_es_url("some garbage string that has http:// in it")
     with pytest.raises(ValueError):
         _format_es_url("some garbage string that has http:// in it:9200")
     with pytest.raises(ValueError):
         _format_es_url("s3:// some garbage string that has http:// in it:9200")
 def test_port(self):
     """raises ValueError w/o proper port
     """
     with pytest.raises(ValueError):
         _format_es_url("es.cluster.com/")
     with pytest.raises(ValueError):
         _format_es_url("es.cluster.com")
     assert isinstance(_format_es_url("http://es.com:9200"), str)
     assert isinstance(_format_es_url("es.es.com:9200"), str)
Esempio n. 4
0
 def __init__(self, url, http_client=HttpClient()):
     self.url = _format_es_url(url)
     self.client = http_client
 def test_protocol(self):
     """inserts protocol if missing/broken
     """
     assert _format_es_url("es.cluster.com:9200/") == "http://es.cluster.com:9200"
     assert _format_es_url("http:/es.cluster.com:9200/") == "http://es.cluster.com:9200"
 def test_slash_removal(self):
     """removes extra trailing slashes
     """
     assert _format_es_url("http://es.cluster.com:9200/") == "http://es.cluster.com:9200"
     assert _format_es_url("http://es.cluster.com:9200///") == "http://es.cluster.com:9200"
 def test_normal(self):
     """returns a valid url unchanged
     """
     valid_url = "http://es.cluster.com:9200"
     assert valid_url == _format_es_url(valid_url)
     assert "http://localhost:9200" == _format_es_url("localhost:9200")
 def test_typing(self):
     """throws TypeErrors w/ bad types, returns correct type
     """
     with pytest.raises(TypeError):
         _format_es_url(3)
     with pytest.raises(TypeError):
         _format_es_url(3.14)
     with pytest.raises(TypeError):
         _format_es_url(lambda x: 'cat')
     with pytest.raises(TypeError):
         _format_es_url([1, 2, 3])
     with pytest.raises(TypeError):
         _format_es_url({"key": "value"})
     assert isinstance(_format_es_url("http://es.com:9200"), str)