Added option MONGO_DOCUMENT_CLASS #19

Closed
wants to merge 4 commits into
from

Projects

None yet

2 participants

@jeverling
Contributor

Pymongo can be instructed to return custom document classes, instead of dicts.
More information here:

http://api.mongodb.org/python/current/api/pymongo/connection.html#pymongo.connection.Connection.document_class
http://dirolf.com/2010/06/17/pymongo-1.7-released.html

This makes it easy to add functionality to the objects that are returned by Pymongo.

@dcrosta
Owner
dcrosta commented Dec 21, 2012

Awesome, great idea. Would you mind adding a test case?

@jeverling
Contributor

Not at all, will do so later this evening. :)

On Fri, Dec 21, 2012 at 2:11 PM, Dan Crosta notifications@github.comwrote:

Awesome, great idea. Would you mind adding a test case?


Reply to this email directly or view it on GitHubhttps://github.com/dcrosta/flask-pymongo/pull/19#issuecomment-11612209.

@jeverling
Contributor

Tests added. I thought a while about where the tests belong, and decided in the end to put the tests into test_config.py.
Since I also wanted to test retrieval of a real object from the DB, and this was neither possible with FlaskRequestTest nor with FlaskPyMongoTest (due to self.mongo being already set up), I just used a second DB connection, and didn't bother to overwrite setUp/tearDown or something along the lines.
It seemed to be the most straightforward way to do it, YMMV.

By the way, apparently FlaskPyMongoTest.setUp/tearDown doesn't work as expected.
It sets self.dbname to self.class.name, and tries to drop this db. However, the DBNAME that is used should be 'test' if I'm not mistaken, since self.mongo is set up with the default configuration (self.app.name).

@jeverling
Contributor

I realized that it's no very good idea to drop the DB 'test', because that's a name that is quite likely to be already used.
I reverted to self.dbname = self.class.name, and added a line that sets this to self.app.config['MONGO_DBNAME'].
This way, 'CollectionTest' and 'CustomDocumentClassTest' are dropped, not 'test'.

@dcrosta dcrosta closed this in 464c971 Dec 22, 2012
@dcrosta
Owner
dcrosta commented Dec 22, 2012

Awesome, thanks! Yeah, the "test" database is created by default in MongoDB, so it's probably best neither to use it for testing modules like this, nor to delete it.

Released version 0.2.1 with this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment