Skip to content

Commit 52e9d89

Browse files
committed
Fix Mango text index tests
The text index tests are not routinely run by the Couch CI (due to an external dependency that isn't shipped with Couch). This fixes a number of tests that were broken as a result of recent feature changes.
1 parent 687ff88 commit 52e9d89

4 files changed

+22
-23
lines changed

src/mango/test/05-index-selection-test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,13 @@ def test_uses_all_docs_when_selector_doesnt_require_fields_to_exist(self):
181181

182182

183183
@unittest.skipUnless(mango.has_text_service(), "requires text service")
184-
class TextIndexSelectionTests(mango.UserDocsTests, IndexSelectionTests):
184+
class TextIndexSelectionTests(mango.UserDocsTests):
185185

186186
@classmethod
187187
def setUpClass(klass):
188188
super(TextIndexSelectionTests, klass).setUpClass()
189-
190-
def setUp(self):
191-
self.db.recreate()
192-
user_docs.add_text_indexes(self.db, {})
189+
if mango.has_text_service():
190+
user_docs.add_text_indexes(klass.db, {})
193191

194192
def test_with_text(self):
195193
resp = self.db.find({

src/mango/test/06-basic-text-test.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,14 @@ def test_elem_match_non_object(self):
450450
}
451451
}
452452
docs = self.db.find(q)
453-
assert len(docs) == 1
454-
assert docs[0]["bestfriends"] == ["Wolverine", "Cyclops"]
453+
self.assertEqual(len(docs), 1)
454+
self.assertEqual(docs[0]["bestfriends"], ["Wolverine", "Cyclops"])
455455

456456
q = {"results": {"$elemMatch": {"$gte": 80, "$lt": 85}}}
457457

458458
docs = self.db.find(q)
459-
assert len(docs) == 1
460-
assert docs[0]["results"] == [82, 85, 88]
459+
self.assertEqual(len(docs), 1)
460+
self.assertEqual(docs[0]["results"], [82, 85, 88])
461461

462462
def test_elem_match(self):
463463
q = {"friends": {
@@ -466,9 +466,9 @@ def test_elem_match(self):
466466
}
467467
}
468468
docs = self.db.find(q)
469-
assert len(docs) == 2
469+
self.assertEqual(len(docs), 2)
470470
for d in docs:
471-
assert d["user_id"] in (0, 1)
471+
self.assertIn(d["user_id"], (0, 1))
472472

473473
q = {
474474
"friends": {
@@ -479,8 +479,8 @@ def test_elem_match(self):
479479
}
480480
}
481481
docs = self.db.find(q)
482-
assert len(docs) == 1
483-
assert docs[0]["user_id"] == 4
482+
self.assertEqual(len(docs), 1)
483+
self.assertEqual(docs[0]["user_id"], 4)
484484

485485

486486
# Check that we can do logic in elemMatch
@@ -490,8 +490,9 @@ def test_elem_match(self):
490490
}}
491491
}
492492
docs = self.db.find(q)
493-
assert len(docs) == 1
494-
assert docs[0]["user_id"] == 1
493+
self.assertEqual(len(docs), 2)
494+
for d in docs:
495+
self.assertIn(d["user_id"], (1, 15))
495496

496497
q = {
497498
"friends": {
@@ -505,9 +506,9 @@ def test_elem_match(self):
505506
}
506507
}
507508
docs = self.db.find(q)
508-
assert len(docs) == 2
509+
self.assertEqual(len(docs), 3)
509510
for d in docs:
510-
assert d["user_id"] in (1, 4)
511+
self.assertIn(d["user_id"], (1, 4, 15))
511512

512513
# Same as last, but using $in
513514
q = {
@@ -519,9 +520,9 @@ def test_elem_match(self):
519520
}
520521
}
521522
docs = self.db.find(q)
522-
assert len(docs) == 2
523+
self.assertEqual(len(docs), 3)
523524
for d in docs:
524-
assert d["user_id"] in (1, 4)
525+
self.assertIn(d["user_id"], (1, 4, 15))
525526

526527
q = {
527528
"$and": [{
@@ -564,9 +565,9 @@ def test_elem_match(self):
564565
]
565566
}
566567
docs = self.db.find(q)
567-
assert len(docs) == 3
568+
self.assertEqual(len(docs), 3)
568569
for d in docs:
569-
assert d["user_id"] in (10, 11,12)
570+
self.assertIn(d["user_id"], (10, 11,12))
570571

571572
@unittest.skipUnless(mango.has_text_service(), "requires text service")
572573
class AllMatchTests(mango.FriendDocsTextTests):

src/mango/test/10-disable-array-length-field-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@unittest.skipUnless(mango.has_text_service(), "requires text service")
1717
class DisableIndexArrayLengthsTest(mango.UserDocsTextTests):
1818

19-
def setUp(klass):
19+
def setUp(self):
2020
self.db.recreate()
2121
self.db.create_text_index(ddoc="disable_index_array_lengths",
2222
analyzer="keyword",

src/mango/test/16-index-selectors-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,6 @@ def test_text_old_selector_still_supported(self):
273273

274274
@unittest.skipUnless(mango.has_text_service(), "requires text service")
275275
def test_text_partial_filter_only_in_return_if_not_default(self):
276-
self.db.create_text_index(fields=[{"name":"location"}])
276+
self.db.create_text_index(fields=[{"name":"location", "type":"string"}])
277277
index = self.db.list_indexes()[1]
278278
self.assertEqual('partial_filter_selector' in index['def'], False)

0 commit comments

Comments
 (0)