Skip to content

Commit

Permalink
Uncomment 'refresh=True' for Elasticsearch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
clairempr committed Apr 26, 2022
1 parent a859263 commit 2ee7799
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 29 deletions.
16 changes: 4 additions & 12 deletions letters/models/letter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ def create_or_update_in_elasticsearch(self, is_new):
index it in Elasticsearch
If it's an existing Letter, update the Elasticsearch index
Calling create() or update() with refresh as arg causes TypeError: got an unexpected keyword argument 'refresh',
at least in a unit test, so it's commented out
"""

es = es_settings.ES_CLIENT
Expand All @@ -155,15 +152,15 @@ def create_or_update_in_elasticsearch(self, is_new):
index=self._meta.es_index_name,
doc_type=self._meta.es_type_name,
id=self.pk,
# refresh=True,
refresh=True,
body=payload
)
else:
es.update(
index=self._meta.es_index_name,
doc_type=self._meta.es_type_name,
id=self.pk,
# refresh=True,
refresh=True,
body={
"doc": payload
}
Expand All @@ -175,15 +172,10 @@ def delete(self, *args, **kwargs):
self.delete_from_elasticsearch(pk)

def delete_from_elasticsearch(self, pk):
"""
Calling create() or update() with refresh as arg causes TypeError: got an unexpected keyword argument 'refresh',
at least in a unit test, so it's commented out
"""

es = es_settings.ES_CLIENT
es.delete(
index=self._meta.es_index_name,
doc_type=self._meta.es_type_name,
id=pk,
# refresh=True,
)
refresh=True,
)
4 changes: 2 additions & 2 deletions letters/models/place.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.contrib.gis.db import models
from django.contrib.gis.db.models import PointField

DEFAULT_COUNTRY = 'US'

Expand All @@ -9,7 +9,7 @@ class Place(models.Model):
state = models.CharField(max_length=2, blank=True)
country = models.CharField(max_length=2, default=DEFAULT_COUNTRY, blank=True)
# Geo Django field to store a point
point = models.PointField(help_text='Represented as (longitude, latitude)', null=True, blank=True)
point = PointField(help_text='Represented as (longitude, latitude)', null=True, blank=True)
notes = models.TextField(blank=True)

def __str__(self):
Expand Down
10 changes: 0 additions & 10 deletions letters/tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ def test_delete_temp_document(self, mock_delete):
"delete_temp_document() should call ES_CLIENT.delete() with 'id' in kwargs")
self.assertIsNone(result, "delete_temp_document() shouldn't return anything")

#

# def delete_temp_document():
# ES_CLIENT.delete(
# index=Letter._meta.es_index_name,
# doc_type=Letter._meta.es_type_name,
# id='temp',
# refresh=True,
# )



class DoEsAnalyzeTestCase(SimpleTestCase):
Expand Down
6 changes: 3 additions & 3 deletions letters/tests/test_letter.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def test_save(self, mock_create_or_update_in_elasticsearch):
'Letter.save() should call create_or_update_in_elasticsearch(None) on Letter update')

@patch.object(Letter, 'es_repr', autospec=True)
@patch.object(ES_CLIENT, 'create', autospec=True)
@patch.object(ES_CLIENT, 'update', autospec=True)
@patch.object(ES_CLIENT, 'create')
@patch.object(ES_CLIENT, 'update')
def test_create_or_update_in_elasticsearch(self, mock_update, mock_create, mock_es_repr):
"""
If this is a newly-created Letter that hasn't been assigned a pk yet,
Expand Down Expand Up @@ -304,7 +304,7 @@ def test_delete(self, mock_delete_from_elasticsearch):
args, kwargs = mock_delete_from_elasticsearch.call_args
self.assertEqual(args[1], letter_pk, 'Letter.delete() should call delete_from_elasticsearch(letter.pk)')

@patch.object(ES_CLIENT, 'delete', autospec=True)
@patch.object(ES_CLIENT, 'delete')
def test_delete_from_elasticsearch(self, mock_delete):
"""
Letter.delete_from_elasticsearch() should call ES_CLIENT.delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_template_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def test_template_content(self):
rendered = render_to_string(template, context={'pages': ['1', '2']})
self.assertIn('Page navigation', rendered, "'Page navigation' should appear in HTML if page count > 1")
self.assertIn('results found', rendered, "'results found' should appear in HTML if page count > 1")
self.assertIn('search_prev_page()', rendered, "'search_prev_page()' should appear in HTML if page count > 1")
self.assertIn('search_next_page()', rendered, "'search_next_page()' should appear in HTML if page count > 1")
self.assertIn('search_page.prev()', rendered, "'search_page.prev()' should appear in HTML if page count > 1")
self.assertIn('search_page.next()', rendered, "'search_page.next()' should appear in HTML if page count > 1")
self.assertIn('page1', rendered, "'page=<page_num>' should appear in HTML if page count > 1")
self.assertIn('page2', rendered, "'page=<page_num>' should appear in HTML if page count > 1")
self.assertTrue(rendered.count('do_search') == 2,
Expand Down

0 comments on commit 2ee7799

Please sign in to comment.