Пример #1
0
 def __init__(self):
     debug(True)
     self._db_engine = None
     self._db_session = None
     self._db_session_maker = None
     self.reset_filesystem()
     # Mock Box consists of 3 webservers - one for the content API, one for the upload API, and one for OAuth2
     api, upload, oauth_api, event, oauth_authorize = Bottle(), Bottle(), Bottle(), Bottle(), Bottle()
     app_mapping = {
         self.API_PORT: api,
         self.EVENT_PORT: event,
         self.OAUTH_API_PORT: oauth_api,
         self.UPLOAD_PORT: upload,
         self.OAUTH_AUTHORIZE_PORT: oauth_authorize,
     }
     # Since we don't instantiate the servers until Box is instantiated, we have to apply the routes now
     for routed_method in (getattr(self, m) for m in dir(self) if hasattr(getattr(self, m), 'route')):
         app_port = routed_method.app
         app = app_mapping[app_port]
         app.route(routed_method.route, routed_method.verb, routed_method)
     for code in [400, 401, 404, 409, 429, 500]:
         for app in app_mapping.values():
             app.error(code)(self.handle_error)
     self._api = StoppableWSGIRefServer(host='localhost', port=self.API_PORT).run(api)
     self._upload = StoppableWSGIRefServer(host='localhost', port=self.UPLOAD_PORT).run(upload)
     self._oauth_api = StoppableWSGIRefServer(host='localhost', port=self.OAUTH_API_PORT).run(oauth_api)
     self._event = StoppableWSGIRefServer(host='localhost', port=self.EVENT_PORT).run(event)
     self._oauth_authorize = StoppableWSGIRefServer(host='localhost', port=self.OAUTH_AUTHORIZE_PORT).run(oauth_authorize)
     self._rate_limit_bucket = (self.RATE_LIMIT_THRESHOLD, datetime.utcnow())