Today I spent some time chasing ghosts and a missing textarea value in my POST data. All form elements were posted correctly but the textarea was missing. I am using the WYMeditor for the textarea to turn the element into a rich text field. The textarea was missing from the POST data because it has it's style attribute set to display:none. This is something that the class="wymeditor" attribute does to the textarea. The important bit is the submit button which also needs a class attribute. Something I had missed when copying from the demo page for the WYMeditor. After giving the submit button a class="wymupdate" everything works just fine.
Currently I am working on a web application which is based on the Tornado web framework. After reading this excellent blog post I felt motivated to be a bit more strict about TDD with Python. Similar to the code form Tomas, my tornado.web.Application is receiving a peer object in it's init method. The peer is a DAO object wrapping access to a MongoDB database called MongoDbDao. To access MongoDB I am using the PyMongo distribution which heavily uses pymongo.cursor.Cursor objects. These Cursor objects are then returned from my MongoDbDao. Maybe thats not the greatest idea as it leaks out some implementation details from the DAO class. But Cursors itself are nice, so I decided to always return a pymongo.cursor.Cursor.
This however was a bit annoying in unit tests. These tests are not executed against a real database, I am mocking the MongoDbDao instead. When using a pymongo.cursor.Cursor, the only thing I am doing in production code is iteration over the results or checking if there were any results using the count function. So here is what I came up with for the unit test.
This is basically a UserList that has the count function of the pymongo.cursor.Cursor added to it (not really using the with_limit_and_skip argument at the moment). I found this to be easier than creating a stub with Mockito every time I want to return a Cursor that can be iterated or checked for it's size.
This however was a bit annoying in unit tests. These tests are not executed against a real database, I am mocking the MongoDbDao instead. When using a pymongo.cursor.Cursor, the only thing I am doing in production code is iteration over the results or checking if there were any results using the count function. So here is what I came up with for the unit test.
This is basically a UserList that has the count function of the pymongo.cursor.Cursor added to it (not really using the with_limit_and_skip argument at the moment). I found this to be easier than creating a stub with Mockito every time I want to return a Cursor that can be iterated or checked for it's size.
Subscribe to:
Posts (Atom)