def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.admin = Admin( email=current_app.config['BLOG_ADMIN_EMAIL'], username="******", password="******" ) db.session.add(self.admin) db.session.commit() self.client = self.app.test_client()
def app(): # tempfile.mkstemp() creates and opens a temporary file, returning # the file object and the path to it _, db_path = tempfile.mkstemp() app = create_app({ # TESTING tells Flask that the app is in test mode 'TESTING': True, 'DATABASE': db_path, }) with app.app_context(): init_db() get_db().executescript(_data_sql) yield app db_path = Path(db_path) db_path.unlink()
def test_config(): assert not create_app().testing assert create_app({'TESTING': True}).testing
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.client = self.app.test_client()
from my_blog import create_app app = create_app()
# coding=utf8 import os from my_blog import create_app, db from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand app = create_app('default') manager = Manager(app) migrate = Migrate(app, db) def make_shell_context(): return dict(app=app, db=db) manager.add_command('shell', Shell(make_context=make_shell_context)) manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run() # print(app.url_map) # app.run(host="0.0.0.0", port=5000)
from flask_script import Manager, Server from flask_migrate import Migrate, MigrateCommand # from flask import render_template, redirect, url_for, Flask # from main import app # from config import DevConfig # import models # from models import db # from my_blog.controller import blog from my_blog import create_app from my_blog import models #app = Flask(__name__) #app.config.from_object(DevConfig) env = os.environ.get('BLOG_ENV', 'dev') app = create_app('my_blog.config.%sConfig' % env.capitalize()) manage = Manager(app) migrate = Migrate(app, models.db) manage.add_command('server', Server(host='localhost', port=8089)) manage.add_command('db', MigrateCommand) # db.init_app(app) @manage.shell def make_shell_context(): return dict(app=app, db=models.db, User=models.User, Post=models.Post, Comment=models.Comment, Tag=models.Tag,
COV = None if os.environ.get('FLASK_COVERAGE'): import coverage COV = coverage.coverage(branch=True, include='app/*') COV.start() if os.path.exists('.env'): print 'Importing environment from .env ... ' for line in open('.env'): var = line.strip().split('=') if len(var) == 2: os.environ[var[0]] = var[1] app = create_app(os.getenv('FLASK_CONFIG') or 'default') manager = Manager(app) migrate = Migrate(app, db) def make_shell_context(): return dict(app=app, db=db, WorkExperience=WorkExperience, EducationExperience=EducationExperience, Skill=Skill, Guest=Guest, Admin=Admin, Post=Post, Comment=Comment, Tag=Tag) manager.add_command('shell', Shell(make_context=make_shell_context)) manager.add_command('db', MigrateCommand) @manager.command