Allow fields to be a set (#347)
Add test cases for set and tuple projection arguments.
This commit is contained in:
parent
1a784e1afb
commit
077fb2041a
@ -235,7 +235,7 @@ def _fields_list_to_dict(fields, option_name):
|
||||
if isinstance(fields, collections.Mapping):
|
||||
return fields
|
||||
|
||||
if isinstance(fields, collections.Sequence):
|
||||
if isinstance(fields, (collections.Sequence, collections.Set)):
|
||||
if not all(isinstance(field, string_type) for field in fields):
|
||||
raise TypeError("%s must be a list of key names, each an "
|
||||
"instance of %s" % (option_name,
|
||||
|
||||
@ -1743,6 +1743,16 @@ class TestCollection(IntegrationTest):
|
||||
|
||||
self.assertTrue("hello" in db.test.find_one(projection=["hello"]))
|
||||
self.assertTrue("hello" not in db.test.find_one(projection=["foo"]))
|
||||
|
||||
self.assertTrue("hello" in db.test.find_one(projection=("hello",)))
|
||||
self.assertTrue("hello" not in db.test.find_one(projection=("foo",)))
|
||||
|
||||
self.assertTrue("hello" in db.test.find_one(projection=set(["hello"])))
|
||||
self.assertTrue("hello" not in db.test.find_one(projection=set(["foo"])))
|
||||
|
||||
self.assertTrue("hello" in db.test.find_one(projection=frozenset(["hello"])))
|
||||
self.assertTrue("hello" not in db.test.find_one(projection=frozenset(["foo"])))
|
||||
|
||||
self.assertEqual(["_id"], list(db.test.find_one(projection=[])))
|
||||
|
||||
self.assertEqual(None, db.test.find_one({"hello": "foo"}))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user