Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to support ES 8.X #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
install:
- pip install tox-travis
- pip install coveralls
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ELASTICMOCK_VERSION='1.8.1'
ELASTICMOCK_VERSION='2.0.0'

install:
pip3 install -r requirements.txt
Expand All @@ -7,7 +7,7 @@ test_install: install
pip3 install -r requirements_test.txt

test: test_install
python3.9 setup.py test
python3.12 setup.py test

upload: create_dist
pip3 install twine
Expand All @@ -16,11 +16,11 @@ upload: create_dist

create_dist: create_dist_no_commit update_pip
rm -rf dist
python3.9 setup.py sdist
python3.12 setup.py sdist

create_dist_no_commit: update_pip
rm -rf dist
python3.9 setup.py sdist
python3.12 setup.py sdist

create_dist_commit:
git commit --all -m "Bump version ${ELASTICMOCK_VERSION}"
Expand Down
8 changes: 4 additions & 4 deletions elasticmock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import wraps

from elasticsearch.client import _normalize_hosts
from elasticsearch._sync.client.utils import client_node_configs
from unittest.mock import patch

from elasticmock.fake_elasticsearch import FakeElasticsearch
Expand All @@ -11,15 +11,15 @@


def _get_elasticmock(hosts=None, *args, **kwargs):
host = _normalize_hosts(hosts)[0]
host = client_node_configs(hosts, cloud_id=None)[0]
elastic_key = '{0}:{1}'.format(
host.get('host', 'localhost'), host.get('port', 9200)
host.host, host.port
)

if elastic_key in ELASTIC_INSTANCES:
connection = ELASTIC_INSTANCES.get(elastic_key)
else:
connection = FakeElasticsearch()
connection = FakeElasticsearch(hosts=[host])
ELASTIC_INSTANCES[elastic_key] = connection
return connection

Expand Down
18 changes: 12 additions & 6 deletions elasticmock/fake_cluster.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# -*- coding: utf-8 -*-
import typing as t
from elasticsearch._sync.client.cluster import ClusterClient
from elasticsearch._sync.client.utils import _rewrite_parameters

from elasticsearch.client.cluster import ClusterClient
from elasticsearch.client.utils import query_params

from elastic_transport import ObjectApiResponse
from elasticmock.utilities.decorator import wrap_object_api_response


class FakeClusterClient(ClusterClient):

@query_params('level', 'local', 'master_timeout', 'timeout',
'wait_for_active_shards', 'wait_for_nodes',
'wait_for_relocating_shards', 'wait_for_status')
def health(self, index=None, params=None, headers=None):
@_rewrite_parameters()
@wrap_object_api_response
def health(
self,
**params
) -> ObjectApiResponse[t.Any]:
return {
'cluster_name': 'testcluster',
'status': 'green',
Expand Down
Loading