Beispiel #1
0
def mscolab_start_server(all_ports,
                         mscolab_settings=mscolab_settings,
                         timeout=5):
    handle_db_init()
    port = mscolab_check_free_port(all_ports, all_ports.pop())

    url = f"http://localhost:{port}"

    _app = APP
    _app.config['SQLALCHEMY_DATABASE_URI'] = mscolab_settings.SQLALCHEMY_DB_URI
    _app.config['MSCOLAB_DATA_DIR'] = mscolab_settings.MSCOLAB_DATA_DIR
    _app.config['UPLOAD_FOLDER'] = mscolab_settings.UPLOAD_FOLDER
    _app.config['URL'] = url

    _app, sockio, cm, fm = initialize_managers(_app)

    # ToDo refactoring for spawn needed, fork is not implemented on windows, spawn is default on MAC and Windows
    if multiprocessing.get_start_method(allow_none=True) != 'fork':
        multiprocessing.set_start_method("fork")
    process = multiprocessing.Process(target=start_server,
                                      args=(
                                          _app,
                                          sockio,
                                          cm,
                                          fm,
                                      ),
                                      kwargs={'port': port})
    process.start()
    start_time = time.time()
    while True:
        elapsed_time = (time.time() - start_time)
        if elapsed_time > timeout:
            raise RuntimeError(
                "Failed to start the server after %d seconds. " % timeout)

        if mscolab_ping_server(port):
            break

    return process, url, _app, sockio, cm, fm
Beispiel #2
0
 def setUp(self):
     handle_db_init()
     self.userdata = 'UV10@uv10', 'UV10', 'uv10'
     self.anotheruserdata = 'UV20@uv20', 'UV20', 'uv20'
     socketio, cm, self.fm = setup_managers(self.app)
Beispiel #3
0
 def setUp(self):
     db.init_app(self.app)
     handle_db_init()
     assert Operation.query.all() == []
     assert User.query.all() == []
     assert Permission.query.all() == []