Skip to content

Commit

Permalink
Merge branch 'master' into filelock-management-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajslater committed Feb 7, 2022
2 parents f47e444 + 515651f commit e7bd12e
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions tests/xapian_tests/tests/test_management_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import random
import sys
from io import StringIO
from unittest import TestCase
Expand All @@ -24,12 +23,9 @@ def setUp(self):

for i in range(1, self.NUM_BLOG_ENTRIES + 1):
entry = BackendFeaturesTestCase.get_entry(i)
entry.float_number = random.uniform(0.0, 1000.0)
self.sample_objs.append(entry)
entry.save()

self.backend.update(self.index, BlogEntry.objects.all())

def verify_indexed_document_count(self, expected):
count = self.backend.document_count()
self.assertEqual(count, expected)
Expand All @@ -51,10 +47,47 @@ def verify_indexed_documents(self):

self.assertSetEqual(pks, doc_ids)

def test_multiprocessing(self):
def test_clear(self):
self.backend.update(self.index, BlogEntry.objects.all())
self.verify_indexed_documents()

call_command("clear_index", interactive=False, verbosity=0)
self.verify_indexed_document_count(0)

def test_update(self):
self.verify_indexed_document_count(0)

call_command("update_index", verbosity=0)
self.verify_indexed_documents()

def test_rebuild(self):
self.verify_indexed_document_count(0)

call_command("rebuild_index", interactive=False, verbosity=0)
self.verify_indexed_documents()

def test_remove(self):
self.verify_indexed_document_count(0)

call_command("update_index", verbosity=0)
self.verify_indexed_documents()

# Remove three instances.
three_pks = BlogEntry.objects.all()[:3].values_list("pk", flat=True)
BlogEntry.objects.filter(pk__in=three_pks).delete()
self.verify_indexed_document_count(self.NUM_BLOG_ENTRIES)

# Plain ``update_index`` doesn't fix it.
call_command("update_index", verbosity=0)
self.verify_indexed_document_count(self.NUM_BLOG_ENTRIES)

# … but remove does:
call_command("update_index", remove=True, verbosity=0)
self.verify_indexed_document_count(self.NUM_BLOG_ENTRIES - 3)

def test_multiprocessing(self):
self.verify_indexed_document_count(0)

old_stderr = sys.stderr
sys.stderr = StringIO()
call_command(
Expand Down

0 comments on commit e7bd12e

Please sign in to comment.