Skip to content

Ci/add test support for v8 #1

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

Open
wants to merge 7 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
32 changes: 5 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,12 @@ jobs:
fail-fast: false

matrix:
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
django-version: ["1.11", "2.0", "2.2", "2.1", "3.0", "3.1","3.2", "4.0", "4.1",]
es-dsl-version: ["6.4", "7.4"]
es-version: ["7.13.4"]
es-dsl-version: ["8.9"]
es-version: ["8.2.0"]

exclude:
- python-version: "2.7"
django-version: "2.0"
- python-version: "2.7"
django-version: "2.1"
- python-version: "2.7"
django-version: "2.2"
- python-version: "2.7"
django-version: "3.0"
- python-version: "2.7"
django-version: "3.1"
- python-version: "2.7"
django-version: "3.2"
- python-version: "2.7"
django-version: "4.0"
- python-version: "2.7"
django-version: "4.1"

- python-version: "3.6"
django-version: "4.0"
- python-version: "3.6"
django-version: "4.1"

- python-version: "3.7"
django-version: "4.0"
- python-version: "3.7"
Expand Down Expand Up @@ -99,7 +77,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -121,7 +99,7 @@ jobs:
- name: Run tests with Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} and elasticsearch-dsl-py ${{ matrix.es-dsl-version }}
run: |
TOX_ENV=$(echo "py${{ matrix.python-version }}-django-${{ matrix.django-version }}-es${{ matrix.es-dsl-version }}" | tr -d .)
python -m tox -e $TOX_ENV -- --elasticsearch
python -m tox -e $TOX_ENV -- --elasticsearch https://localhost:9200 --elasticsearch-username elastic --elasticsearch-password changeme

- name: Publish Coverage Report
uses: codecov/codecov-action@v1
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Features
The library is compatible with all Elasticsearch versions since 5.x
**but you have to use a matching major version:**

- For Elasticsearch 8.0 and later, use the major version 8 (8.x.y) of the library.

- For Elasticsearch 7.0 and later, use the major version 7 (7.x.y) of the library.

- For Elasticsearch 6.0 and later, use the major version 6 (6.x.y) of the library.
Expand All @@ -45,6 +47,9 @@ The library is compatible with all Elasticsearch versions since 5.x

.. code-block:: python

# Elasticsearch 8.x
elasticsearch-dsl>=8.0.0,<9.0.0

# Elasticsearch 7.x
elasticsearch-dsl>=7.0.0,<8.0.0

Expand Down
6 changes: 3 additions & 3 deletions django_elasticsearch_dsl/management/commands/search_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _delete_alias_indices(self, alias):
alias_delete_actions = [
{"remove_index": {"index": index}} for index in alias_indices
]
self.es_conn.indices.update_aliases({"actions": alias_delete_actions})
self.es_conn.indices.update_aliases(actions=alias_delete_actions)
for index in alias_indices:
self.stdout.write("Deleted index '{}'".format(index))

Expand Down Expand Up @@ -231,7 +231,7 @@ def _update_alias(self, alias, new_index, alias_exists, options):
{"remove_index": {"index": index}} for index in old_indices
]

self.es_conn.indices.update_aliases({"actions": alias_actions})
self.es_conn.indices.update_aliases(actions=alias_actions)
if delete_existing_index:
self.stdout.write("Deleted index '{}'".format(alias))

Expand All @@ -247,7 +247,7 @@ def _update_alias(self, alias, new_index, alias_exists, options):

if alias_delete_actions and not options['use_alias_keep_index']:
self.es_conn.indices.update_aliases(
{"actions": alias_delete_actions}
actions=alias_delete_actions
)
for index in old_indices:
self.stdout.write("Deleted index '{}'".format(index))
Expand Down
5 changes: 3 additions & 2 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ For example:

ELASTICSEARCH_DSL={
'default': {
'hosts': 'localhost:9200'
},
'hosts': 'localhost:9200',
'http_auth': ('username', 'password')
}
}

``ELASTICSEARCH_DSL`` is then passed to ``elasticsearch-dsl-py.connections.configure`` (see here_).
Expand Down
2 changes: 1 addition & 1 deletion example/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
-e ../

django-autofixture==0.12.1
Pillow==6.2.0
Pillow==6.2.2
django==4.1.2
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
django>=1.9.6
elasticsearch-dsl>=7.0.0,<8.0.0

elasticsearch-dsl>=8.0.0,<9.0.0
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage==4.1
mock>=1.0.1
flake8>=2.1.0
tox>=1.7.0
Pillow==6.2.0
Pillow==6.2.2


# Additional test requirements go here
61 changes: 55 additions & 6 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
from django.test.utils import get_runner

def get_settings():
elasticsearch_dsl_default_settings = {
'hosts': os.environ.get(
'ELASTICSEARCH_URL',
'https://127.0.0.1:9200'
),
'http_auth': (
os.environ.get('ELASTICSEARCH_USERNAME'),
os.environ.get('ELASTICSEARCH_PASSWORD')
)
}

elasticsearch_certs_path = os.environ.get(
'ELASTICSEARCH_CERTS_PATH'
)
if elasticsearch_certs_path:
elasticsearch_dsl_default_settings['ca_certs'] = (
elasticsearch_certs_path
)
else:
elasticsearch_dsl_default_settings['verify_certs'] = False

settings.configure(
DEBUG=True,
USE_TZ=True,
Expand All @@ -25,10 +46,7 @@ def get_settings():
SITE_ID=1,
MIDDLEWARE_CLASSES=(),
ELASTICSEARCH_DSL={
'default': {
'hosts': os.environ.get('ELASTICSEARCH_URL',
'127.0.0.1:9200')
},
'default': elasticsearch_dsl_default_settings
},
DEFAULT_AUTO_FIELD="django.db.models.BigAutoField",
)
Expand All @@ -55,10 +73,29 @@ def make_parser():
parser.add_argument(
'--elasticsearch',
nargs='?',
metavar='localhost:9200',
const='localhost:9200',
metavar='https://127.0.0.1:9200',
const='https://127.0.0.1:9200',
help="To run integration test against an Elasticsearch server",
)
parser.add_argument(
'--elasticsearch-username',
nargs='?',
metavar='elastic',
const='elastic',
help="Username for Elasticsearch user"
)
parser.add_argument(
'--elasticsearch-password',
nargs='?',
metavar='changeme',
const='changeme',
help="Password for Elasticsearch user"
)
parser.add_argument(
'--elasticsearch-certs-path',
nargs='?',
help="Path to CA certificates for Elasticsearch"
)
return parser


Expand All @@ -67,6 +104,18 @@ def run_tests(*test_args):
if args.elasticsearch:
os.environ.setdefault('ELASTICSEARCH_URL', args.elasticsearch)

os.environ.setdefault(
'ELASTICSEARCH_USERNAME', args.elasticsearch_username
)
os.environ.setdefault(
'ELASTICSEARCH_PASSWORD', args.elasticsearch_password
)

if args.elasticsearch_certs_path:
os.environ.setdefault(
'ELASTICSEARCH_CERTS_PATH', args.elasticsearch_certs_path
)

if not test_args:
test_args = ['tests']

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
except ImportError:
from distutils.core import setup

version = '7.3'
version = '8.0.0'

if sys.argv[-1] == 'publish':
try:
Expand Down Expand Up @@ -42,7 +42,7 @@
],
include_package_data=True,
install_requires=[
'elasticsearch-dsl>=7.2.0,<8.0.0',
'elasticsearch-dsl>=8.9.0,<9.0.0',
'six',
],
license="Apache Software License 2.0",
Expand Down
14 changes: 9 additions & 5 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ def generate_id(cls, article):

# Get the data from the elasticsearch low level API because
# The generator get executed there.
data = json.loads(mock_bulk.call_args[1]['body'].split("\n")[0])
assert data["index"]["_id"] == article.slug
data = json.loads(mock_bulk.call_args[1]['operations'][1])
assert data['slug'] == article.slug

@patch('elasticsearch_dsl.connections.Elasticsearch.bulk')
def test_should_index_object_is_called(self, mock_bulk):
Expand Down Expand Up @@ -535,6 +535,10 @@ def should_index_object(self, obj):

d = ArticleDocument()
d.update([article1, article2])
data_body = mock_bulk.call_args[1]['body']
self.assertTrue(article1.slug in data_body)
self.assertTrue(article2.slug not in data_body)
operations = mock_bulk.call_args[1]['operations']
slugs = [
json.loads(operation)['slug'] for operation in operations
if 'slug' in json.loads(operation)
]
self.assertTrue(article1.slug in slugs)
self.assertTrue(article2.slug not in slugs)
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[tox]
envlist =
py27-django-111-es74
{py36,py37,py38,py39,py310,py311}-django-{111,20,21,22,30,31,32,40,41}-{es64,es74}
{py36,py37,py38,py39,py310,py311}-django-{111,20,21,22,30,31,32,40,41}-{es64,es74,es89}

[testenv]
setenv =
Expand All @@ -20,10 +19,10 @@ deps =
django-41: Django>=4.1,<4.2
es64: elasticsearch-dsl>=6.4.0,<7.0.0
es74: elasticsearch-dsl>=7.4.0,<8
es89: elasticsearch-dsl>=8.9.0,<9
-r{toxinidir}/requirements_test.txt

basepython =
py27: python2.7
py36: python3.6
py37: python3.7
py38: python3.8
Expand Down