Skip to content

Commit 7ca0dd6

Browse files
author
Cosimo Streppone
committed
GH#151: delete(id=<list>) assumed no parent/child docs
Rearrange the multiple-id delete() test code according to the new default document test set. Chose to filter out the parent/child documents from this specific part of the test, under the assumption that Solr will behave correctly whether the id to be deleted belongs to a leaf, parent, child or grandchild document. The test code should be generic enough to not need modifications when the document test set (self.docs) is expanded.
1 parent 11380c0 commit 7ca0dd6

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tests/test_client.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,26 +655,35 @@ def test_delete(self):
655655
self.solr.delete(q='*:*')
656656
self.assertEqual(len(self.solr.search('*:*')), 0)
657657

658-
# Try delete with a list of document ids
659-
self.solr.add(self.docs)
658+
# Test delete() with `id' being a list.
659+
# Solr's ability to delete parent/children docs by id is simply assumed
660+
# and not what's under test here.
661+
def leaf_doc(doc):
662+
return 'price' in doc and NESTED_DOC_KEY not in doc
663+
664+
to_delete_docs = filter(leaf_doc, self.docs)
665+
to_delete_ids = [doc['id'] for doc in to_delete_docs]
666+
667+
self.solr.add(to_delete_docs)
660668
self.solr.commit()
661-
self.assertEqual(len(self.solr.search('*:*')), len(self.docs))
662-
to_delete = [doc['id'] for doc in self.docs]
663-
# Extract a random document from the list, to later check it wasn't deleted
664-
graced_doc_id = to_delete.pop(random.randint(0, len(to_delete) - 1))
665-
self.solr.delete(id=to_delete)
669+
670+
leaf_q = 'price:[* TO *]'
671+
self.assertEqual(len(self.solr.search(leaf_q)), len(to_delete_docs))
672+
# Extract a random doc from the list, to later check it wasn't deleted.
673+
graced_doc_id = to_delete_ids.pop(random.randint(0, len(to_delete_ids) - 1))
674+
self.solr.delete(id=to_delete_ids)
666675
# There should be only one left, our graced id
667-
self.assertEqual(len(self.solr.search('*:*')), 1)
676+
self.assertEqual(len(self.solr.search(leaf_q)), 1)
668677
self.assertEqual(len(self.solr.search('id:%s' % graced_doc_id)), 1)
669678
# Now we can wipe the graced document too. None should be left.
670679
self.solr.delete(id=graced_doc_id)
671-
self.assertEqual(len(self.solr.search('*:*')), 0)
680+
self.assertEqual(len(self.solr.search(leaf_q)), 0)
672681

673682
# Can't delete when the list of documents is empty
674683
self.assertRaises(ValueError, self.solr.delete, id=[None, None, None])
675684
self.assertRaises(ValueError, self.solr.delete, id=[None])
676685

677-
# Need at least one.
686+
# Need at least one of either `id' or `q'
678687
self.assertRaises(ValueError, self.solr.delete)
679688
# Can't have both.
680689
self.assertRaises(ValueError, self.solr.delete, id='foo', q='bar')

0 commit comments

Comments
 (0)