33
44from django .db import models
55from django .utils .translation import ugettext_lazy as _
6- from elasticsearch_dsl import GeoPoint , MetaField , InnerDoc
7- from mock import patch , Mock , PropertyMock
6+ from elasticsearch_dsl import GeoPoint , InnerDoc
7+ from mock import patch , Mock
88
99from django_elasticsearch_dsl import fields
10- from django_elasticsearch_dsl .documents import DocType , Document
10+ from django_elasticsearch_dsl .documents import DocType
1111from django_elasticsearch_dsl .exceptions import (ModelFieldNotMappedError ,
1212 RedeclaredFieldError )
1313from django_elasticsearch_dsl .registries import registry
1414from tests import ES_MAJOR_VERSION
1515
1616from .models import Article
17- from .documents import ArticleDocument , ArticleWithSlugAsIdDocument
1817
1918
2019class Car (models .Model ):
@@ -72,7 +71,6 @@ def test_auto_refresh_default(self):
7271 self .assertTrue (CarDocument .django .auto_refresh )
7372
7473 def test_ignore_signal_added (self ):
75-
7674 @registry .register_document
7775 class CarDocument2 (DocType ):
7876 class Django :
@@ -138,20 +136,20 @@ def test_mapping(self):
138136
139137 self .assertEqual (
140138 CarDocument ._doc_type .mapping .to_dict (), {
141- 'properties' : {
142- 'name' : {
143- 'type' : text_type
144- },
145- 'color' : {
146- 'type' : text_type
147- },
148- 'type' : {
149- 'type' : text_type
150- },
151- 'price' : {
152- 'type' : 'double'
153- }
139+ 'properties' : {
140+ 'name' : {
141+ 'type' : text_type
142+ },
143+ 'color' : {
144+ 'type' : text_type
145+ },
146+ 'type' : {
147+ 'type' : text_type
148+ },
149+ 'price' : {
150+ 'type' : 'double'
154151 }
152+ }
155153 }
156154 )
157155
@@ -359,7 +357,7 @@ class Django:
359357 bulk = "django_elasticsearch_dsl.documents.bulk"
360358 parallel_bulk = "django_elasticsearch_dsl.documents.parallel_bulk"
361359 with patch (bulk ) as mock_bulk , patch (parallel_bulk ) as mock_parallel_bulk :
362- doc .update ([car3 , car2 , car3 ])
360+ doc .update ([car1 , car2 , car3 ])
363361 self .assertEqual (
364362 3 , len (list (mock_bulk .call_args_list [0 ][1 ]['actions' ]))
365363 )
@@ -390,13 +388,13 @@ def test_init_prepare_correct(self):
390388
391389 expect = {
392390 'color' : ("<class 'django_elasticsearch_dsl.fields.TextField'>" ,
393- ("<class 'method'>" , "<type 'instancemethod'>" )), # py3, py2
391+ ("<class 'method'>" , "<type 'instancemethod'>" )), # py3, py2
394392 'type' : ("<class 'django_elasticsearch_dsl.fields.TextField'>" ,
395- ("<class 'functools.partial'>" ,"<type 'functools.partial'>" )),
393+ ("<class 'functools.partial'>" , "<type 'functools.partial'>" )),
396394 'name' : ("<class 'django_elasticsearch_dsl.fields.TextField'>" ,
397- ("<class 'functools.partial'>" ,"<type 'functools.partial'>" )),
395+ ("<class 'functools.partial'>" , "<type 'functools.partial'>" )),
398396 'price' : ("<class 'django_elasticsearch_dsl.fields.DoubleField'>" ,
399- ("<class 'functools.partial'>" ,"<type 'functools.partial'>" )),
397+ ("<class 'functools.partial'>" , "<type 'functools.partial'>" )),
400398 }
401399
402400 for name , field , prep in d ._prepared_fields :
@@ -412,8 +410,8 @@ def test_init_prepare_results(self):
412410 car = Car ()
413411 setattr (car , 'name' , "Tusla" )
414412 setattr (car , 'price' , 340123.21 )
415- setattr (car , 'color' , "polka-dots" ) # Overwritten by prepare function
416- setattr (car , 'pk' , 4701 ) # Ignored, not in document
413+ setattr (car , 'color' , "polka-dots" ) # Overwritten by prepare function
414+ setattr (car , 'pk' , 4701 ) # Ignored, not in document
417415 setattr (car , 'type' , "imaginary" )
418416
419417 self .assertEqual (d .prepare (car ), {'color' : 'blue' , 'type' : 'imaginary' , 'name' : 'Tusla' , 'price' : 340123.21 })
@@ -425,8 +423,8 @@ def test_init_prepare_results(self):
425423 with patch .object (CarDocument , '_fields' , 33 ):
426424 d .prepare (m )
427425 self .assertEqual (sorted ([tuple (x ) for x in m .method_calls ], key = lambda _ : _ [0 ]),
428- [('name' , (), {}), ('price' , (), {}), ('type' , (), {})]
429- )
426+ [('name' , (), {}), ('price' , (), {}), ('type' , (), {})]
427+ )
430428
431429 # Mock the elasticsearch connection because we need to execute the bulk so that the generator
432430 # got iterated and generate_id called.
@@ -438,6 +436,7 @@ def test_default_generate_id_is_called(self, _):
438436 id = 124594 ,
439437 slug = 'some-article' ,
440438 )
439+
441440 @registry .register_document
442441 class ArticleDocument (DocType ):
443442 class Django :
0 commit comments