diff --git a/.travis.yml b/.travis.yml index 2f289e65..a8bfc7a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # Config file for automatic testing at travis-ci.org language: python -python: 3.8 +python: 3.7 dist: xenial # default "precise" distro doesn't include Java 8 for Elasticsearch 5 @@ -11,8 +11,6 @@ matrix: python: 3.6 - env: TOX_ENV=py37-django-111-es6 python: 3.7 - - env: TOX_ENV=py38-django-111-es6 - python: 3.8 - env: TOX_ENV=py27-django-111-es6 python: 2.7 - env: TOX_ENV=py36-django-2-es6 @@ -23,21 +21,11 @@ matrix: python: 3.7 - env: TOX_ENV=py37-django-22-es6 python: 3.7 - - env: TOX_ENV=py37-django-30-es6 - python: 3.7 - - env: TOX_ENV=py38-django-2-es6 - python: 3.8 - - env: TOX_ENV=py38-django-21-es6 - python: 3.8 - - env: TOX_ENV=py38-django-22-es6 - python: 3.8 - - env: TOX_ENV=py38-django-30-es6 - python: 3.8 cache: pip env: global: - - ES_APT_URL=https://artifacts.elastic.co/packages/7.x/apt + - ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt before_install: # work around https://github.com/travis-ci/travis-ci/issues/8363 diff --git a/django_elasticsearch_dsl/documents.py b/django_elasticsearch_dsl/documents.py index 4defa8b7..9940f158 100644 --- a/django_elasticsearch_dsl/documents.py +++ b/django_elasticsearch_dsl/documents.py @@ -23,6 +23,7 @@ TextField, ) from .search import Search +from .versions import ES_MAJOR_VERSION model_field_class_to_field_class = { models.AutoField: IntegerField, @@ -159,8 +160,8 @@ def parallel_bulk(self, actions, **kwargs): @classmethod def generate_id(cls, object_instance): """ - The default behavior is to use the Django object's pk (id) as the - elasticseach index id (_id). If needed, this method can be overloaded + The default behavior is to use the Django object's pk (id) as the + elasticseach index id (_id). If needed, this method can be overloaded to change this default behavior. """ return object_instance.pk @@ -170,6 +171,7 @@ def _prepare_action(self, object_instance, action): '_op_type': action, '_index': self._index._name, '_id': self.generate_id(object_instance), + '_type': self._doc_type.name, '_source': ( self.prepare(object_instance) if action != 'delete' else None ), diff --git a/django_elasticsearch_dsl/versions.py b/django_elasticsearch_dsl/versions.py new file mode 100644 index 00000000..7f06df26 --- /dev/null +++ b/django_elasticsearch_dsl/versions.py @@ -0,0 +1,3 @@ +from elasticsearch_dsl import VERSION + +ES_MAJOR_VERSION = VERSION[0] diff --git a/setup.py b/setup.py index cf74203d..31141971 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ except ImportError: from distutils.core import setup -version = '7.1.4' +version = '6.5.0' if sys.argv[-1] == 'publish': try: @@ -42,7 +42,7 @@ ], include_package_data=True, install_requires=[ - 'elasticsearch-dsl>=7.0.0<8.0.0', + 'elasticsearch-dsl>=6.4.0<7.0.0', 'six', ], license="Apache Software License 2.0", diff --git a/tests/__init__.py b/tests/__init__.py index 7f06df26..e69de29b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +0,0 @@ -from elasticsearch_dsl import VERSION - -ES_MAJOR_VERSION = VERSION[0] diff --git a/tests/test_documents.py b/tests/test_documents.py index 6a4f29d3..c70e1e8d 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -11,7 +11,7 @@ from django_elasticsearch_dsl.exceptions import (ModelFieldNotMappedError, RedeclaredFieldError) from django_elasticsearch_dsl.registries import registry -from tests import ES_MAJOR_VERSION +from django_elasticsearch_dsl.versions import ES_MAJOR_VERSION from .models import Article from .documents import ArticleDocument, ArticleWithSlugAsIdDocument @@ -62,6 +62,8 @@ class Index: class DocTypeTestCase(TestCase): + maxDiff = None + def test_model_class_added(self): self.assertEqual(CarDocument.django.model, Car) @@ -136,8 +138,10 @@ def test_to_field_with_unknown_field(self): def test_mapping(self): text_type = 'string' if ES_MAJOR_VERSION == 2 else 'text' - self.assertEqual( - CarDocument._doc_type.mapping.to_dict(), { + doc_type_mapping = CarDocument._doc_type.mapping.to_dict()['car_document'] + + self.assertDictEqual( + doc_type_mapping, { 'properties': { 'name': { 'type': text_type @@ -164,7 +168,7 @@ def test_prepare(self): car = Car(name="Type 57", price=5400000.0, not_indexed="not_indexex") doc = CarDocument() prepared_data = doc.prepare(car) - self.assertEqual( + self.assertDictEqual( prepared_data, { 'color': doc.prepare_color(None), 'type': car.type(), @@ -188,7 +192,7 @@ class Index: car = Car(name="Type 57", price=5400000.0, not_indexed="not_indexex") doc = CarDocumentDSlBaseField() prepared_data = doc.prepare(car) - self.assertEqual( + self.assertDictEqual( prepared_data, { 'name': car.name, 'price': car.price @@ -211,10 +215,13 @@ def test_model_instance_update(self): 'color': doc.prepare_color(None), }, '_index': 'car_index', + '_type': 'car_document' }] + self.assertEqual(1, mock.call_count) self.assertEqual( - actions, list(mock.call_args_list[0][1]['actions']) + actions, list(mock.call_args_list[0][1]['actions']), + str(list(mock.call_args_list[0][1]['actions'])) ) self.assertTrue(mock.call_args_list[0][1]['refresh']) self.assertEqual( @@ -239,6 +246,7 @@ def test_model_instance_iterable_update(self): 'color': doc.prepare_color(None), }, '_index': 'car_index', + '_type': 'car_document' }, { '_id': car2.pk, @@ -249,10 +257,11 @@ def test_model_instance_iterable_update(self): 'type': car2.type(), 'color': doc.prepare_color(None), }, - '_index': 'car_index' + '_index': 'car_index', + '_type': 'car_document' }] self.assertEqual(1, mock.call_count) - self.assertEqual( + self.assertListEqual( actions, list(mock.call_args_list[0][1]['actions']) ) self.assertTrue(mock.call_args_list[0][1]['refresh']) diff --git a/tests/test_fields.py b/tests/test_fields.py index af216ae2..98c0ee43 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -13,7 +13,7 @@ ListField, LongField, NestedField, ObjectField, ShortField, TextField ) -from tests import ES_MAJOR_VERSION +from django_elasticsearch_dsl.versions import ES_MAJOR_VERSION class DEDFieldTestCase(TestCase): diff --git a/tests/test_integration.py b/tests/test_integration.py index c95bcfb3..f8c99f98 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -10,7 +10,7 @@ from elasticsearch.exceptions import NotFoundError from elasticsearch_dsl import Index as DSLIndex from django_elasticsearch_dsl.test import ESTestCase -from tests import ES_MAJOR_VERSION +from django_elasticsearch_dsl.versions import ES_MAJOR_VERSION from .documents import ( ad_index, @@ -31,6 +31,9 @@ "--elasticsearch not set" ) class IntegrationTestCase(ESTestCase, TestCase): + + maxDiff = None + def setUp(self): super(IntegrationTestCase, self).setUp() self.manufacturer = Manufacturer( @@ -103,7 +106,7 @@ def test_get_doc_with_reverse_relationships(self): result = s.execute() self.assertEqual(len(result), 1) car1_doc = result[0] - self.assertEqual(car1_doc.ads, [ + self.assertListEqual(list(car1_doc.ads), [ { 'title': self.ad1.title, 'description': self.ad1.description, @@ -123,7 +126,7 @@ def test_get_doc_with_many_to_many_relationships(self): result = s.execute() self.assertEqual(len(result), 1) car1_doc = result[0] - self.assertEqual(car1_doc.categories, [ + self.assertListEqual(list(car1_doc.categories), [ { 'title': self.category1.title, 'slug': self.category1.slug, @@ -141,7 +144,7 @@ def test_doc_to_dict(self): result = s.execute() self.assertEqual(len(result), 1) car2_doc = result[0] - self.assertEqual(car2_doc.to_dict(), { + self.assertDictEqual(car2_doc.to_dict(), { 'type': self.car2.type, 'launched': self.car2.launched, 'name': self.car2.name, @@ -160,7 +163,7 @@ def test_doc_to_dict(self): result = s.execute() self.assertEqual(len(result), 1) car3_doc = result[0] - self.assertEqual(car3_doc.to_dict(), { + self.assertDictEqual(car3_doc.to_dict(), { 'type': self.car3.type, 'launched': self.car3.launched, 'name': self.car3.name, @@ -188,7 +191,7 @@ def test_index_to_dict(self): index_dict = test_index.to_dict() - self.assertEqual(index_dict['settings'], { + self.assertDictEqual(index_dict['settings'], { 'number_of_shards': 1, 'number_of_replicas': 0, 'analysis': { @@ -203,7 +206,12 @@ def test_index_to_dict(self): } } }) - self.assertEqual(index_dict['mappings'], { + + index_dict_mappings = index_dict['mappings']["doc"] + + self.assertDictEqual( + index_dict_mappings, + { 'properties': { 'ads': { 'type': 'nested', @@ -235,7 +243,8 @@ def test_index_to_dict(self): 'launched': {'type': 'date'}, 'type': {'type': text_type} } - }) + } + ) def test_related_docs_are_updated(self): # test foreignkey relation @@ -363,8 +372,8 @@ def test_default_document_id(self): slug=article_slug, ) - # saving should create two documents (in the two indices): one with the - # Django object's id as the ES doc _id, and the other with the slug + # saving should create two documents (in the two indices): one with the + # Django object's id as the ES doc _id, and the other with the slug # as the ES _id article.save() @@ -381,8 +390,8 @@ def test_custom_document_id(self): slug=article_slug, ) - # saving should create two documents (in the two indices): one with the - # Django object's id as the ES doc _id, and the other with the slug + # saving should create two documents (in the two indices): one with the + # Django object's id as the ES doc _id, and the other with the slug # as the ES _id article.save() diff --git a/tox.ini b/tox.ini index 599dad26..d9840442 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,9 @@ [tox] envlist = - py27-django-111-es7 - {py36,py37,py38}-django-{111,2,21,22,30}-{es7} + {py27,py36,py37}-django-111-{es6} + {py36,py37}-django-2-{es6} + {py36,py37}-django-21-{es6} + {py36,py37}-django-22-{es6} [testenv] setenv = @@ -14,13 +16,10 @@ deps = django-2: Django>=2.0,<2.1 django-21: Django>=2.1,<2.2 django-22: Django>=2.2,<2.3 - django-30: Django>=3.0,<3.1 es6: elasticsearch-dsl>=6.4.0,<7.0.0 - es7: elasticsearch-dsl>=7,<8 -r{toxinidir}/requirements_test.txt basepython = py27: python2.7 py36: python3.6 py37: python3.7 - py38: python3.8 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy