def run(): from example.app import app from example.models import db, Character created_at = datetime.utcnow().replace(month=1, day=1, hour=10, minute=0, second=0, microsecond=0) with app.test_request_context(): db.drop_all() db.create_all() db.session.add(Character(id=1, created_at=created_at, name='Obe Wan')) db.session.add( Character(id=2, created_at=created_at, name='Luke Skywalker')) db.session.add(Character(id=3, created_at=created_at, name='Yoda')) db.session.add( Character(id=4, created_at=created_at, name='Darth Vader')) db.session.add( Character(id=5, created_at=created_at, name='Princess Leia')) db.session.commit()
from flask import Flask, render_template from flask_login import login_required, current_user, LoginManager from flask_migrate import Migrate from example import config from example.models import db, User, write_user_to_db from flask_lti_login import lti, lti_login_authenticated lti_login_authenticated.connect(write_user_to_db) login_manager = LoginManager() app = Flask(__name__) app.config.from_object(config) login_manager.init_app(app) db.init_app(app) with app.app_context(): db.create_all() app.register_blueprint(lti) migrate = Migrate(app, db) @login_manager.user_loader def load_user(id): user = User.query.filter_by(id=id).first() return user @login_required @app.route('/', methods=['GET']) def main_page(): return render_template('main_page.html', user=current_user)
def createdb(): from example.models import db db.create_all()
def test_database(): db.create_all() yield db # testing happens here db.session.remove() db.drop_all()