Esempio n. 1
0
def app():
    db_fd, db_path = tempfile.mkstemp()
    upload_path = tempfile.mkdtemp()

    DATABASE = db_path
    app = create_app(
        {
            "TESTING": True,
            "SQLALCHEMY_DATABASE_URI": "sqlite:///" + DATABASE,
            "SQLALCHEMY_TRACK_MODIFICATIONS": False,
            "UPLOAD_DIR": upload_path,
        }
    )

    with app.app_context():
        from flaskr.database import init_db, load_test_data

        init_db()
        load_test_data()

    yield app

    os.close(db_fd)
    os.unlink(db_path)
    shutil.rmtree(upload_path)
Esempio n. 2
0
def create_app():
    app = Flask(__name__)
    # configを読み込む
    app.config.from_object('flaskr.config.Config')

    # DBを初期化
    init_db(app)

    # Blueprint
    from flaskr.main.views import main_bp
    from flaskr.main.verification.verifications import verification_bp
    from flaskr.api.v1.api import api_v1_main_bp
    from flaskr.api.v1.slack.api import api_v1_slack_bp
    from flaskr.api.v1.member.api import api_v1_member_bp
    from flaskr.api.v1.calendar.api import api_v1_calendar_bp
    from flaskr.api.v1.gmail.api import api_v1_gmail_bp
    from flaskr.api.v1.zoom.api import api_v1_zoom_bp
    app.register_blueprint(main_bp)
    app.register_blueprint(verification_bp)
    app.register_blueprint(api_v1_main_bp)
    app.register_blueprint(api_v1_slack_bp)
    app.register_blueprint(api_v1_member_bp)
    app.register_blueprint(api_v1_calendar_bp)
    app.register_blueprint(api_v1_gmail_bp)
    app.register_blueprint(api_v1_zoom_bp)

    return app
Esempio n. 3
0
def create_app():
    app = Flask(__name__)
    app.config.from_object('flaskr.config.Config')

    init_db(app)
    CORS(app)
    register_blueprints(app)

    return app
Esempio n. 4
0
def create_app(test_config=None):
    test_config = None
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        #DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    from werkzeug.local import LocalProxy
    from flask import current_app
    logger = LocalProxy(lambda: app.logger)
    logger.debug("create_app")
    logger.info("app.instance_path: " + app.instance_path)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    #from . import db
    #db.init_app(app)
    from flaskr.database import init_db
    from flaskr.database import db_session

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        db_session.remove()

    init_db()

    from . import auth
    app.register_blueprint(auth.bp)

    from . import blog
    app.register_blueprint(blog.bp)
    app.add_url_rule('/', endpoint='index')

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    return app
Esempio n. 5
0
def app():
    db_fd, db_path = tempfile.mkstemp()
    print("db_path: {}".format(db_path))
    app = create_app({
        'TESTING': True,
        'SQLALCHEMY_DATABASE_URI': 'sqlite:///' + db_path,
    })

    db = get_db()
    # Create database and load test data
    # Create a new session for every test.
    with app.app_context():
        init_db()
        yield app
        db.session.remove()
        db.drop_all()

    # Close the db data.
    os.close(db_fd)
    os.unlink(db_path)
Esempio n. 6
0
def create_app(test_config=None):
    """
    Function to create an instance of the app.
    A config can be specified. It uses sql alchemy
    which is stored in the database file.
    """

    # create and configure the app
    app = Flask(__name__, instance_relative_config=True,
                static_folder="../../dist/static",
                template_folder="../../dist")

    if os.environ.get('FLASK_ENV') == 'development':
        # When in development mode, we proxy the local Vue server. This means
        # CSRF Protection is not available. Make sure to test application in
        # production mode as well.
        app.config['WTF_CSRF_CHECK_DEFAULT'] = False

    app.config['WTF_CSRF_CHECK_DEFAULT'] = False

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    app.config['JWT_SECRET_KEY'] = 'very-secure'  # Test value
    app.config['TIKTECH_BASE_URL'] = 'http://*****:*****@app.route('/', defaults={'path': ''})
    @app.route('/<path:path>')
    def render_vue(path):
        if app.debug:
            try:
                res = requests.get(
                    'http://*****:*****@socketio.on('join-room')
    def sock_join_room(data):
        print(data)
        print("Want to join {}".format(data['room']))
        r_type, r_id = tuple(data['room'].split('-', maxsplit=1))
        if r_type == "user":
            print("That room is a private user room")
            print("it belongs to user {}".format(r_id))
            print("TODO: check if request was sent by that user")
        try:
            join_room(data['room'])
            emit('join-room', {'status': 'success',
                               'room': data['room']})
        except Exception as e:
            print("Failed to join room")
            emit('join-room', {'status': 'failure',
                               'room': data['room']})

    @socketio.on('leave-room')
    def sock_leave_room(data):
        print(data)
        print("Want to leave {}".format(data['room']))
        try:
            leave_room(data['room'])
        except Exception as e:
            print("Failed to leave toom")

    @socketio.on('setup-email')
    def setup_mail(data):
        emit('setup-email', {'result': 'update', 'data': "recieved data"})
        email = data['email']
        password = data['password']
        port = data['port']
        server = data['pop']
        course_id = data['course_id']
        sleeptime = app.config['MAIL_WAIT_TIME_BEFORE_FETCH']

        thread = MailThread.existThreadCourseID(course_id)
        if (MailThread.existThreadEmail(email)):
            if thread is None:
                emit('setup-email',
                     {'result': 'fail', 'data': 'Email already exists'})
                return

        try:
            test_connection = poplib.POP3_SSL(server, port)
            test_connection.user(email)
            test_connection.pass_(password)
            test_connection.quit()
        except (poplib.error_proto) as msg:
            message = msg.args[0].decode('ascii')
            emit('setup-email', {'result': 'fail', 'data': message})
            return
        except OSError as msg:
            message = str(msg)
            emit('setup-email', {'result': 'fail', 'data': message})
            return

        if (thread is None):
            new_thread = MailThread(sleeptime, server, port, email, password,
                                    course_id)
            new_thread.setName(course_id)
            new_thread.start()
        else:
            thread.update(sleep_time=sleeptime, server=server, port=port,
                          email=email, password=password)

        course = Course.Course.query.get(course_id)
        course.course_email = email
        course.mail_password = password
        course.mail_port = port
        course.mail_server_url = server
        if not database.addItemSafelyToDB(course):
            emit('setup-email', {'result': 'fail', 'data': 'database error'})
            return

        emit('setup-email', {'result': 'succes'})
        return

    return app
Esempio n. 7
0
def initd_command():
    """Initialize the databse."""
    init_db()
    print("Initialized the databse.")
Esempio n. 8
0
def initdb(error):
    from flaskr.database import init_db
    init_db()
    return "db done"
Esempio n. 9
0
 def _init_ext(app):
     from flaskr.redisutils import RedisConn
     init_db(app)
     RedisConn.init(config.Config.REDIS_HOST, config.Config.REDIS_PORT,
                    config.Config.REDIS_PASSWORD, config.Config.REDIS_DB)