I am trying to unit test my RESTful API. Here is my API:
class BaseHandler(tornado.web.RequestHandler): def __init__(self, *args, **kwargs): tornado.web.RequestHandler.__init__(self, *args, **kwargs) self.log = self.application.log self.db = self.application.db class ProductHandler(BaseHandler): @tornado.web.removeslash def put(self, id = None, *args, **kwargs): try: self.log.info("Handling PUT request") if not id: raise Exception('Object Id Required') id = { '_id' : id } new_values = dict() name = self.get_argument('name', None) description = self.get_argument('description', None) if name: new_values['name'] = name if description: new_values['description'] = description self.db.products.update(id, new_values, safe = True) except: self.log.error("".join(tb.format_exception(*sys.exc_info()))) raise class Application(tornado.web.Application): def __init__(self, config_path, test = False, *args, **kwargs): handlers = [ (r"/product/?(.*)", ProductHandler), ] settings = dict(debug=True) tornado.web.Application.__init__(self, handlers, **settings) self.log = logging.getLogger(__name__) self.config = ConfigParser() self.config.read(config_path) self.mongo_connection = Connection( host = self.config.get('mongo','host'), port = self.config.getint('mongo','port'), ) if test: db_name = self.config.get('test', 'mongo.db') else: db_name = self.config.get('mongo', 'db') self.log.debug("Using db: %s" % db_name) self.db = self.mongo_connection[db_name]
But here is my problem: the handler does not see the arguments of the name or description. :(
Any suggestions?
source share