diff --git a/src/mango/test/01-index-crud-test.py b/src/mango/test/01-index-crud-test.py index 617bfd5235d..cf5b918650a 100644 --- a/src/mango/test/01-index-crud-test.py +++ b/src/mango/test/01-index-crud-test.py @@ -36,7 +36,7 @@ def test_bad_fields(self): try: self.db.create_index(fields) except Exception as e: - assert e.response.status_code == 400 + self.assertEqual(e.response.status_code, 400) else: raise AssertionError("bad create index") @@ -55,7 +55,7 @@ def test_bad_types(self): try: self.db.create_index(["foo"], idx_type=bt) except Exception as e: - assert e.response.status_code == 400, (bt, e.response.status_code) + self.assertEqual(e.response.status_code, 400, (bt, e.response.status_code)) else: raise AssertionError("bad create index") @@ -71,13 +71,13 @@ def test_bad_names(self): try: self.db.create_index(["foo"], name=bn) except Exception as e: - assert e.response.status_code == 400 + self.assertEqual(e.response.status_code, 400) else: raise AssertionError("bad create index") try: self.db.create_index(["foo"], ddoc=bn) except Exception as e: - assert e.response.status_code == 400 + self.assertEqual(e.response.status_code, 400) else: raise AssertionError("bad create index") @@ -88,7 +88,7 @@ def test_create_idx_01(self): for idx in self.db.list_indexes(): if idx["name"] != "idx_01": continue - assert idx["def"]["fields"] == [{"foo": "asc"}, {"bar": "asc"}] + self.assertEqual(idx["def"]["fields"], [{"foo": "asc"}, {"bar": "asc"}]) return raise AssertionError("index not created") @@ -106,7 +106,7 @@ def test_create_idx_02(self): for idx in self.db.list_indexes(): if idx["name"] != "idx_02": continue - assert idx["def"]["fields"] == [{"baz": "asc"}, {"foo": "asc"}] + self.assertEqual(idx["def"]["fields"], [{"baz": "asc"}, {"foo": "asc"}]) return raise AssertionError("index not created") @@ -118,9 +118,9 @@ def test_read_idx_doc(self): continue ddocid = idx["ddoc"] doc = self.db.open_doc(ddocid) - assert doc["_id"] == ddocid + self.assertEqual(doc["_id"], ddocid) info = self.db.ddoc_info(ddocid) - assert info["name"] == ddocid.split('_design/')[-1] + self.assertEqual(info["name"], ddocid.split('_design/')[-1]) def test_delete_idx_escaped(self): self.db.create_index(["foo", "bar"], name="idx_01") @@ -130,10 +130,10 @@ def test_delete_idx_escaped(self): for idx in self.db.list_indexes(): if idx["name"] != "idx_del_1": continue - assert idx["def"]["fields"] == [{"bing": "asc"}] + self.assertEqual(idx["def"]["fields"], [{"bing": "asc"}]) self.db.delete_index(idx["ddoc"].replace("/", "%2F"), idx["name"]) post_indexes = self.db.list_indexes() - assert pre_indexes == post_indexes + self.assertEqual(pre_indexes, post_indexes) def test_delete_idx_unescaped(self): pre_indexes = self.db.list_indexes() @@ -142,10 +142,10 @@ def test_delete_idx_unescaped(self): for idx in self.db.list_indexes(): if idx["name"] != "idx_del_2": continue - assert idx["def"]["fields"] == [{"bing": "asc"}] + self.assertEqual(idx["def"]["fields"], [{"bing": "asc"}]) self.db.delete_index(idx["ddoc"], idx["name"]) post_indexes = self.db.list_indexes() - assert pre_indexes == post_indexes + self.assertEqual(pre_indexes, post_indexes) def test_delete_idx_no_design(self): pre_indexes = self.db.list_indexes() @@ -154,10 +154,10 @@ def test_delete_idx_no_design(self): for idx in self.db.list_indexes(): if idx["name"] != "idx_del_3": continue - assert idx["def"]["fields"] == [{"bing": "asc"}] + self.assertEqual(idx["def"]["fields"], [{"bing": "asc"}]) self.db.delete_index(idx["ddoc"].split("/")[-1], idx["name"]) post_indexes = self.db.list_indexes() - assert pre_indexes == post_indexes + self.assertEqual(pre_indexes, post_indexes) def test_bulk_delete(self): fields = ["field1"] @@ -182,8 +182,8 @@ def test_bulk_delete(self): ret = self.db.bulk_delete(docids) - assert ret["fail"][0]["id"] == "_design/this_is_not_an_index_name" - assert len(ret["success"]) == 3 + self.assertEqual(ret["fail"][0]["id"], "_design/this_is_not_an_index_name") + self.assertEqual(len(ret["success"]), 3) for idx in self.db.list_indexes(): assert idx["type"] != "json" @@ -197,18 +197,18 @@ def test_recreate_index(self): for idx in self.db.list_indexes(): if idx["name"] != "idx_recreate": continue - assert idx["def"]["fields"] == [{"bing": "asc"}] + self.assertEqual(idx["def"]["fields"], [{"bing": "asc"}]) self.db.delete_index(idx["ddoc"], idx["name"]) break post_indexes = self.db.list_indexes() - assert pre_indexes == post_indexes + self.assertEqual(pre_indexes, post_indexes) - def test_delete_misisng(self): + def test_delete_missing(self): # Missing design doc try: self.db.delete_index("this_is_not_a_design_doc_id", "foo") except Exception as e: - assert e.response.status_code == 404 + self.assertEqual(e.response.status_code, 404) else: raise AssertionError("bad index delete") @@ -221,7 +221,7 @@ def test_delete_misisng(self): try: self.db.delete_index(ddocid, "this_is_not_an_index_name") except Exception as e: - assert e.response.status_code == 404 + self.assertEqual(e.response.status_code, 404) else: raise AssertionError("bad index delete") @@ -229,11 +229,54 @@ def test_delete_misisng(self): try: self.db.delete_index(ddocid, idx["name"], idx_type="not_a_real_type") except Exception as e: - assert e.response.status_code == 404 + self.assertEqual(e.response.status_code, 404) else: raise AssertionError("bad index delete") - @unittest.skipUnless(mango.has_text_service(), "requires text service") + def test_limit_skip_index(self): + fields = ["field1"] + ret = self.db.create_index(fields, name="idx_01") + assert ret is True + + fields = ["field2"] + ret = self.db.create_index(fields, name="idx_02") + assert ret is True + + fields = ["field3"] + ret = self.db.create_index(fields, name="idx_03") + assert ret is True + + fields = ["field4"] + ret = self.db.create_index(fields, name="idx_04") + assert ret is True + + fields = ["field5"] + ret = self.db.create_index(fields, name="idx_05") + assert ret is True + + self.assertEqual(len(self.db.list_indexes(limit=2)), 2) + self.assertEqual(len(self.db.list_indexes(limit=5,skip=4)), 2) + self.assertEqual(len(self.db.list_indexes(skip=5)), 1) + self.assertEqual(len(self.db.list_indexes(skip=6)), 0) + self.assertEqual(len(self.db.list_indexes(skip=100)), 0) + self.assertEqual(len(self.db.list_indexes(limit=10000000)), 6) + + try: + self.db.list_indexes(skip=-1) + except Exception as e: + self.assertEqual(e.response.status_code, 500) + + try: + self.db.list_indexes(limit=0) + except Exception as e: + self.assertEqual(e.response.status_code, 500) + + +@unittest.skipUnless(mango.has_text_service(), "requires text service") +class IndexCrudTextTests(mango.DbPerClass): + def setUp(self): + self.db.recreate() + def test_create_text_idx(self): fields = [ {"name":"stringidx", "type" : "string"}, @@ -244,14 +287,13 @@ def test_create_text_idx(self): for idx in self.db.list_indexes(): if idx["name"] != "text_idx_01": continue - assert idx["def"]["fields"] == [ + self.assertEqual(idx["def"]["fields"], [ {"stringidx": "string"}, {"booleanidx": "boolean"} - ] + ]) return raise AssertionError("index not created") - @unittest.skipUnless(mango.has_text_service(), "requires text service") def test_create_bad_text_idx(self): bad_fields = [ True, @@ -270,10 +312,10 @@ def test_create_bad_text_idx(self): try: self.db.create_text_index(fields=fields) except Exception as e: - assert e.response.status_code == 400 + self.assertEqual(e.response.status_code, 400) else: raise AssertionError("bad create text index") - + def test_limit_skip_index(self): fields = ["field1"] ret = self.db.create_index(fields, name="idx_01") @@ -291,28 +333,26 @@ def test_limit_skip_index(self): ret = self.db.create_index(fields, name="idx_04") assert ret is True - fields = ["field5"] - ret = self.db.create_index(fields, name="idx_05") + fields = [ + {"name":"stringidx", "type" : "string"}, + {"name":"booleanidx", "type": "boolean"} + ] + ret = self.db.create_text_index(fields=fields, name="idx_05") assert ret is True - skip_add = 0 - - if mango.has_text_service(): - skip_add = 1 - - assert len(self.db.list_indexes(limit=2)) == 2 - assert len(self.db.list_indexes(limit=5,skip=4)) == 2 + skip_add - assert len(self.db.list_indexes(skip=5)) == 1 + skip_add - assert len(self.db.list_indexes(skip=6)) == 0 + skip_add - assert len(self.db.list_indexes(skip=100)) == 0 - assert len(self.db.list_indexes(limit=10000000)) == 6 + skip_add + self.assertEqual(len(self.db.list_indexes(limit=2)), 2) + self.assertEqual(len(self.db.list_indexes(limit=5,skip=4)), 2) + self.assertEqual(len(self.db.list_indexes(skip=5)), 1) + self.assertEqual(len(self.db.list_indexes(skip=6)), 0) + self.assertEqual(len(self.db.list_indexes(skip=100)), 0) + self.assertEqual(len(self.db.list_indexes(limit=10000000)), 6) try: self.db.list_indexes(skip=-1) except Exception as e: - assert e.response.status_code == 500 + self.assertEqual(e.response.status_code, 500) try: self.db.list_indexes(limit=0) except Exception as e: - assert e.response.status_code == 500 + self.assertEqual(e.response.status_code, 500) diff --git a/src/mango/test/03-operator-test.py b/src/mango/test/03-operator-test.py index 1af39f2051d..239cc7d416a 100644 --- a/src/mango/test/03-operator-test.py +++ b/src/mango/test/03-operator-test.py @@ -174,6 +174,9 @@ def test_ne_includes_null_but_not_missing(self): for d in docs: self.assertIn("twitter", d) + # ideally this work be consistent across index types but, alas, it is not + @unittest.skipUnless(not mango.has_text_service(), + "text indexes do not support range queries across type boundaries") def test_lt_includes_null_but_not_missing(self): docs = self.db.find({ "twitter": {"$lt": 1} @@ -183,6 +186,8 @@ def test_lt_includes_null_but_not_missing(self): for d in docs: self.assertEqual(d["twitter"], None) + @unittest.skipUnless(not mango.has_text_service(), + "text indexes do not support range queries across type boundaries") def test_lte_includes_null_but_not_missing(self): docs = self.db.find({ "twitter": {"$lt": 1} diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py index 1cc21038206..05571a7e8c3 100644 --- a/src/mango/test/05-index-selection-test.py +++ b/src/mango/test/05-index-selection-test.py @@ -15,12 +15,7 @@ import unittest -class IndexSelectionTests(mango.UserDocsTests): - @classmethod - def setUpClass(klass): - super(IndexSelectionTests, klass).setUpClass() - if mango.has_text_service(): - user_docs.add_text_indexes(klass.db, {}) +class IndexSelectionTests: def test_basic(self): resp = self.db.find({"age": 123}, explain=True) @@ -33,30 +28,6 @@ def test_with_and(self): }, explain=True) self.assertEqual(resp["index"]["type"], "json") - @unittest.skipUnless(mango.has_text_service(), "requires text service") - def test_with_text(self): - resp = self.db.find({ - "$text" : "Stephanie", - "name.first": "Stephanie", - "name.last": "This doesn't have to match anything." - }, explain=True) - self.assertEqual(resp["index"]["type"], "text") - - @unittest.skipUnless(mango.has_text_service(), "requires text service") - def test_no_view_index(self): - resp = self.db.find({"name.first": "Ohai!"}, explain=True) - self.assertEqual(resp["index"]["type"], "text") - - @unittest.skipUnless(mango.has_text_service(), "requires text service") - def test_with_or(self): - resp = self.db.find({ - "$or": [ - {"name.first": "Stephanie"}, - {"name.last": "This doesn't have to match anything."} - ] - }, explain=True) - self.assertEqual(resp["index"]["type"], "text") - def test_use_most_columns(self): # ddoc id for the age index ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f" @@ -92,36 +63,6 @@ def test_invalid_use_index(self): else: raise AssertionError("bad find") - def test_uses_all_docs_when_fields_do_not_match_selector(self): - # index exists on ["company", "manager"] but not ["company"] - # so we should fall back to all docs (so we include docs - # with no "manager" field) - selector = { - "company": "Pharmex" - } - docs = self.db.find(selector) - self.assertEqual(len(docs), 1) - self.assertEqual(docs[0]["company"], "Pharmex") - self.assertNotIn("manager", docs[0]) - - resp_explain = self.db.find(selector, explain=True) - self.assertEqual(resp_explain["index"]["type"], "special") - - def test_uses_all_docs_when_selector_doesnt_require_fields_to_exist(self): - # as in test above, use a selector that doesn't overlap with the index - # due to an explicit exists clause - selector = { - "company": "Pharmex", - "manager": {"$exists": False} - } - docs = self.db.find(selector) - self.assertEqual(len(docs), 1) - self.assertEqual(docs[0]["company"], "Pharmex") - self.assertNotIn("manager", docs[0]) - - resp_explain = self.db.find(selector, explain=True) - self.assertEqual(resp_explain["index"]["type"], "special") - def test_uses_index_when_no_range_or_equals(self): # index on ["manager"] should be valid because # selector requires "manager" to exist. The @@ -200,7 +141,77 @@ def test_manual_bad_view_idx01(self): with self.assertRaises(KeyError): self.db.save_doc(design_doc) - @unittest.skipUnless(mango.has_text_service(), "requires text service") + +class JSONIndexSelectionTests(mango.UserDocsTests, IndexSelectionTests): + + @classmethod + def setUpClass(klass): + super(JSONIndexSelectionTests, klass).setUpClass() + + def test_uses_all_docs_when_fields_do_not_match_selector(self): + # index exists on ["company", "manager"] but not ["company"] + # so we should fall back to all docs (so we include docs + # with no "manager" field) + selector = { + "company": "Pharmex" + } + docs = self.db.find(selector) + self.assertEqual(len(docs), 1) + self.assertEqual(docs[0]["company"], "Pharmex") + self.assertNotIn("manager", docs[0]) + + resp_explain = self.db.find(selector, explain=True) + + self.assertEqual(resp_explain["index"]["type"], "special") + + def test_uses_all_docs_when_selector_doesnt_require_fields_to_exist(self): + # as in test above, use a selector that doesn't overlap with the index + # due to an explicit exists clause + selector = { + "company": "Pharmex", + "manager": {"$exists": False} + } + docs = self.db.find(selector) + self.assertEqual(len(docs), 1) + self.assertEqual(docs[0]["company"], "Pharmex") + self.assertNotIn("manager", docs[0]) + + resp_explain = self.db.find(selector, explain=True) + self.assertEqual(resp_explain["index"]["type"], "special") + + +@unittest.skipUnless(mango.has_text_service(), "requires text service") +class TextIndexSelectionTests(mango.UserDocsTests, IndexSelectionTests): + + @classmethod + def setUpClass(klass): + super(TextIndexSelectionTests, klass).setUpClass() + + def setUp(self): + self.db.recreate() + user_docs.add_text_indexes(self.db, {}) + + def test_with_text(self): + resp = self.db.find({ + "$text" : "Stephanie", + "name.first": "Stephanie", + "name.last": "This doesn't have to match anything." + }, explain=True) + self.assertEqual(resp["index"]["type"], "text") + + def test_no_view_index(self): + resp = self.db.find({"name.first": "Ohai!"}, explain=True) + self.assertEqual(resp["index"]["type"], "text") + + def test_with_or(self): + resp = self.db.find({ + "$or": [ + {"name.first": "Stephanie"}, + {"name.last": "This doesn't have to match anything."} + ] + }, explain=True) + self.assertEqual(resp["index"]["type"], "text") + def test_manual_bad_text_idx(self): design_doc = { "_id": "_design/bad_text_index", @@ -243,8 +254,8 @@ def setUpClass(klass): klass.db.create_text_index(ddoc="foo", analyzer="keyword") klass.db.create_text_index(ddoc="bar", analyzer="email") - def test_view_ok_with_multi_text(self): - resp = self.db.find({"name.last": "A last name"}, explain=True) + def test_fallback_to_json_with_multi_text(self): + resp = self.db.find({"name.first": "A first name", "name.last": "A last name"}, explain=True) self.assertEqual(resp["index"]["type"], "json") def test_multi_text_index_is_error(self): diff --git a/src/mango/test/09-text-sort-test.py b/src/mango/test/09-text-sort-test.py index 1c55572274f..a1a644c7959 100644 --- a/src/mango/test/09-text-sort-test.py +++ b/src/mango/test/09-text-sort-test.py @@ -19,60 +19,60 @@ class SortTests(mango.UserDocsTextTests): def test_number_sort(self): q = {"age": {"$gt": 0}} docs = self.db.find(q, sort=["age:number"]) - assert len(docs) == 15 - assert docs[0]["age"] == 22 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["age"], 22) def test_number_sort_desc(self): q = {"age": {"$gt": 0}} docs = self.db.find(q, sort=[{"age": "desc"}]) - assert len(docs) == 15 - assert docs[0]["age"] == 79 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["age"], 79) q = {"manager": True} docs = self.db.find(q, sort=[{"age:number": "desc"}]) - assert len(docs) == 11 - assert docs[0]["age"] == 79 + self.assertEqual(len(docs), 10) + self.assertEqual(docs[0]["age"], 79) def test_string_sort(self): q = {"email": {"$gt": None}} docs = self.db.find(q, sort=["email:string"]) - assert len(docs) == 15 - assert docs[0]["email"] == "abbottwatson@talkola.com" + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["email"], "abbottwatson@talkola.com") def test_notype_sort(self): q = {"email": {"$gt": None}} try: self.db.find(q, sort=["email"]) except Exception as e: - assert e.response.status_code == 400 + self.assertEqual(e.response.status_code, 400) else: raise AssertionError("Should have thrown error for sort") def test_array_sort(self): q = {"favorites": {"$exists": True}} docs = self.db.find(q, sort=["favorites.[]:string"]) - assert len(docs) == 15 - assert docs[0]["user_id"] == 8 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["user_id"], 8) def test_multi_sort(self): q = {"name": {"$exists": True}} docs = self.db.find(q, sort=["name.last:string", "age:number"]) - assert len(docs) == 15 - assert docs[0]["name"] == {"last":"Ewing","first":"Shelly"} - assert docs[1]["age"] == 22 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["name"], {"last":"Ewing","first":"Shelly"}) + self.assertEqual(docs[1]["age"], 22) def test_guess_type_sort(self): q = {"$or": [{"age":{"$gt": 0}}, {"email": {"$gt": None}}]} docs = self.db.find(q, sort=["age"]) - assert len(docs) == 15 - assert docs[0]["age"] == 22 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["age"], 22) def test_guess_dup_type_sort(self): q = {"$and": [{"age":{"$gt": 0}}, {"email": {"$gt": None}}, {"age":{"$lte": 100}}]} docs = self.db.find(q, sort=["age"]) - assert len(docs) == 15 - assert docs[0]["age"] == 22 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["age"], 22) def test_ambiguous_type_sort(self): q = {"$or": [{"age":{"$gt": 0}}, {"email": {"$gt": None}}, @@ -80,7 +80,7 @@ def test_ambiguous_type_sort(self): try: self.db.find(q, sort=["age"]) except Exception as e: - assert e.response.status_code == 400 + self.assertEqual(e.response.status_code, 400) else: raise AssertionError("Should have thrown error for sort") @@ -88,14 +88,14 @@ def test_guess_multi_sort(self): q = {"$or": [{"age":{"$gt": 0}}, {"email": {"$gt": None}}, {"name.last": "Harvey"}]} docs = self.db.find(q, sort=["name.last", "age"]) - assert len(docs) == 15 - assert docs[0]["name"] == {"last":"Ewing","first":"Shelly"} - assert docs[1]["age"] == 22 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["name"], {"last":"Ewing","first":"Shelly"}) + self.assertEqual(docs[1]["age"], 22) def test_guess_mix_sort(self): q = {"$or": [{"age":{"$gt": 0}}, {"email": {"$gt": None}}, {"name.last": "Harvey"}]} docs = self.db.find(q, sort=["name.last:string", "age"]) - assert len(docs) == 15 - assert docs[0]["name"] == {"last":"Ewing","first":"Shelly"} - assert docs[1]["age"] == 22 + self.assertEqual(len(docs), 15) + self.assertEqual(docs[0]["name"], {"last":"Ewing","first":"Shelly"}) + self.assertEqual(docs[1]["age"], 22) diff --git a/src/mango/test/10-disable-array-length-field-test.py b/src/mango/test/10-disable-array-length-field-test.py index 0715f1db999..ce7713b63b9 100644 --- a/src/mango/test/10-disable-array-length-field-test.py +++ b/src/mango/test/10-disable-array-length-field-test.py @@ -13,28 +13,24 @@ import mango import unittest - +@unittest.skipUnless(mango.has_text_service(), "requires text service") class DisableIndexArrayLengthsTest(mango.UserDocsTextTests): - @classmethod - def setUpClass(klass): - super(DisableIndexArrayLengthsTest, klass).setUpClass() - if mango.has_text_service(): - klass.db.create_text_index(ddoc="disable_index_array_lengths", + def setUp(klass): + self.db.recreate() + self.db.create_text_index(ddoc="disable_index_array_lengths", analyzer="keyword", index_array_lengths=False) - klass.db.create_text_index(ddoc="explicit_enable_index_array_lengths", + self.db.create_text_index(ddoc="explicit_enable_index_array_lengths", analyzer="keyword", index_array_lengths=True) - @unittest.skipUnless(mango.has_text_service(), "requires text service") def test_disable_index_array_length(self): docs = self.db.find({"favorites": {"$size": 4}}, use_index="disable_index_array_lengths") for d in docs: assert len(d["favorites"]) == 0 - @unittest.skipUnless(mango.has_text_service(), "requires text service") def test_enable_index_array_length(self): docs = self.db.find({"favorites": {"$size": 4}}, use_index="explicit_enable_index_array_lengths") diff --git a/src/mango/test/11-ignore-design-docs.py b/src/mango/test/11-ignore-design-docs-test.py similarity index 100% rename from src/mango/test/11-ignore-design-docs.py rename to src/mango/test/11-ignore-design-docs-test.py diff --git a/src/mango/test/12-use-correct-index.py b/src/mango/test/12-use-correct-index-test.py similarity index 86% rename from src/mango/test/12-use-correct-index.py rename to src/mango/test/12-use-correct-index-test.py index 84b42534378..5a2b24d3fd1 100644 --- a/src/mango/test/12-use-correct-index.py +++ b/src/mango/test/12-use-correct-index-test.py @@ -68,15 +68,15 @@ def test_choose_index_with_two(self): self.assertEqual(explain["index"]["ddoc"], '_design/bbb') def test_choose_index_alphabetically(self): - self.db.create_index(["name", "age", "user_id"], ddoc="aaa") - self.db.create_index(["name", "age", "location"], ddoc="bbb") + self.db.create_index(["name"], ddoc="aaa") + self.db.create_index(["name"], ddoc="bbb") self.db.create_index(["name"], ddoc="zzz") explain = self.db.find({"name": "Eddie", "age": {"$gte": 12}}, explain=True) self.assertEqual(explain["index"]["ddoc"], '_design/aaa') def test_choose_index_most_accurate(self): - self.db.create_index(["name", "location", "user_id"], ddoc="aaa") - self.db.create_index(["name", "age", "user_id"], ddoc="bbb") + self.db.create_index(["name", "age", "user_id"], ddoc="aaa") + self.db.create_index(["name", "age"], ddoc="bbb") self.db.create_index(["name"], ddoc="zzz") explain = self.db.find({"name": "Eddie", "age": {"$gte": 12}}, explain=True) self.assertEqual(explain["index"]["ddoc"], '_design/bbb') @@ -105,3 +105,12 @@ def test_chooses_idxA(self): self.db.create_index(["a", "d", "e"]) explain = self.db.find({"a": {"$gt": 0}, "b": {"$gt": 0}, "c": {"$gt": 0}}, explain=True) self.assertEqual(explain["index"]["def"]["fields"], [{'a': 'asc'}, {'b': 'asc'}, {'c': 'asc'}]) + + def test_can_query_with_range_on_secondary_column(self): + self.db.create_index(["age", "name"], ddoc="bbb") + selector = {"age": 10, "name": {"$gte": 0}} + docs = self.db.find(selector) + self.assertEqual(len(docs), 1) + explain = self.db.find(selector, explain=True) + self.assertEqual(explain["index"]["ddoc"], "_design/bbb") + self.assertEqual(explain["mrargs"]["end_key"], [10, '']) diff --git a/src/mango/test/14-json-pagination.py b/src/mango/test/14-json-pagination-test.py similarity index 100% rename from src/mango/test/14-json-pagination.py rename to src/mango/test/14-json-pagination-test.py diff --git a/src/mango/test/16-index-selectors.py b/src/mango/test/16-index-selectors-test.py similarity index 100% rename from src/mango/test/16-index-selectors.py rename to src/mango/test/16-index-selectors-test.py diff --git a/src/mango/test/README.md b/src/mango/test/README.md index fc2cd62e58f..3aace39b096 100644 --- a/src/mango/test/README.md +++ b/src/mango/test/README.md @@ -7,6 +7,11 @@ To run these, do this in the Mango top level directory: $ virtualenv venv $ source venv/bin/activate - $ pip install nose requests - $ pip install hypothesis - $ nosetests + $ make pip-install + $ make test + +To run an individual test suite: + nosetests --nocapture test/12-use-correct-index.py + +To run the tests with text index support: + MANGO_TEXT_INDEXES=1 nosetests --nocapture test \ No newline at end of file diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py index a275a23d055..576cec6ebc1 100644 --- a/src/mango/test/mango.py +++ b/src/mango/test/mango.py @@ -27,7 +27,7 @@ def random_db_name(): return "mango_test_" + uuid.uuid4().hex def has_text_service(): - return os.path.isfile(os.getcwd() + "/../src/mango_cursor_text.erl") + return os.environ.get('MANGO_TEXT_INDEXES') == '1' class Database(object):