Ejemplo n.º 1
0
    def setUp(self):
        self.app = create_app("Test")
        self.app_context = self.app.test_request_context()
        self.app_context.push()
        self.client = self.app.test_client()

        with self.app.app_context():
            db.create_all()
            usr_role = Role(name="user")
            adm_role = Role(name="admin")
            db.session.add(usr_role)
            db.session.add(adm_role)
            # noinspection PyArgumentList
            db.session.add(
                User(
                    email=USR,
                    pw_hash=hashpw("password".encode("utf-8"), gensalt()),
                    roles=[usr_role],
                ))
            # noinspection PyArgumentList
            db.session.add(
                User(
                    email=ADM,
                    pw_hash=hashpw("password".encode("utf-8"), gensalt()),
                    roles=[adm_role, usr_role],
                ))
            db.session.commit()
Ejemplo n.º 2
0
def app():
    app = create_app('testing')
    yield app
    # Teardown
    users_to_delete = app._redis.lrange('user_list', 0, -1)
    for user in users_to_delete:
        try:
            app._db.execute_sql(
                SQL("REASSIGN OWNED BY {user} TO postgres;DROP OWNED BY {user};DROP USER {user};"
                    ).format(user=Identifier(user.decode('utf-8'))))
        except:
            pass
    groups_to_delete = app._redis.lrange('group_list', 0, -1)
    for group in groups_to_delete:
        try:
            app._db.execute_sql(
                SQL("DROP GROUP IF EXISTS {user};").format(
                    user=Identifier(group.decode('utf-8'))))
        except:
            pass
    app._db.execute_sql("TRUNCATE public.layer_styles RESTART IDENTITY;")
    app._db.execute_sql("TRUNCATE system.layer_tag RESTART IDENTITY;")
    app._db.execute_sql("TRUNCATE system.tag RESTART IDENTITY CASCADE;")
    app._db.execute_sql("TRUNCATE system.dict RESTART IDENTITY CASCADE;")
    app._db.execute_sql(
        f"TRUNCATE system.attachment_qgis RESTART IDENTITY CASCADE;")
    app._db.execute_sql("TRUNCATE system.project RESTART IDENTITY CASCADE;")
    app._db.execute_sql(f"DROP TYPE IF EXISTS {TEST_ENUM_NAME} CASCADE;")

    app._db.execute_sql("TRUNCATE attachment RESTART IDENTITY;")
    app._db.execute_sql("TRUNCATE settings RESTART IDENTITY;")
    app._db.execute_sql("TRUNCATE service RESTART IDENTITY CASCADE;")

    app._redis.delete('user_list')
    cur = app._db.execute_sql(
        "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"
    )
    tables_to_delete = [
        row[0] for row in cur.fetchall() if row[0] not in SYSTEM_TABLES
    ]
    for table in tables_to_delete:
        app._db.execute_sql('DROP TABLE "{}" cascade'.format(table))
    cur.close()
Ejemplo n.º 3
0
from app.create import create_app

app = create_app()
Ejemplo n.º 4
0
        for script in scripts_to_be_executed:

            print(f"{script.name}... ", end="")

            try:
                if script.name.endswith(".py"):
                    run_python_migration(app, script)
            except:
                print("")
                raise
            else:
                print("\33[32m", "OK", '\33[0m')

        insert_migrations(scripts_to_be_executed)

    return 0


if __name__ == '__main__':
    config = environ["CONFIG"]

    print(config.upper())
    app = create_app(config)
    main(app)

    if config.lower() != "production":
        print("")

        print("TESTING")
        app = create_app('testing')
        main(app)
Ejemplo n.º 5
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from app.create import create_app

if __name__ == '__main__':
    app = create_app('development')
    app.run(host='0.0.0.0', port=app.config['APP_PORT'], threaded=True)
else:
    app = create_app('production')
Ejemplo n.º 6
0
import os
from app.create import create_app

PATH_HERE = os.path.dirname(os.path.realpath(__file__))
PATH_INSTANCE = os.path.join(PATH_HERE, 'instance')
PATH_DB = os.path.join(PATH_INSTANCE, 'app.db')

CONFIG = {
    'SQLALCHEMY_DATABASE_URI': f'sqlite:///{PATH_DB}',
    'SQLALCHEMY_TRACK_MODIFICATIONS': False,
    'DEBUG': True,
}
APP = create_app(CONFIG)

if __name__ == "__main__":
    APP.run()
Ejemplo n.º 7
0
from app.create import create_app
from os import environ

app = create_app(config=environ.get("FLASK_COFIG", None))

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
Ejemplo n.º 8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from app.create import create_app

if __name__ == '__main__':
    app = create_app('production')
    app.run(host='0.0.0.0', port=app.config['APP_PORT'], threaded=True)
Ejemplo n.º 9
0
"""Starts the Flask application.

It can be run in various configurations using the FLASK_APP_ENV
environment variable. The available configurations are defined in
conf/config.py.

Example Usage::
    $ export FLASK_APP=run.py
    $ export FLASK_APP_ENV=Dev
    $ flask run
"""

from os import environ

from app.create import create_app
from app.extensions import make_celery

app = create_app(config=environ.get("FLASK_APP_ENV", None))
celery = make_celery(app)

if __name__ == "__main__":
    app.run()
Ejemplo n.º 10
0
# coding: utf-8
import json
from gevent.pywsgi import WSGIServer
from flask import Flask, request, Response, jsonify
from app.create import create_app
# from gevent import monkey;monkey.patch_all()
from utils.config import SERVER_PORT
from module.mtqq import mqtt_start_subscribe

app = create_app(True)

if __name__ == '__main__':
    mqtt_start_subscribe()  #启动mqtt订阅服务
    WSGIServer(('0.0.0.0', SERVER_PORT), app).serve_forever()