def test_elasticsearch_teardown(): """ Verify that temporary directories and files are cleaned up after the server is stopped. """ es = ElasticSearchServer() with es as es: result = requests.get(es.uri()) assert result.status_code == 200 assert not os.path.isdir(es._root)
def test_elasticsearch_context(): """ Verify that using the elasticsearch server as a context block sets up and tears down as expected. """ es = ElasticSearchServer() with pytest.raises(requests.exceptions.MissingSchema): # invalid uri requests.get(es.uri()) previous_uri = None with es as es: uri = es.uri() result = requests.get(uri) assert result.status_code == 200 assert uri is not None previous_uri = uri with pytest.raises(requests.exceptions.ConnectionError): # elasticsearch is no longer running requests.get(previous_uri)