Skip to content

Commit

Permalink
Merge pull request #240 from cogitosys/bugfixes/collection-creation-o…
Browse files Browse the repository at this point in the history
…ptions

Allow collection options to be passed only via kwargs
  • Loading branch information
psi29a committed Nov 21, 2018
2 parents 06b89d2 + f0b257f commit b3357d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/source/NEWS.rst
@@ -1,6 +1,14 @@
Changelog
=========

Release 18.3.0 (UNRELEASED)
---------------------------

Features
^^^^^^^^

- Allow passing only kwargs to `Database.create_collection()`


Release 18.2.0 (2018-07-19)
---------------------------
Expand Down
9 changes: 9 additions & 0 deletions tests/test_collection.py
Expand Up @@ -335,6 +335,15 @@ def tearDown(self):
yield self.conn.drop_database(self.db)
yield self.conn.disconnect()

@defer.inlineCallbacks
def test_WithOptions(self):
coll = yield self.db.create_collection("opttest", capped=True, size=4096)
self.assertTrue(isinstance(coll, Collection))

opts = yield coll.options()
self.assertEqual(opts["capped"], True)
self.assertEqual(opts["size"], 4096)

@defer.inlineCallbacks
def test_Fail(self):
# Not using assertFailure() here because it doesn't wait until deferred is
Expand Down
4 changes: 4 additions & 0 deletions txmongo/database.py
Expand Up @@ -78,6 +78,10 @@ def create_collection(self, name, options=None, write_concern=None,
collection = Collection(self, name, write_concern=write_concern,
codec_options=codec_options)

if options is None and kwargs:
options = kwargs
kwargs = {}

if options:
if "size" in options:
options["size"] = float(options["size"])
Expand Down

0 comments on commit b3357d6

Please sign in to comment.