diff --git a/wagtail/search/tests/test_backends.py b/wagtail/search/tests/test_backends.py index 1da24e90a..551e2da45 100644 --- a/wagtail/search/tests/test_backends.py +++ b/wagtail/search/tests/test_backends.py @@ -402,15 +402,17 @@ class BackendTests(WagtailTestUtils): self.assertSetEqual(results_across_pages, same_rank_objects) def test_delete(self): - # Delete foundation - models.Book.objects.filter(title="Foundation").delete() + foundation = models.Novel.objects.filter(title="Foundation").first() - # Refresh the index - # Note: The delete signal handler should've removed the book, but we still need to refresh the index manually - index = self.backend.get_index_for_model(models.Book) + # Delete from the search index + index = self.backend.get_index_for_model(models.Novel) if index: + index.delete_item(foundation) index.refresh() + # Delete from the database + foundation.delete() + # To test that the book was deleted from the index as well, we will perform the slicing check from an earlier # test where "Foundation" was the first result. We need to test it this way so we can pick up the case where # the object still exists in the index but not in the database (in that case, just two objects would be returned @@ -423,9 +425,10 @@ class BackendTests(WagtailTestUtils): results = results[:3] self.assertEqual(list(r.title for r in results), [ + # "Foundation" "The Hobbit", "The Two Towers", - "The Fellowship of the Ring" + "The Fellowship of the Ring" # If this item doesn't appear, "Foundation" is still in the index ]) diff --git a/wagtail/search/tests/test_elasticsearch2_backend.py b/wagtail/search/tests/test_elasticsearch2_backend.py index c127ada9c..ce8aa78e3 100644 --- a/wagtail/search/tests/test_elasticsearch2_backend.py +++ b/wagtail/search/tests/test_elasticsearch2_backend.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import datetime import json -import unittest import mock from django.db.models import Q @@ -19,11 +18,6 @@ from .test_backends import BackendTests class TestElasticsearch2SearchBackend(BackendTests, ElasticsearchCommonSearchBackendTests, TestCase): backend_path = 'wagtail.search.backends.elasticsearch2' - # Broken - @unittest.expectedFailure - def test_delete(self): - super(TestElasticsearch2SearchBackend, self).test_delete() - class TestElasticsearch2SearchQuery(TestCase): def assertDictEqual(self, a, b): diff --git a/wagtail/search/tests/test_elasticsearch5_backend.py b/wagtail/search/tests/test_elasticsearch5_backend.py index 205f50d13..f32aa7f8e 100644 --- a/wagtail/search/tests/test_elasticsearch5_backend.py +++ b/wagtail/search/tests/test_elasticsearch5_backend.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import datetime import json -import unittest import mock from django.db.models import Q @@ -18,11 +17,6 @@ from .test_backends import BackendTests class TestElasticsearch5SearchBackend(BackendTests, ElasticsearchCommonSearchBackendTests, TestCase): backend_path = 'wagtail.search.backends.elasticsearch5' - # Broken - @unittest.expectedFailure - def test_delete(self): - super(TestElasticsearch5SearchBackend, self).test_delete() - class TestElasticsearch5SearchQuery(TestCase): def assertDictEqual(self, a, b):