Ejemplo n.º 1
0
 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()  # Flask内建的测试客户端,模拟浏览器行为
Ejemplo n.º 2
0
 def setUp(self):
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client()
     tag = Tag()
     tag.name = 'tagx'
     db.session.add(tag)
     category = Category()
     category.name = 'categoryx'
     db.session.add(category)
     db.session.commit()
     article = Article()
     article.title = 'articlex'
     article.slug = 'slugx'
     article.category = category
     article.content = 'contentx'
     article.tags = [tag]
     db.session.add(category)
     db.session.commit()
     user = User()
     user.name = 'admin'
     user.password = '******'
     db.session.add(user)
     db.session.commit()
Ejemplo n.º 3
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client(use_cookies=True)
Ejemplo n.º 4
0
    def setUp(self) -> None:
        """Setting up application for tests"""

        self.app = create_app()
        self.app.config.from_object(TestConfig)
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
Ejemplo n.º 5
0
 def setUp(self):
     self.app = create_app(TestingConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.user = self.register_user()
     self.post = self.add_post()
Ejemplo n.º 6
0
def dev(host, port):
    """
    Test Mode
    """
    CONFIG['DEBUG'] = True
    app = create_app(CONFIG)
    server = Server(app.wsgi_app)
    server.watch('**/*.*')
    server.serve(host=host, port=int(port))
Ejemplo n.º 7
0
 def setUp(self):
     self.db_name = 'project_m_test'
     self.app = blog.create_app(MONGODB_SETTINGS={
         'DB': self.db_name,
         'HOST': 'masunghoon.asuscomm.com'
     },
                                TESTING=True)
     self.ctx = self.app.app_context()
     self.ctx.push()
Ejemplo n.º 8
0
def client():
    app = create_app(config_class=config.TestingConfig)

    # Flask provides a way to test your application by exposing the Werkzeug
    # test client and handling the context locals test_client() method
    # Establish an application context before running the test use
    # context manager
    with app.test_client() as client:
        with app.app_context():
            yield client
Ejemplo n.º 9
0
def app(request):
    """An application for the tests."""
    os.environ['TYPE'] = TESTING
    _app = create_app()
    request.cls.app = _app.test_client()
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
 def setUp(self):
     self.app = create_app(config['testDB'])
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.user = User(username='******',
                      email='*****@*****.**',
                      password='******',
                      image_file='Night view.png')
     db.session.add(self.user)
     db.session.commit()
Ejemplo n.º 11
0
def app(request):
    """An application for the tests."""
    os.environ['TYPE'] = TESTING
    _app = create_app()
    request.cls.app = _app.test_client()
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
Ejemplo n.º 12
0
 def setUp(self):
     """
     1. create db if not exists, drop db and create if exists
     2. db.create_all()
     """
     create_db()
     self.app = create_app(TestingConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.test_client = self.app.test_client()
     db.create_all()
Ejemplo n.º 13
0
	def setUp(self):
		self.app = create_app(config['testDB'])
		self.app_context = self.app.app_context()
		self.app_context.push()
		db.create_all()
		self.user = User(username='******', email='*****@*****.**',
						 password='******', image_file='Night view.png')
		db.session.add(self.user)
		db.session.commit()
		self.post = Post(title='Random post', date_posted=parser.parse("2020 05 17 12:00AM"),
				 		 content='Some words', user_id=self.user.id)
		db.session.add(self.post)
		db.session.commit()
Ejemplo n.º 14
0
def client():
    # 设置测试数据库路径和测试环境
    app = create_app('test')

    # 初始化测试数据库
    with app.test_client() as client:
        with app.app_context():
            db.drop_all()
            db.create_all()
            db.session.add(User(username='******', password='******'))
            db.session.commit()
            db.session.close()
        yield client
Ejemplo n.º 15
0
Archivo: base.py Proyecto: xue000/Blog
    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()
        Role.init_role()

        admin_user = User(email='*****@*****.**',
                          name='Admin',
                          username='******')
        admin_user.set_password('123')
        admin_user.set_role()
        normal_user = User(email='*****@*****.**',
                           name='Normal User',
                           username='******')
        normal_user.set_password('123')
        unconfirmed_user = User(
            email='*****@*****.**',
            name='Unconfirmed',
            username='******',
        )
        unconfirmed_user.set_password('123')
        locked_user = User(email='*****@*****.**',
                           name='Locked User',
                           username='******',
                           locked=True)
        locked_user.set_password('123')
        locked_user.lock()

        blocked_user = User(email='*****@*****.**',
                            name='Blocked User',
                            username='******',
                            active=False)
        blocked_user.set_password('123')

        category = Category(name='test category')
        post = Post(title='test post', body='Test post', category=category)
        comment = Comment(body='test comment body',
                          post=post,
                          author=normal_user)
        db.session.add_all([
            admin_user, normal_user, unconfirmed_user, locked_user,
            blocked_user
        ])
        db.session.commit()
Ejemplo n.º 16
0
def app():
    db_fd, db_path = tempfile.mkstemp()

    app = create_app({
        "SECRET_KEY": "test",
        "TESTING": True,
        "SQLALCHEMY_DATABASE_URI": "sqlite:///" + db_path,
    })

    with app.app_context():
        init_db()

    yield app

    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 17
0
Archivo: base.py Proyecto: zxbylx/blog
    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()
Ejemplo n.º 18
0
def app():
    db_fd, db_path = tempfile.mkstemp()

    app = create_app({
        'TESTING': True,
        'DATABASE': db_path,
    })

    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    os.close(db_fd)
    os.unlink(db_path)
Ejemplo n.º 19
0
from flask_migrate import MigrateCommand, Migrate

# 使用管理器
from flask_script import Manager
# 导入工厂函数
from blog import create_app, db, models

# 调用__init__文件中的工厂函数,获取app
from blog.models import User

app = create_app('development')

manage = Manager(app)
Migrate(app, db)
manage.add_command('db', MigrateCommand)


# 创建管理员账户
# 在script扩展,自定义脚本命令,以自定义函数的形式实现创建管理员用户
# 以终端启动命令的形式实现;
# 在终端使用命令:python manage.py create_supper_user -n admin -p 123456
@manage.option('-n', '-name', dest='name')
@manage.option('-p', '-password', dest='password')
def create_supper_user(name, password):
    if not all([name, password]):
        print('参数缺失')
    user = User()
    user.nick_name = name
    user.mobile = name
    user.password = password
    user.is_admin = True
Ejemplo n.º 20
0
from blog import create_app

app = create_app()

if __name__ == '__main__':
    app.run()
Ejemplo n.º 21
0
 def setUp(self):
     self.app = create_app(TestingConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
Ejemplo n.º 22
0
from blog import create_app, db
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

# 创建flask的应用对象
app = create_app("develop")
manage = Manager(app)

Migrate(app, db)
manage.add_command("db", MigrateCommand)

if __name__ == '__main__':
    manage.run()
Ejemplo n.º 23
0
"""
    定义Flask应用实例
"""
import os
import sys
import click
from blog import create_app

app = create_app(None)  # development

# production

# app = create_app('production')
# if __name__ == '__main__':
#     from werkzeug.contrib.fixers import ProxyFix
#     app.wsgi_app = ProxyFix(app.wsgi_app)
#     app.run()

# 创建 coverage 实例
COV = None
if os.environ.get('FLASK_COVERAGE'):
    import coverage
    COV = coverage.coverage(branch=True, include='blog/*')
    COV.start()


@app.cli.command()
@click.option('--coverage/--no-coverage',
              default=False,
              help='Run tests under code coverage.')
def test(coverage):
Ejemplo n.º 24
0
#!/usr/bin/env python
import os

from blog import create_app

from flask.ext.script import Manager


app = create_app(os.getenv("FLASK_CONFIG") or "default")
manager = Manager(app)


@manager.command
def init_database():
    from blog import db
    from blog import models

    db.create_all()


@manager.command
def recreate_database():
    from blog import db
    from blog import models

    db.reflect()  # hacky solution
                  # ref: http://jrheard.tumblr.com/post/12759432733/dropping-all-tables-on-postgres-using
    db.drop_all()
    db.create_all()

Ejemplo n.º 25
0
from blog import create_app
from blog.models import Article
from extand import db
import markdown

app = create_app('dev')


def do():
    with app.app_context():
        articles = Article.query.all()
        for article in articles:
            article.raw_content = article.content
            article.content = markdown.markdown(
                article.raw_content,
                extensions=[
                    'markdown.extensions.extra',
                    'markdown.extensions.codehilite',
                    'markdown.extensions.toc',
                ])
            db.session.add(article)
        db.session.commit()
    print('finish')


if __name__ == "__main__":
    do()
Ejemplo n.º 26
0
 def setUp(self):
     """Checks the proper creation of the models on App startup."""
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 27
0
import os

from blog import create_app

config_name = os.getenv('FLASK_ENV')
app = create_app(config_name)

if __name__ == '__main__':
    app.run()
Ejemplo n.º 28
0
#!/usr/bin/env python
import os
from blog import create_app, db
from blog.models import User, Role, Post
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand

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, User=User, Role=Role, Post=Post)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
Ejemplo n.º 29
0
 def setUp(self):
   self.app = create_app('blog.configs.TestConfig', 'test')
   with self.app.app_context():
     db.create_all()
   self.client = self.app.test_client()
Ejemplo n.º 30
0
if os.environ.get('FLASK_COVERAGE'):
  import coverage
  COV = coverage.coverage(branch=True, include='app/*')
  COV.start()

from flask.ext.script import Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script.commands import ShowUrls, Clean

from blog import create_app
from blog.models import db, User

# Try to load an environment, or default to a development config
env = os.environ.get('BLOG_ENV', 'dev')
# Load the settings
app = create_app('blog.configs.{0}Config'.format( env.capitalize()), env=env)
print('Using config {0}'.format(env))

migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command("server", Server())
manager.add_command("show-urls", ShowUrls())
manager.add_command("clean", Clean())
manager.add_command('db', MigrateCommand)

@manager.command
def createuser(name, password, email):
  if User.query.filter_by(username=name).first() != None:
    print('User with name', name, 'already exists!')
    return
Ejemplo n.º 31
0
 def setUp(self):
     self.app = create_app('testing')  # ????????????????????????????????
     self.app_contaxt = self.app.app_context()
     self.app_contaxt.push()
     db.create_all()
Ejemplo n.º 32
0
from blog import create_app


app = create_app('config/settings.py')
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5996)
Ejemplo n.º 33
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 blog import create_app

app = create_app('production')
Ejemplo n.º 34
0
import os
from blog import create_app,db
from blog.models import User, Role
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app(os.getenv('FLASKY_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app,db)

def make_shell_context():
    return dict(app=app,db=db,User=User,Role=Role)

app.debug = True
manager.add_command("shell",Shell(make_context=make_shell_context))
manager.add_command('db',MigrateCommand)

if __name__ == '__main__':
    manager.run()
Ejemplo n.º 35
0
"""Contains WSGI for blog app."""

from os import environ

from blog import create_app

# Load app_config from environment variable
app_config = environ.get("APP_CONFIG", "config.DevelopmentConfig")

app = create_app(app_config)


def start():
    """Start blog web server."""
    app.run()


if __name__ == "__main__":
    start()
Ejemplo n.º 36
0
 def setUp(self):
     '''每个测试之前执行'''
     self.app = create_app('testing')  # 创建Flask应用
     self.app_context = self.app.app_context()  # 激活(或推送)Flask应用上下文
     self.app_context.push()
     db.create_all()  # db.create_all()快速创建所有的数据库表
Ejemplo n.º 37
0
'''
启动和管理项目
'''
from blog import create_app

app = create_app()

if __name__ == '__main__':
    app.run()
Ejemplo n.º 38
0
from blog import create_app

blog = create_app('../config.py')