Re:Flask 0.7 Released (Python Web Framework)
by viandante on Tuesday June 28, 2011 @11:41AM
(#2705804)
I take the occasion to ask here if someone could point or write some documentation on unittest in Flask. I am trying to get that right using mongodb...
[ Parent
| on HN ]
Re:Flask 0.7 Released (Python Web Framework)
by johnpaulett on Tuesday June 28, 2011 @11:47AM
(#2705828)
http://flask.pocoo.org/docs/testing/
For testing a MongoDB database, I wrote a simple unittest.TestCase subclass that in the setUp and tearDown, creates and then deletes a test database.
Re:Flask 0.7 Released (Python Web Framework)
by viandante on Tuesday June 28, 2011 @11:48AM
(#2705838)
Could you put an example on pastebin or somewhere? I would really appreciate this.
Re:Flask 0.7 Released (Python Web Framework)
by johnpaulett on Tuesday June 28, 2011 @12:26PM
(#2706002)
Along the lines of http://flask.pocoo.org/docs/patterns/mongokit/, I have a MONGODB_DATABASE setting, which is set to my normal database name. Then access the database via the connections' dictionary syntax, instead of attribute syntax (I have a helper method to make this prettier):
connection[app.config['MONGODB_DATABASE']].mycollection.find_one()
The unittest code just modifies the setting: import unittest
def setUp(self):
myapp.app.config['MONGODB_DATABASE'] = 'test'
self.app = myapp.app.test_client()
def tearDown(self):
# can clean up here, e.g.
connection.test.drop_collection('mycollection')