diff --git a/letters/models/letter.py b/letters/models/letter.py index 10dcb61..f507c48 100644 --- a/letters/models/letter.py +++ b/letters/models/letter.py @@ -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 @@ -155,7 +152,7 @@ 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: @@ -163,7 +160,7 @@ 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={ "doc": payload } @@ -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, - ) \ No newline at end of file + refresh=True, + ) diff --git a/letters/models/place.py b/letters/models/place.py index a2c0bfb..8a02ba6 100644 --- a/letters/models/place.py +++ b/letters/models/place.py @@ -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' @@ -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): diff --git a/letters/tests/test_elasticsearch.py b/letters/tests/test_elasticsearch.py index 4ef15d9..3935632 100644 --- a/letters/tests/test_elasticsearch.py +++ b/letters/tests/test_elasticsearch.py @@ -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): diff --git a/letters/tests/test_letter.py b/letters/tests/test_letter.py index 9c4a7df..2dd4c38 100644 --- a/letters/tests/test_letter.py +++ b/letters/tests/test_letter.py @@ -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, @@ -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() diff --git a/tests/test_template_snippets.py b/tests/test_template_snippets.py index 35858d7..b509487 100644 --- a/tests/test_template_snippets.py +++ b/tests/test_template_snippets.py @@ -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=' should appear in HTML if page count > 1") self.assertIn('page2', rendered, "'page=' should appear in HTML if page count > 1") self.assertTrue(rendered.count('do_search') == 2,