summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2018-12-19 11:48:45 -0600
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-01-18 12:35:38 -0600
commit234a9637552ef78f40350ac03bbd13fbd3c6fc07 (patch)
treeb3ffca8394f48a161e4928902175b1af132b8998
parentfe6849f5caaafc0a21fc8b4e97b898baffe94817 (diff)
downloadcouchdb-234a9637552ef78f40350ac03bbd13fbd3c6fc07.tar.gz
Use index names when testing index selection
Using the internal hash values for indexes was a brittle approach to ensuring that a specific index was or was not picked. By naming the index and design docs we can more concretely ensure that the chosen indexes match the intent of the test while also not breaking each time mango internals change.
-rw-r--r--src/mango/test/05-index-selection-test.py20
-rw-r--r--src/mango/test/user_docs.py37
2 files changed, 28 insertions, 29 deletions
diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py
index e7ea329c6..3f7fb9f21 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -37,8 +37,7 @@ class IndexSelectionTests:
self.assertEqual(resp["index"]["type"], "json")
def test_with_or(self):
- # index on ["company","manager"]
- ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+ ddocid = "_design/company_and_manager"
resp = self.db.find(
{
@@ -50,8 +49,7 @@ class IndexSelectionTests:
self.assertEqual(resp["index"]["ddoc"], ddocid)
def test_use_most_columns(self):
- # ddoc id for the age index
- ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f"
+ ddocid = "_design/age"
resp = self.db.find(
{
"name.first": "Stephanie",
@@ -60,7 +58,7 @@ class IndexSelectionTests:
},
explain=True,
)
- self.assertNotEqual(resp["index"]["ddoc"], "_design/" + ddocid)
+ self.assertNotEqual(resp["index"]["ddoc"], ddocid)
resp = self.db.find(
{
@@ -83,7 +81,7 @@ class IndexSelectionTests:
def test_invalid_use_index(self):
# ddoc id for the age index
- ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f"
+ ddocid = "_design/age"
r = self.db.find({}, use_index=ddocid, return_raw=True)
self.assertEqual(
r["warning"],
@@ -105,8 +103,7 @@ class IndexSelectionTests:
self.assertEqual(resp_explain["index"]["type"], "json")
def test_reject_use_index_invalid_fields(self):
- # index on ["company","manager"] which should not be valid
- ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+ ddocid = "_design/company_and_manager"
selector = {"company": "Pharmex"}
r = self.db.find(selector, use_index=ddocid, return_raw=True)
self.assertEqual(
@@ -121,9 +118,8 @@ class IndexSelectionTests:
self.assertEqual(d["company"], "Pharmex")
def test_reject_use_index_ddoc_and_name_invalid_fields(self):
- # index on ["company","manager"] which should not be valid
- ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
- name = "a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+ ddocid = "_design/company_and_manager"
+ name = "company_and_manager"
selector = {"company": "Pharmex"}
resp = self.db.find(selector, use_index=[ddocid, name], return_raw=True)
@@ -141,7 +137,7 @@ class IndexSelectionTests:
def test_reject_use_index_sort_order(self):
# index on ["company","manager"] which should not be valid
# and there is no valid fallback (i.e. an index on ["company"])
- ddocid = "_design/a0c425a60cf3c3c09e3c537c9ef20059dcef9198"
+ ddocid = "_design/company_and_manager"
selector = {"company": {"$gt": None}}
try:
self.db.find(selector, use_index=ddocid, sort=[{"company": "desc"}])
diff --git a/src/mango/test/user_docs.py b/src/mango/test/user_docs.py
index afbea710e..e0495353b 100644
--- a/src/mango/test/user_docs.py
+++ b/src/mango/test/user_docs.py
@@ -70,24 +70,27 @@ def setup(db, index_type="view", **kwargs):
def add_view_indexes(db, kwargs):
indexes = [
- ["user_id"],
- ["name.last", "name.first"],
- ["age"],
- [
- "location.state",
- "location.city",
- "location.address.street",
- "location.address.number",
- ],
- ["company", "manager"],
- ["manager"],
- ["favorites"],
- ["favorites.3"],
- ["twitter"],
- ["ordered"],
+ (["user_id"], "user_id"),
+ (["name.last", "name.first"], "name"),
+ (["age"], "age"),
+ (
+ [
+ "location.state",
+ "location.city",
+ "location.address.street",
+ "location.address.number",
+ ],
+ "location",
+ ),
+ (["company", "manager"], "company_and_manager"),
+ (["manager"], "manager"),
+ (["favorites"], "favorites"),
+ (["favorites.3"], "favorites_3"),
+ (["twitter"], "twitter"),
+ (["ordered"], "ordered"),
]
- for idx in indexes:
- assert db.create_index(idx) is True
+ for (idx, name) in indexes:
+ assert db.create_index(idx, name=name, ddoc=name) is True
def add_text_indexes(db, kwargs):