Example #1
0
    def setUp(self):
        app = create_app('testing')
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()
        self.runner = app.test_cli_runner()

        db.create_all()
        user = Admin(name='Grey Li', username='******', about='I am test', blog_title='Testlog', blog_sub_title='a test')
        user.set_password('123')
        db.session.add(user)
        db.session.commit()
Example #2
0
def app():
    """Create and configure a new app instance for each test."""
    # create a temporary file to isolate the database for each test
    db_fd, db_path = tempfile.mkstemp()
    # create the app with common test config
    app = create_app({"TESTING": True, "DATABASE": db_path})

    # create the database and load test data
    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
Example #3
0
    def setUp(self) -> None:
        app = create_app("testing")
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()
        self.runner = app.test_cli_runner()

        db.create_all()
        user = Admin(
            name="Grey Li",
            username="******",
            about="I am test",
            blog_title="Testlog",
            blog_sub_title="a test",
        )
        user.set_password("123")
        db.session.add(user)
        db.session.commit()
Example #4
0
from dotenv import load_dotenv
import os

dotenv_path = os.path.join(os.path.dirname(__file__), '.flaskenv')
if os.path.exists(dotenv_path):
    load_dotenv(dotenv_path)

from myblog import create_app

app = create_app('production')
Example #5
0
from myblog import create_app

app = create_app()

if __name__ == '__main__':
    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    app.run(debug=True)
Example #6
0
from myblog import create_app

app = create_app(config_name='production')
Example #7
0
def test_config():
    """Test create_app without passing test config."""
    assert not create_app().testing
    assert create_app({"TESTING": True}).testing
Example #8
0
import os
from dotenv import load_dotenv

dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
if os.path.exists(dotenv_path):
    load_dotenv(dotenv_path)

from myblog import create_app

app = create_app("production")
Example #9
0
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Server
from myblog import create_app
from myblog.controllers.model import User, Role, HiddenPeril, Detal, Devtable, Comment, BLOGImage, Tag, Post, Image, Devdefect
from myblog.exts import db, myconfig

app = create_app(myconfig)
migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command("runserver", Server(host='127.0.0.1', port='8080'))
manager.add_command("db", MigrateCommand)


@manager.shell
def make_shell_context():
    return dict(app=app,
                db=db,
                User=User,
                Post=Post,
                Comment=Comment,
                Tag=Tag,
                Role=Role,
                Devtable=Devtable,
                HiddenPeril=HiddenPeril,
                Image=Image,
                BLOGImage=BLOGImage,
                Devdefect=Devdefect)


@app.before_first_request
Example #10
0
# import Flask Script object
import os
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Server

from myblog import models, __init__, create_app

#Get the env from os_environ
env = os.environ.get('BLOG_ENV', 'dev')
#Create app instance via factory method
app = create_app('myblog.config.%sConfig' % env.capitalize())
#Init manager
manager = Manager(app)

migrate = Migrate(app, models.db)

# Init manager object via app object
# manager = Manager(__init__.app)

# Init migrate object via app and db object
# migrate = Migrate(__init__.app, models.db)

# Create some new commands
manager.add_command("server", Server())
manager.add_command("db", MigrateCommand)


@manager.shell
def make_shell_context():
    """Create a python CLI.
    return: Default import object