Extract ElasticTestCase from YamlTestCase
This commit is contained in:
@@ -8,7 +8,7 @@ import requests
|
|||||||
from elasticsearch import Elasticsearch
|
from elasticsearch import Elasticsearch
|
||||||
from elasticsearch.exceptions import ConnectionError
|
from elasticsearch.exceptions import ConnectionError
|
||||||
|
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest, TestCase
|
||||||
|
|
||||||
data_dir = None
|
data_dir = None
|
||||||
|
|
||||||
@@ -29,22 +29,7 @@ CMD = """
|
|||||||
server = None
|
server = None
|
||||||
pidfile = tempfile.mktemp()
|
pidfile = tempfile.mktemp()
|
||||||
|
|
||||||
from os import environ
|
|
||||||
from os.path import join, dirname, pardir, exists
|
|
||||||
|
|
||||||
YAML_DIR = environ.get(
|
|
||||||
'YAML_TEST_DIR',
|
|
||||||
join(
|
|
||||||
dirname(__file__),
|
|
||||||
pardir, pardir, pardir,
|
|
||||||
'elasticsearch-rest-api-spec', 'test'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
# no integration tests, skip starting the server
|
|
||||||
if not exists(YAML_DIR):
|
|
||||||
raise SkipTest('')
|
|
||||||
global server
|
global server
|
||||||
|
|
||||||
# use running ES instance, don't attempt to start our own
|
# use running ES instance, don't attempt to start our own
|
||||||
@@ -97,3 +82,11 @@ def teardown():
|
|||||||
pid = pidf.read()
|
pid = pidf.read()
|
||||||
os.kill(int(pid), 15)
|
os.kill(int(pid), 15)
|
||||||
server.wait()
|
server.wait()
|
||||||
|
|
||||||
|
class ElasticTestCase(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Elasticsearch([os.environ['TEST_ES_SERVER']])
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.client.indices.delete()
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ some integration tests. These files are shared among all official Elasticsearch
|
|||||||
clients.
|
clients.
|
||||||
"""
|
"""
|
||||||
from os import walk, environ
|
from os import walk, environ
|
||||||
from os.path import exists, join
|
from os.path import exists, join, dirname, pardir
|
||||||
import yaml
|
import yaml
|
||||||
from unittest import TestCase, SkipTest
|
from unittest import SkipTest
|
||||||
|
|
||||||
from elasticsearch import Elasticsearch
|
from . import ElasticTestCase
|
||||||
|
|
||||||
from test_elasticsearch.test_server import YAML_DIR
|
|
||||||
|
|
||||||
# some params had to be changed in python, keep track of them so we can rename
|
# some params had to be changed in python, keep track of them so we can rename
|
||||||
# those in the tests accordingly
|
# those in the tests accordingly
|
||||||
@@ -29,7 +27,7 @@ def _get_version(version_string):
|
|||||||
version = version_string.strip().split('.')
|
version = version_string.strip().split('.')
|
||||||
return tuple(int(v) if v.isdigit() else 999 for v in version)
|
return tuple(int(v) if v.isdigit() else 999 for v in version)
|
||||||
|
|
||||||
class YamlTestCase(TestCase):
|
class YamlTestCase(ElasticTestCase):
|
||||||
_definition = None
|
_definition = None
|
||||||
@property
|
@property
|
||||||
def es_version(self):
|
def es_version(self):
|
||||||
@@ -40,14 +38,10 @@ class YamlTestCase(TestCase):
|
|||||||
return ES_VERSION
|
return ES_VERSION
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = Elasticsearch([environ['TEST_ES_SERVER']])
|
super(YamlTestCase, self).setUp()
|
||||||
self.last_response = None
|
self.last_response = None
|
||||||
self._state = {}
|
self._state = {}
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
# clean up everything
|
|
||||||
self.client.indices.delete()
|
|
||||||
|
|
||||||
def test_from_yaml(self):
|
def test_from_yaml(self):
|
||||||
if not self._definition:
|
if not self._definition:
|
||||||
raise SkipTest('Empty test.')
|
raise SkipTest('Empty test.')
|
||||||
@@ -190,7 +184,14 @@ def construct_case(filename, name):
|
|||||||
|
|
||||||
return type(name, (YamlTestCase, ), attrs)
|
return type(name, (YamlTestCase, ), attrs)
|
||||||
|
|
||||||
|
YAML_DIR = environ.get(
|
||||||
|
'YAML_TEST_DIR',
|
||||||
|
join(
|
||||||
|
dirname(__file__),
|
||||||
|
pardir, pardir, pardir,
|
||||||
|
'elasticsearch-rest-api-spec', 'test'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if exists(YAML_DIR):
|
if exists(YAML_DIR):
|
||||||
# find all the test definitions in yaml files ...
|
# find all the test definitions in yaml files ...
|
||||||
|
|||||||
Reference in New Issue
Block a user