summaryrefslogtreecommitdiff
path: root/src/mango/test/16-index-selectors-test.py
diff options
context:
space:
mode:
authorJoan Touzet <wohali@users.noreply.github.com>2018-12-06 18:03:57 -0500
committerGitHub <noreply@github.com>2018-12-06 18:03:57 -0500
commit33d4f6d02715a204ef2dd7ddc4795aed5c1b72ce (patch)
tree3c3bb3ca489922e4bf2f595b12dee80d3ff5fd5d /src/mango/test/16-index-selectors-test.py
parent25e9e7759223ecccbcb87ac34d4a9d8c56db31ab (diff)
downloadcouchdb-33d4f6d02715a204ef2dd7ddc4795aed5c1b72ce.tar.gz
Format and check all code using python black (#1776)
The Makefile target builds a python3 venv at .venv and installs black if possible. Since black is Python 3.6 and up only, we skip the check on systems with an older Python 3.x.
Diffstat (limited to 'src/mango/test/16-index-selectors-test.py')
-rw-r--r--src/mango/test/16-index-selectors-test.py229
1 files changed, 103 insertions, 126 deletions
diff --git a/src/mango/test/16-index-selectors-test.py b/src/mango/test/16-index-selectors-test.py
index a876dc68f..4510065f5 100644
--- a/src/mango/test/16-index-selectors-test.py
+++ b/src/mango/test/16-index-selectors-test.py
@@ -15,62 +15,20 @@ import mango
import unittest
DOCS = [
- {
- "_id": "100",
- "name": "Jimi",
- "location": "AUS",
- "user_id": 1,
- "same": "value"
- },
- {
- "_id": "200",
- "name": "Eddie",
- "location": "BRA",
- "user_id": 2,
- "same": "value"
- },
- {
- "_id": "300",
- "name": "Harry",
- "location": "CAN",
- "user_id":3,
- "same": "value"
- },
- {
- "_id": "400",
- "name": "Eddie",
- "location": "DEN",
- "user_id":4,
- "same": "value"
- },
- {
- "_id": "500",
- "name": "Jones",
- "location": "ETH",
- "user_id":5,
- "same": "value"
- },
+ {"_id": "100", "name": "Jimi", "location": "AUS", "user_id": 1, "same": "value"},
+ {"_id": "200", "name": "Eddie", "location": "BRA", "user_id": 2, "same": "value"},
+ {"_id": "300", "name": "Harry", "location": "CAN", "user_id": 3, "same": "value"},
+ {"_id": "400", "name": "Eddie", "location": "DEN", "user_id": 4, "same": "value"},
+ {"_id": "500", "name": "Jones", "location": "ETH", "user_id": 5, "same": "value"},
{
"_id": "600",
"name": "Winnifried",
"location": "FRA",
- "user_id":6,
- "same": "value"
- },
- {
- "_id": "700",
- "name": "Marilyn",
- "location": "GHA",
- "user_id":7,
- "same": "value"
- },
- {
- "_id": "800",
- "name": "Sandra",
- "location": "ZAR",
- "user_id":8,
- "same": "value"
+ "user_id": 6,
+ "same": "value",
},
+ {"_id": "700", "name": "Marilyn", "location": "GHA", "user_id": 7, "same": "value"},
+ {"_id": "800", "name": "Sandra", "location": "ZAR", "user_id": 8, "same": "value"},
]
oldschoolnoselectorddoc = {
@@ -78,21 +36,11 @@ oldschoolnoselectorddoc = {
"language": "query",
"views": {
"oldschoolnoselector": {
- "map": {
- "fields": {
- "location": "asc"
- }
- },
+ "map": {"fields": {"location": "asc"}},
"reduce": "_count",
- "options": {
- "def": {
- "fields": [
- "location"
- ]
- }
- }
+ "options": {"def": {"fields": ["location"]}},
}
- }
+ },
}
oldschoolddoc = {
@@ -101,23 +49,13 @@ oldschoolddoc = {
"views": {
"oldschool": {
"map": {
- "fields": {
- "location": "asc"
- },
- "selector": {
- "location": {"$gte": "FRA"}
- }
+ "fields": {"location": "asc"},
+ "selector": {"location": {"$gte": "FRA"}},
},
"reduce": "_count",
- "options": {
- "def": {
- "fields": [
- "location"
- ]
- }
- }
+ "options": {"def": {"fields": ["location"]}},
}
- }
+ },
}
oldschoolddoctext = {
@@ -128,28 +66,20 @@ oldschoolddoctext = {
"index": {
"default_analyzer": "keyword",
"default_field": {},
- "selector": {
- "location": {"$gte": "FRA"}
- },
- "fields": [
- {
- "name": "location",
- "type": "string"
- }
- ],
- "index_array_lengths": True
- },
+ "selector": {"location": {"$gte": "FRA"}},
+ "fields": [{"name": "location", "type": "string"}],
+ "index_array_lengths": True,
+ },
"analyzer": {
"name": "perfield",
"default": "keyword",
- "fields": {
- "$default": "standard"
- }
- }
+ "fields": {"$default": "standard"},
+ },
}
- }
+ },
}
+
class IndexSelectorJson(mango.DbPerClass):
def setUp(self):
self.db.recreate()
@@ -164,7 +94,7 @@ class IndexSelectorJson(mango.DbPerClass):
def test_partial_filter_only_in_return_if_not_default(self):
self.db.create_index(["location"])
index = self.db.list_indexes()[1]
- self.assertEqual('partial_filter_selector' in index['def'], False)
+ self.assertEqual("partial_filter_selector" in index["def"], False)
def test_saves_selector_in_index_throws(self):
selector = {"location": {"$gte": "FRA"}}
@@ -177,30 +107,50 @@ class IndexSelectorJson(mango.DbPerClass):
def test_uses_partial_index_for_query_selector(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_index(["location"], partial_filter_selector=selector, ddoc="Selected", name="Selected")
- resp = self.db.find(selector, explain=True, use_index='Selected')
+ self.db.create_index(
+ ["location"],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
+ resp = self.db.find(selector, explain=True, use_index="Selected")
self.assertEqual(resp["index"]["name"], "Selected")
- docs = self.db.find(selector, use_index='Selected')
+ docs = self.db.find(selector, use_index="Selected")
self.assertEqual(len(docs), 3)
def test_uses_partial_index_with_different_selector(self):
selector = {"location": {"$gte": "FRA"}}
selector2 = {"location": {"$gte": "A"}}
- self.db.create_index(["location"], partial_filter_selector=selector, ddoc="Selected", name="Selected")
- resp = self.db.find(selector2, explain=True, use_index='Selected')
+ self.db.create_index(
+ ["location"],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
+ resp = self.db.find(selector2, explain=True, use_index="Selected")
self.assertEqual(resp["index"]["name"], "Selected")
- docs = self.db.find(selector2, use_index='Selected')
+ docs = self.db.find(selector2, use_index="Selected")
self.assertEqual(len(docs), 3)
def test_doesnot_use_selector_when_not_specified(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_index(["location"], partial_filter_selector=selector, ddoc="Selected", name="Selected")
+ self.db.create_index(
+ ["location"],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
resp = self.db.find(selector, explain=True)
self.assertEqual(resp["index"]["name"], "_all_docs")
def test_doesnot_use_selector_when_not_specified_with_index(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_index(["location"], partial_filter_selector=selector, ddoc="Selected", name="Selected")
+ self.db.create_index(
+ ["location"],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
self.db.create_index(["location"], name="NotSelected")
resp = self.db.find(selector, explain=True)
self.assertEqual(resp["index"]["name"], "NotSelected")
@@ -208,57 +158,82 @@ class IndexSelectorJson(mango.DbPerClass):
def test_old_selector_with_no_selector_still_supported(self):
selector = {"location": {"$gte": "FRA"}}
self.db.save_doc(oldschoolnoselectorddoc)
- resp = self.db.find(selector, explain=True, use_index='oldschoolnoselector')
+ resp = self.db.find(selector, explain=True, use_index="oldschoolnoselector")
self.assertEqual(resp["index"]["name"], "oldschoolnoselector")
- docs = self.db.find(selector, use_index='oldschoolnoselector')
+ docs = self.db.find(selector, use_index="oldschoolnoselector")
self.assertEqual(len(docs), 3)
def test_old_selector_still_supported(self):
selector = {"location": {"$gte": "FRA"}}
self.db.save_doc(oldschoolddoc)
- resp = self.db.find(selector, explain=True, use_index='oldschool')
+ resp = self.db.find(selector, explain=True, use_index="oldschool")
self.assertEqual(resp["index"]["name"], "oldschool")
- docs = self.db.find(selector, use_index='oldschool')
+ docs = self.db.find(selector, use_index="oldschool")
self.assertEqual(len(docs), 3)
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_saves_partialfilterselector_in_index(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}], partial_filter_selector=selector)
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}],
+ partial_filter_selector=selector,
+ )
indexes = self.db.list_indexes()
self.assertEqual(indexes[1]["def"]["partial_filter_selector"], selector)
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_uses_partial_index_for_query_selector(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}], partial_filter_selector=selector, ddoc="Selected", name="Selected")
- resp = self.db.find(selector, explain=True, use_index='Selected')
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
+ resp = self.db.find(selector, explain=True, use_index="Selected")
self.assertEqual(resp["index"]["name"], "Selected")
- docs = self.db.find(selector, use_index='Selected', fields=['_id', 'location'])
+ docs = self.db.find(selector, use_index="Selected", fields=["_id", "location"])
self.assertEqual(len(docs), 3)
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_uses_partial_index_with_different_selector(self):
selector = {"location": {"$gte": "FRA"}}
selector2 = {"location": {"$gte": "A"}}
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}], partial_filter_selector=selector, ddoc="Selected", name="Selected")
- resp = self.db.find(selector2, explain=True, use_index='Selected')
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
+ resp = self.db.find(selector2, explain=True, use_index="Selected")
self.assertEqual(resp["index"]["name"], "Selected")
- docs = self.db.find(selector2, use_index='Selected')
+ docs = self.db.find(selector2, use_index="Selected")
self.assertEqual(len(docs), 3)
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_doesnot_use_selector_when_not_specified(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}], partial_filter_selector=selector, ddoc="Selected", name="Selected")
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
resp = self.db.find(selector, explain=True)
self.assertEqual(resp["index"]["name"], "_all_docs")
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_doesnot_use_selector_when_not_specified_with_index(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}], partial_filter_selector=selector, ddoc="Selected", name="Selected")
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}], name="NotSelected")
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}],
+ partial_filter_selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}], name="NotSelected"
+ )
resp = self.db.find(selector, explain=True)
self.assertEqual(resp["index"]["name"], "NotSelected")
@@ -266,23 +241,25 @@ class IndexSelectorJson(mango.DbPerClass):
def test_text_old_selector_still_supported(self):
selector = {"location": {"$gte": "FRA"}}
self.db.save_doc(oldschoolddoctext)
- resp = self.db.find(selector, explain=True, use_index='oldschooltext')
+ resp = self.db.find(selector, explain=True, use_index="oldschooltext")
self.assertEqual(resp["index"]["name"], "oldschooltext")
- docs = self.db.find(selector, use_index='oldschooltext')
+ docs = self.db.find(selector, use_index="oldschooltext")
self.assertEqual(len(docs), 3)
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_old_selector_still_supported_via_api(self):
selector = {"location": {"$gte": "FRA"}}
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}],
- selector=selector,
- ddoc="Selected",
- name="Selected")
- docs = self.db.find({"location": {"$exists":True}}, use_index='Selected')
+ self.db.create_text_index(
+ fields=[{"name": "location", "type": "string"}],
+ selector=selector,
+ ddoc="Selected",
+ name="Selected",
+ )
+ docs = self.db.find({"location": {"$exists": True}}, use_index="Selected")
self.assertEqual(len(docs), 3)
@unittest.skipUnless(mango.has_text_service(), "requires text service")
def test_text_partial_filter_only_in_return_if_not_default(self):
- self.db.create_text_index(fields=[{"name":"location", "type":"string"}])
+ self.db.create_text_index(fields=[{"name": "location", "type": "string"}])
index = self.db.list_indexes()[1]
- self.assertEqual('partial_filter_selector' in index['def'], False)
+ self.assertEqual("partial_filter_selector" in index["def"], False)