summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Holley <willholley@gmail.com>2017-09-11 11:41:05 +0100
committergarren smith <garren.smith@gmail.com>2017-09-11 12:41:05 +0200
commitaa14e5d67650e5a484d5f4d862e17718b5b643eb (patch)
treeb22a238123a9028a45b2ae20ef0979bd977d4ee5
parent1091b5a3866be3e7cca8e21f4a289ac421a44958 (diff)
downloadcouchdb-aa14e5d67650e5a484d5f4d862e17718b5b643eb.tar.gz
Query operator tests for multiple index types (#800)
* add operator tests for text indexes * add operator tests for _all_docs * add tests for null and range handling Tests consistent behaviour for handling null values and range queries between different index types (_all_docs, json indexes and text indexes).
-rw-r--r--src/mango/test/03-operator-test.py72
-rw-r--r--src/mango/test/mango.py11
-rw-r--r--src/mango/test/user_docs.py28
3 files changed, 97 insertions, 14 deletions
diff --git a/src/mango/test/03-operator-test.py b/src/mango/test/03-operator-test.py
index 76e00ccbe..863752682 100644
--- a/src/mango/test/03-operator-test.py
+++ b/src/mango/test/03-operator-test.py
@@ -11,15 +11,15 @@
# the License.
import mango
+import unittest
-
-class OperatorTests(mango.UserDocsTests):
+class OperatorTests:
def assertUserIds(self, user_ids, docs):
user_ids_returned = list(d["user_id"] for d in docs)
user_ids.sort()
user_ids_returned.sort()
- self.assertEqual(user_ids_returned, user_ids)
+ self.assertEqual(user_ids, user_ids_returned)
def test_all(self):
docs = self.db.find({
@@ -174,7 +174,16 @@ class OperatorTests(mango.UserDocsTests):
for d in docs:
self.assertIn("twitter", d)
- def test_range_includes_null_but_not_missing(self):
+ def test_lt_includes_null_but_not_missing(self):
+ docs = self.db.find({
+ "twitter": {"$lt": 1}
+ })
+ user_ids = [9]
+ self.assertUserIds(user_ids, docs)
+ for d in docs:
+ self.assertEqual(d["twitter"], None)
+
+ def test_lte_includes_null_but_not_missing(self):
docs = self.db.find({
"twitter": {"$lt": 1}
})
@@ -183,6 +192,27 @@ class OperatorTests(mango.UserDocsTests):
for d in docs:
self.assertEqual(d["twitter"], None)
+ def test_lte_null_includes_null_but_not_missing(self):
+ docs = self.db.find({
+ "twitter": {"$lte": None}
+ })
+ user_ids = [9]
+ self.assertUserIds(user_ids, docs)
+ for d in docs:
+ self.assertEqual(d["twitter"], None)
+
+ def test_lte_at_z_except_null_excludes_null_and_missing(self):
+ docs = self.db.find({
+ "twitter": {"$and": [
+ {"$lte": "@z"},
+ {"$ne": None}
+ ]}
+ })
+ user_ids = [0,1,4,13]
+ self.assertUserIds(user_ids, docs)
+ for d in docs:
+ self.assertNotEqual(d["twitter"], None)
+
def test_range_gte_null_includes_null_but_not_missing(self):
docs = self.db.find({
"twitter": {"$gte": None}
@@ -198,3 +228,37 @@ class OperatorTests(mango.UserDocsTests):
self.assertGreater(len(docs), 0)
for d in docs:
self.assertNotIn("twitter", d)
+
+ @unittest.skipUnless(not mango.has_text_service(),
+ "text indexes do not support range queries across type boundaries")
+ def test_lte_respsects_unicode_collation(self):
+ docs = self.db.find({
+ "ordered": {"$lte": "a"}
+ })
+ user_ids = [7,8,9,10,11,12]
+ self.assertUserIds(user_ids, docs)
+
+ @unittest.skipUnless(not mango.has_text_service(),
+ "text indexes do not support range queries across type boundaries")
+ def test_gte_respsects_unicode_collation(self):
+ docs = self.db.find({
+ "ordered": {"$gte": "a"}
+ })
+ user_ids = [12,13,14]
+ self.assertUserIds(user_ids, docs)
+
+
+
+class OperatorJSONTests(mango.UserDocsTests, OperatorTests):
+ pass
+
+
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
+class OperatorTextTests(mango.UserDocsTextTests, OperatorTests):
+ pass
+
+
+class OperatorAllDocsTests(mango.UserDocsTestsNoIndexes, OperatorTests):
+ pass
+
+
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index dbe980e29..69b3649ee 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -226,6 +226,17 @@ class UserDocsTests(DbPerClass):
user_docs.setup(klass.db)
+class UserDocsTestsNoIndexes(DbPerClass):
+
+ @classmethod
+ def setUpClass(klass):
+ super(UserDocsTestsNoIndexes, klass).setUpClass()
+ user_docs.setup(
+ klass.db,
+ index_type="_all_docs"
+ )
+
+
class UserDocsTextTests(DbPerClass):
DEFAULT_FIELD = None
diff --git a/src/mango/test/user_docs.py b/src/mango/test/user_docs.py
index 01105e2f0..9896e5596 100644
--- a/src/mango/test/user_docs.py
+++ b/src/mango/test/user_docs.py
@@ -83,7 +83,8 @@ def add_view_indexes(db, kwargs):
["manager"],
["favorites"],
["favorites.3"],
- ["twitter"]
+ ["twitter"],
+ ["ordered"]
]
for idx in indexes:
assert db.create_index(idx) is True
@@ -310,8 +311,8 @@ DOCS = [
"Ruby",
"Erlang"
],
- "exists_field" : "should_exist1"
-
+ "exists_field" : "should_exist1",
+ "ordered": None
},
{
"_id": "6c0afcf1-e57e-421d-a03d-0c0717ebf843",
@@ -333,7 +334,8 @@ DOCS = [
"email": "jamesmcdaniel@globoil.com",
"manager": True,
"favorites": None,
- "exists_field" : "should_exist2"
+ "exists_field" : "should_exist2",
+ "ordered": False
},
{
"_id": "954272af-d5ed-4039-a5eb-8ed57e9def01",
@@ -361,7 +363,8 @@ DOCS = [
"Python"
],
"exists_array" : ["should", "exist", "array1"],
- "complex_field_value" : "+-(){}[]^~&&*||\"\\/?:!"
+ "complex_field_value" : "+-(){}[]^~&&*||\"\\/?:!",
+ "ordered": True
},
{
"_id": "e900001d-bc48-48a6-9b1a-ac9a1f5d1a03",
@@ -386,7 +389,8 @@ DOCS = [
"Erlang",
"Erlang"
],
- "exists_array" : ["should", "exist", "array2"]
+ "exists_array" : ["should", "exist", "array2"],
+ "ordered": 9
},
{
"_id": "b06aadcf-cd0f-4ca6-9f7e-2c993e48d4c4",
@@ -414,7 +418,8 @@ DOCS = [
"C++",
"C++"
],
- "exists_object" : {"should": "object"}
+ "exists_object" : {"should": "object"},
+ "ordered": 10000
},
{
"_id": "5b61abc1-a3d3-4092-b9d7-ced90e675536",
@@ -440,7 +445,8 @@ DOCS = [
"Python",
"Lisp"
],
- "exists_object" : {"another": "object"}
+ "exists_object" : {"another": "object"},
+ "ordered": "a"
},
{
"_id": "b1e70402-8add-4068-af8f-b4f3d0feb049",
@@ -466,7 +472,8 @@ DOCS = [
"C",
"Ruby",
"Ruby"
- ]
+ ],
+ "ordered": "A"
},
{
"_id": "c78c529f-0b07-4947-90a6-d6b7ca81da62",
@@ -491,7 +498,8 @@ DOCS = [
"Erlang",
"Python",
"Lisp"
- ]
+ ],
+ "ordered": "aa"
}
]