Example #1
0
def test_app():
    from app import create_app
    from config import TestConfig
    from main import register_blueprints, db as _db

    app = create_app(TestConfig)
    register_blueprints(app)
    _db.init_app(app)
    _db.app = app
    _db.create_all()
    return app
Example #2
0
def create_app(test_config=None):
    UPLOAD_FOLDER = '/uploads/'
    ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        # a default secret that should be overridden by instance config
        SECRET_KEY='dev',
        # store the database in the instance folder
        DATABASE=os.path.join(app.instance_path, 'main.sqlite'),
        UPLOAD_FOLDER=UPLOAD_FOLDER)

    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.update(test_config)

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

    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    # register the database commands
    from main import db
    db.init_app(app)

    # apply the blueprints to the app
    from main import main
    app.register_blueprint(main.bp)
    app.register_error_handler(404, main.page_not_found)
    app.register_error_handler(500, main.server_error)

    #app.register_blueprint(blog.bp)

    # make url_for('index') == url_for('blog.index')
    # in another app, you might define a separate main index here with
    # app.route, while giving the blog blueprint a url_prefix, but for
    # the tutorial the blog will be the main index
    app.add_url_rule('/', endpoint='index')

    return app
Example #3
0
def db(app_context):
    from main import db
    db.init_app(app_context)
    yield db
from main import app, db
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

db.init_app(app)
migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
Example #5
0
 def setUp(self):
     db.init_app(self.app)
     db.create_all()
     db.session.add(Task(name="have breakfast", status=0))
     db.session.add(Task(name="have lunch", status=0))
     db.session.commit()
Example #6
0
from flask import Flask, render_template, request, session, jsonify
from main import Application, Actor, Goal, Datum, Disclosure, Mitigation, Impact, db
from flask_sqlalchemy import SQLAlchemy
import main
app = Flask(__name__)
app.secret_key = 'development key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db.init_app(app)

@app.route('/')
def start():
    return render_template('start.html', applications = Application.query.all())
    
@app.route('/favicon.ico')
def favicon():
    return app.send_static_file('favicon.ico')

@app.route('/application', methods = ['POST',])
def application():
    id = int(request.form['id'])
    name = request.form['name']
    verb = request.form['verb']
    if verb == 'create':
        application = Application(name)
        db.session.add(application)
    else:
        application = Application.query.filter_by(id=id).first()
        if (verb == 'delete'):    
            db.session.delete(application)
        elif (verb == 'edit'):
            new_name = request.form['newName']