Skip to content

Commit

Permalink
Merge bcf0add into e29100c
Browse files Browse the repository at this point in the history
  • Loading branch information
kblumke committed Aug 1, 2016
2 parents e29100c + bcf0add commit 380061d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
14 changes: 12 additions & 2 deletions src/pytest_elasticsearch/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with pytest-elasticsearch. If not, see <http://www.gnu.org/licenses/>.
"""Fixture factories."""
# along with pytest-dbfixtures. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil

import pytest
Expand Down Expand Up @@ -112,11 +114,17 @@ def elasticsearch_proc_fixture(request):
else:
multicast_enabled = config['discovery_zen_ping_multicast_enabled']

script_path = home_path + '/scripts'
conf_path = home_path + '/config'
if not os.path.exists(conf_path):
os.makedirs(conf_path)

command_exec = '''
{deamon} -p {pidfile} --http.port={port}
--path.home={home_path} --default.path.logs={logs_path}
--default.path.work={work_path}
--default.path.conf=/etc/elasticsearch
--default.path.conf={conf_dir}
--default.path.scripts={script_dir}
--cluster.name={cluster}
--network.publish_host='{network_publish_host}'
--discovery.zen.ping.multicast.enabled={multicast_enabled}
Expand All @@ -131,7 +139,9 @@ def elasticsearch_proc_fixture(request):
cluster=elasticsearch_cluster_name,
network_publish_host=elasticsearch_network_publish_host,
multicast_enabled=multicast_enabled,
index_store_type=elasticsearch_index_store_type
index_store_type=elasticsearch_index_store_type,
conf_dir=conf_path,
script_dir=script_path
)

elasticsearch_executor = HTTPExecutor(
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_elasticsearch/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pytest_addoption(parser):
parser.addini(
name='elasticsearch_index_store_type',
help='',
default='memory'
default=''
)

parser.addini(
Expand Down
48 changes: 30 additions & 18 deletions tests/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def test_elastic_process(elasticsearch_proc):

def test_elasticsarch(elasticsearch):
"""Test if elasticsearch fixtures connects to process."""
info = elasticsearch.info()
assert info['status'] == 200
assert elasticsearch.cluster.health()['status'] == 'green'


elasticsearch_proc_random = factories.elasticsearch_proc(port='?')
Expand All @@ -21,27 +20,40 @@ def test_elasticsarch(elasticsearch):

def test_random_port(elasticsearch_random):
"""Test if elasticsearch fixture can be started on random port."""
assert elasticsearch_random.info()['status'] == 200
assert elasticsearch_random.cluster.health()['status'] == 'green'


def test_default_configuration(request):
"""Test default configuration."""
config = factories.return_config(request)
def test_index_creation(elasticsearch):
"""Test if index creation via elasticsearch fixture succeeds."""
name = 'mytestindex'
elasticsearch.indices.create(index=name)
assert name in elasticsearch.indices.get_settings().keys()

assert config['logsdir'] == '/tmp'
assert config['port'] == 9201
assert config['host'] == '127.0.0.1'
assert config['cluster_name'] == 'elasticsearch_cluster_9201'
assert config['network_publish_host'] == '127.0.0.1'
assert config['discovery_zen_ping_multicast_enabled'] == 'false'
assert config['index_store_type'] == 'memory'
assert config['logs_prefix'] == ''

logsdir_ini = request.config.getini('elasticsearch_logsdir')
logsdir_option = request.config.getoption('logsdir')
def test_default_configuration(request):
"""
Test default configuration.
(Works only if not command line option is passed.)
"""
default_config = {
'logsdir': '/tmp', 'discovery_zen_ping_multicast_enabled': 'false',
'index_store_type': '', 'network_publish_host': '127.0.0.1',
'cluster_name': 'elasticsearch_cluster_9201', 'host': '127.0.0.1',
'logs_prefix': '', 'port': 9201
}

options = (
'logsdir', 'port', 'host', 'cluster_name',
'network_publish_host', 'discovery_zen_ping_multicast_enabled',
'index_store_type', 'logs_prefix'
)

config = factories.return_config(request)

assert logsdir_ini == '/tmp'
assert logsdir_option is None
for option in options:
if not request.config.getoption(option):
assert config[option] == default_config[option]


@patch('pytest_elasticsearch.plugin.pytest.config')
Expand Down

0 comments on commit 380061d

Please sign in to comment.