Ejemplo n.º 1
0
    def setUp(self):
        app = create_app('testing')
        self.app_context = app.app_context()
        self.app_context.push()
        self.client = app.test_client()

        db.create_all()
Ejemplo n.º 2
0
 def setUp(self):
     """
     测试之前运行,尝试创建一个测试环境,尽量与正常运行应用所需环境一致
     :return:
     """
     self.app = create_app('testing')  # 使用测试配置创建应用
     self.app_context = self.app.app_context()  # 激活上下文
     self.app_context.push()
     db.create_all()
Ejemplo n.º 3
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.º 4
0
from flask import Flask
from flask import render_template
from flask import render_template_string

from torcms.model.post_model import MPost

from flask_wtf import CSRFProtect

from flasky import create_app

app = create_app('default')

CSRFProtect(app)
# CsrfProtect(app)


@app.context_processor
def inject_user():
    return dict(test="<h1>a tmp variable</h1>")


#下面的functest函数也是可以在所有的模板中使用的
#使用方式如下{{ functionname(参数) }}
@app.context_processor
def testfunc():
    def post_recent(**kwargs):
        # return "{0}".format(kwargs)

        mpost = MPost()
        recs = mpost.query_recent_most(kwargs['num'])
        kwd = {}
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-

from flasky import create_app

app = create_app()
Ejemplo n.º 6
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 7
0
def test_config():
    assert not create_app().testing
    assert create_app({'TESTING': True}).testing
Ejemplo n.º 8
0
 def setUp(self):
     self.app = create_app(config_name=TestingConfig)
     self.client = self.app.test_client()
     self.product = Product('macbook', 'computers/laptops', 3, 1499.0)
     self.sale = Sale('kibuuka')
Ejemplo n.º 9
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 10
0
"""
程序入口
"""

from flasky import create_app
from config import config


app = create_app(config)

# db.create_all()

# from flasky.flaskr import flasky, init_db
from flasky.todo import todo
from flasky.client import client
from flasky import db
from flasky.models import TodoList,User
from flasky.login import author
from flask_cors import CORS

CORS(app)
# app.register_blueprint(flasky)
app.register_blueprint(todo, url_prefix='/todo')
app.register_blueprint(author,url_prefix='/author')
# app.register_blueprint(client, url_prefix='/client')

db.create_all()

todo1 = TodoList(id=1, task=u"build an API", user='******')
todo2 = TodoList(id=2, task=u'?????', user='******')
todo3 = TodoList(id=3, task=u'profit!', user='******')
Ejemplo n.º 11
0
import os
from flask_script import Manager, Shell
from flask_migrate import Migrate
from entity import *
from flasky import create_app

config_name = os.getenv('FLASK_CONFIG') or 'default'
app = create_app(config_name)
# manager = Manager(app)
#
# manager.add_command('shell', Shell(make_context=make_shell_context))
migrate = Migrate(app, db)


@app.shell_context_processor
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Post=Post, Follow=Follow)


if __name__ == '__main__':
    # manager.run()
    app.run(debug=True)
Ejemplo n.º 12
0
 def test_config(self):
     app = create_app(config.Config)
     self.assertTrue(app.config['DEBUG'])
Ejemplo n.º 13
0
 def test_production_config(self):
     app = create_app(config.ProductionConfig)
     self.assertTrue(app.config['DEBUG'])
Ejemplo n.º 14
0
 def test_testing_config(self):
     app = create_app(config.TestingConfig)
     self.assertTrue(app.config['TESTING'])
Ejemplo n.º 15
0
 def test_development_config(self):
     app = create_app()
     self.assertTrue(app.config['DEBUG'])
Ejemplo n.º 16
0
#!/usr/bin/env python3

import os
from flasky import create_app, db
from flasky.models import User, Role
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app((os.environ.get('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)


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


@manager.command
def test():
    """ Run unittests
    """
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == '__main__':