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