Exemplo n.º 1
0
def db_engine(db_options:DatabaseConfig, db_url: str):
    """
    Fixture providing SQLAlchemy test database connectivity 
    
    :param db_options: database options 
    :param db_url: test database conninfo URL
    """
    db_engine = sa.create_engine(db_url)

    # speed up tests by only installing schema if there was no prior database created with --keepdb
    if not db_options.keepdb_active or os.path.exists(db_options.keepdb_path):
        models.init_database(db_engine)

    yield db_engine

    db_engine.dispose()
Exemplo n.º 2
0
def generate_data(session:sa_orm.Session, scenario_name:dict,
                  conf_dir:str= constants.DEFAULT_CONFIG_DIR):
    config = load_json_file(os.path.join(conf_dir, 'perfdata.conf.json'))
    scenario = config[scenario_name]

    # parse metrics
    metrics = factories.SourceDataMetrics(**scenario['metrics'])

    # load all available schemas
    schemas = []
    for schema_name in scenario['schemas']:
        schema_filename = os.path.join(conf_dir, 'schemas', schema_name + '.json')
        schemas.append(load_json_file(schema_filename))

    LOGGER.info('Creating database schema...')
    models.init_database(session.connection())

    # generate the data
    LOGGER.info('Generating data...')
    factories.make_source_data(session, metrics, schemas)

    session.commit()
Exemplo n.º 3
0
    ['/admin/article/manage', app.controllers.article_manage],
    ['/admin/article/modify', app.controllers.article_modify],
    ['/admin/article/delete', app.controllers.article_delete],
    ['/admin/category/manage', app.controllers.category_manage],
    ['/admin/category/modify', app.controllers.category_modify],
    ['/admin/category/delete', app.controllers.category_delete],
    ['/admin/message/manage', app.controllers.message_manage],
    ['/admin/message/create', app.controllers.message_create],
    ['/admin/message/delete', app.controllers.message_delete],
    ['/admin/comment/manage', app.controllers.comment_manage],
    ['/admin/comment/create', app.controllers.comment_create],
    ['/admin/comment/delete', app.controllers.comment_delete],
    ['/admin/config', app.controllers.config],
    ['/admin/config/password', app.controllers.config_password],
    ['/admin/config/title', app.controllers.config_title],
    ['/admin/config/email', app.controllers.config_email],
    ['/admin/logout', app.controllers.logout],
]

if __name__ == "__main__":
    app = init()
    create_database(app)
    init_database(app)

    for route in routes:
        app.add_url_rule(route[0],
                         endpoint=route[0],
                         view_func=route[1],
                         methods=['GET', 'POST'])

    app.run(host="0.0.0.0", port=80, debug=True)
Exemplo n.º 4
0
import json
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource
import app
from app.room import RoomList, Room
from app import models

#https://flask-restful.readthedocs.io/en/latest/quickstart.html#endpoints

app.api.add_resource(RoomList, '/room')
app.api.add_resource(Room, '/room/<room_id>')

if __name__ == '__main__':
    models.init_database()
    models.create_testdata()
    app.app.run(host='0.0.0.0', debug=True)