Example #1
0
 def setup_db_settings(self):
     self.db_file_path = T.testdb.create_temp_db_file()
     T.MockedSettings['db_uri'] = T.testdb.get_temp_db_uri(
         self.db_file_path)
     with mock.patch.dict(db.Settings, T.MockedSettings):
         db.init_db()
         self.populate_database()
Example #2
0
def init_settings():
    try:
        init_db()
    except DbConnectError as e:
        print(e)
    except:
        traceback.print_exc()
Example #3
0
def info_actions(args):
    if args.db_stat:
        show_db_status()
    elif args.check_md5:
        ss = SmugSync()
        ss.show_stat_by_md5()
    elif args.init_db:
        init_db()
 def setup_db(self):
     self.db_file_path = T.testdb.create_temp_db_file()
     T.MockedSettings['db_uri'] = T.testdb.get_temp_db_uri(self.db_file_path)
     with patch.dict(db.Settings, T.MockedSettings):
         db.init_db()
         self.insert_checklists()
         yield
         db.finalize_db()
         os.unlink(self.db_file_path)
Example #5
0
 def setup_db(self):
     self.db_file = T.make_test_db()
     T.MockedSettings['db_uri'] = T.get_temp_db_uri(self.db_file)
     T.MockedSettings['irc'] = {
         "nickname": "pushhamster+test",
         "channel": "pushmanagertest"
     }
     with mock.patch.dict(db.Settings, T.MockedSettings):
         db.init_db()
Example #6
0
 def setup_db(self):
     self.db_file = T.make_test_db()
     T.MockedSettings['db_uri'] = T.get_temp_db_uri(self.db_file)
     T.MockedSettings['irc'] = {
         "nickname": "pushhamster+test",
         "channel": "pushmanagertest"
     }
     with mock.patch.dict(db.Settings, T.MockedSettings):
         db.init_db()
Example #7
0
def main():
    define("port", default=8000, help="run on the given port", type=int)
    tornado.options.parse_command_line()
    config_file_path = './db_use.conf'
    tornado.options.parse_config_file(config_file_path)
    init_db()
    Application().listen(options.port, address='127.0.0.1')
    logging.info("running on 127.0.0.1:%s", options.port)
    tornado.ioloop.IOLoop.instance().start()
Example #8
0
 def setup_db(self):
     self.db_file_path = T.testdb.create_temp_db_file()
     T.MockedSettings['db_uri'] = T.testdb.get_temp_db_uri(self.db_file_path)
     with patch.dict(db.Settings, T.MockedSettings):
         db.init_db()
         self.insert_requests()
         yield
         db.finalize_db()
         os.unlink(self.db_file_path)
def main():
    usage = 'usage: %prog <oldtag> <newtag>'
    parser = OptionParser(usage)
    (_, args) = parser.parse_args()

    if len(args) == 2:
        db.init_db()
        convert_checklist(args[0], args[1])
        db.finalize_db()
    else:
        parser.error('Incorrect number of arguments')
def main():
    usage = 'usage: %prog <oldtag> <newtag>'
    parser = OptionParser(usage)
    (_, args) = parser.parse_args()

    if len(args) == 2:
        db.init_db()
        convert_checklist(args[0], args[1])
        db.finalize_db()
    else:
        parser.error('Incorrect number of arguments')
Example #11
0
    def setup_db(self):
        self.setup_async_test_case()

        self.db_file = T.make_test_db()
        T.MockedSettings["db_uri"] = T.get_temp_db_uri(self.db_file)
        T.MockedSettings["irc"] = {"nickname": "pushhamster+test", "channel": "pushmanagertest"}
        # for the purpose of unittests we'll use a single application
        # for API and main site.
        T.MockedSettings["api_app"] = {"domain": "localhost", "port": self.get_http_port()}

        with mock.patch.dict(db.Settings, T.MockedSettings):
            db.init_db()
Example #12
0
    def setup_db(self):
        self.setup_async_test_case()

        self.db_file = T.make_test_db()
        T.MockedSettings['db_uri'] = T.get_temp_db_uri(self.db_file)
        T.MockedSettings['irc'] = {
            "nickname": "pushhamster+test",
            "channel": "pushmanagertest"
        }
        # for the purpose of unittests we'll use a single application
        # for API and main site.
        T.MockedSettings['api_app'] = {
            "domain": "localhost",
            "port": self.get_http_port()
        }

        with mock.patch.dict(db.Settings, T.MockedSettings):
            db.init_db()
Example #13
0
def init_core_modules(app):
    """Initializes the core modules for the given context.

    It initializes the following plugins/functions in order:
        1). Launguage system
        2). Logger
        3). Flask-JWT-Extended
        4). Flask-SQLAlchemy
        5). HTTP server (testing only)
    
    Args:
        app (flask.app.Flask): A Flask application.

    """
    # Initialize the launguage system.
    init_lang(app)

    # Setup logger
    file_handler = logging.FileHandler('app.log')
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(
        logging.Formatter(app.config.get('LOG_FORMAT', \
            '%(asctime)s %(levelname)s: %(message)s')))
    app.logger.addHandler(file_handler)

    # Setting up flask-JWT
    init_jwt(app)

    # Setup database
    init_db(app)
    with app.app_context():
        db.create_all()

    # Simple HTTP server. Not recommended in production.
    if (app.config.get('ENABLE_SIMPLE_HTTP_SERVER', False)):
        from utils.http_server import init_http_server
        init_http_server(app)
Example #14
0
    def start_services(self):
        # HTTPS server
        sockets = tornado.netutil.bind_sockets(self.port, address=Settings['main_app']['servername'])
        redir_sockets = tornado.netutil.bind_sockets(self.redir_port, address=Settings['main_app']['servername'])
        tornado.process.fork_processes(Settings['tornado']['num_workers'])

        server = tornado.httpserver.HTTPServer(self.main_app, ssl_options={
                'certfile': Settings['main_app']['ssl_certfile'],
                # This really should be read into a string so we can drop privileges
                # after reading the key but before starting the server, but Python
                # doesn't let us use strings for keys until Python 3.2 :(
                'keyfile': Settings['main_app']['ssl_keyfile'],
                })
        server.add_sockets(sockets)

        # HTTP server (to redirect to HTTPS)
        redir_server = tornado.httpserver.HTTPServer(self.redir_app)
        redir_server.add_sockets(redir_sockets)

        # Start the mail, git, reviewboard and XMPP queue handlers
        MailQueue.start_worker()
        GitQueue.start_worker()
        RBQueue.start_worker()
        XMPPQueue.start_worker()

if __name__ == '__main__':
    app = PushManagerApp()
    db.init_db()
    app.run()
Example #15
0
    [
        get_servlet_urlspec(APIServlet),
    ],
    # Server settings
    static_path=os.path.join(os.path.dirname(__file__), "static"),
    template_path=os.path.join(os.path.dirname(__file__), "templates"),
    gzip=True,
    login_url="/login",
    cookie_secret=Settings['cookie_secret'],
    ui_modules=ui_modules,
    autoescape=None,
)


class PushManagerAPIApp(Application):
    name = "api"

    def start_services(self):
        # HTTP server (for api)
        sockets = tornado.netutil.bind_sockets(
            self.port, address=Settings['api_app']['servername'])
        tornado.process.fork_processes(Settings['tornado']['num_workers'])
        server = tornado.httpserver.HTTPServer(api_application)
        server.add_sockets(sockets)


if __name__ == '__main__':
    app = PushManagerAPIApp()
    db.init_db()
    app.run()
Example #16
0
def create_app():
    app = FastAPI()
    init_db(app)
    router_register(app)
    app.mount("/static", StaticFiles(directory="static"), name="static")
    return app
Example #17
0
 def setup_db_settings(self):
     self.db_file_path = T.testdb.create_temp_db_file()
     T.MockedSettings['db_uri'] = T.testdb.get_temp_db_uri(self.db_file_path)
     with mock.patch.dict(db.Settings, T.MockedSettings):
         db.init_db()
         self.populate_database()