create a collection even if no options are passed to create_collection
This commit is contained in:
parent
6c2944802f
commit
6f29ed27d7
@ -28,7 +28,7 @@ _ONE = "\x01\x00\x00\x00"
|
||||
class Collection(object):
|
||||
"""A Mongo collection.
|
||||
"""
|
||||
def __init__(self, database, name, options={}):
|
||||
def __init__(self, database, name, options=None):
|
||||
"""Get / create a Mongo collection.
|
||||
|
||||
Raises TypeError if name is not an instance of (str, unicode). Raises
|
||||
@ -46,7 +46,7 @@ class Collection(object):
|
||||
if not isinstance(name, types.StringTypes):
|
||||
raise TypeError("name must be an instance of (str, unicode)")
|
||||
|
||||
if not isinstance(options, types.DictType):
|
||||
if not isinstance(options, (types.DictType, types.NoneType)):
|
||||
raise TypeError("options must be an instance of dict")
|
||||
|
||||
if not name or ".." in name:
|
||||
@ -58,7 +58,7 @@ class Collection(object):
|
||||
|
||||
self.__database = database
|
||||
self.__collection_name = unicode(name)
|
||||
if options:
|
||||
if options is not None:
|
||||
self.__create(options)
|
||||
|
||||
def __create(self, options):
|
||||
|
||||
@ -67,7 +67,6 @@ class TestDatabase(unittest.TestCase):
|
||||
self.assertRaises(TypeError, db.create_collection, None)
|
||||
self.assertRaises(InvalidName, db.create_collection, "coll..ection")
|
||||
self.assertRaises(TypeError, db.create_collection, "test", 5)
|
||||
self.assertRaises(TypeError, db.create_collection, "test", None)
|
||||
|
||||
test = db.create_collection("test")
|
||||
test.save({"hello": u"world"})
|
||||
@ -76,9 +75,9 @@ class TestDatabase(unittest.TestCase):
|
||||
|
||||
db.drop_collection("test.foo")
|
||||
db.create_collection("test.foo")
|
||||
self.assertFalse(u"test.foo" in db.collection_names())
|
||||
db.create_collection("test.foo", {"capped": True})
|
||||
self.assertTrue(u"test.foo" in db.collection_names())
|
||||
self.assertEqual(db.test.foo.options(), {})
|
||||
self.assertRaises(CollectionInvalid, db.create_collection, "test.foo")
|
||||
|
||||
def test_collection_names(self):
|
||||
db = Database(self.connection, "pymongo_test")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user