Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option MONGO_DOCUMENT_CLASS #19

Closed
wants to merge 4 commits into from

Conversation

jeverling
Copy link
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
Copy link
Owner

dcrosta commented Dec 21, 2012

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

@jeverling
Copy link
Contributor Author

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//pull/19#issuecomment-11612209.

@jeverling
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants