def setUp(self):
     """Define test variables and initialize app."""
     self.app = create_app()
     self.client = self.app.test_client
     self.database_name = "test_trivia"
     self.database_path = "postgresql://{}:{}@{}/{}".format(
         'postgres', '1', 'localhost:5432', self.database_name)
     setup_db(self.app, self.database_path)
예제 #2
0
def client():
    my_app = create_app({
        'TESTING': True,  # Set to True during testing.
        'REPOSITORY':
        'memory',  # Set to 'memory' or 'database' depending on desired repository.
        'TEST_DATA_PATH':
        TEST_DATA_PATH_MEMORY,  # Path for loading test data into the repository.
        'WTF_CSRF_ENABLED':
        False  # test_client will not send a CSRF token, so disable validation.
    })

    return my_app.test_client()
예제 #3
0
def test_client():
    flask_app = create_app()

    # Flask provides a way to test your application by exposing the Werkzeug test Client
    # and handling the context locals for you.
    testing_client = flask_app.test_client()

    # Establish an application context before running the tests.
    ctx = flask_app.app_context()
    ctx.push()
    yield testing_client  # start testing
    ctx.pop()
예제 #4
0
    def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app()
        self.client = self.app.test_client
        self.database_name = "test_db"
        self.database_path = "postgres://{}:{}@{}/{}".format(
            'lyuben', 'temp123!', 'localhost:5432', self.database_name)
        setup_db(self.app, self.database_path)

        self.new_book = {
            'title': 'Time and Power',
            'author': 'Petar Deunov',
            'rating': 5
        }
예제 #5
0
    def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app()
        self.client = self.app.test_client
        self.database_name = "trivia_test"
        self.database_path = "postgres://{}@{}/{}".format(
            'postgres', 'localhost:5432', self.database_name)
        setup_db(self.app, self.database_path)

        # binds the app to the current context
        with self.app.app_context():
            self.db = SQLAlchemy()
            self.db.init_app(self.app)
            # create all tables
            self.db.create_all()
예제 #6
0
    def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app()
        self.client = self.app.test_client
        self.database_name = "bookshelf_test"
        ##self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name)
        self.database_path = "postgres://{}:{}@{}/{}".format(
            'Kaustav', 'k', 'localhost:5432', self.database_name)
        setup_db(self.app, self.database_path)

        self.new_book = {
            'title': 'Anansi Boys',
            'author': 'Neil Gaiman',
            'rating': 5
        }

        # binds the app to the current context
        with self.app.app_context():
            self.db = SQLAlchemy()
            self.db.init_app(self.app)
            # create all tables
            self.db.create_all()
예제 #7
0
def app():
    app = create_app()  # <<=== A CHANGER
    return app
예제 #8
0
파일: chat.py 프로젝트: gongjunhuang/Spider
from __init__ import create_app, socketio

app = create_app(debug=True)

if __name__ == '__main__':
    socketio.run(app)
예제 #9
0
def client():
    app = create_app()      # <<=== A CHANGER
    client = app.test_client()
    yield client
예제 #10
0
def main():
    app = create_app()
    app.run(host='localhost', port=8000, threaded=False, debug=True)
예제 #11
0
def test_client() -> FlaskClient:
    flask_app = create_app()
    with flask_app.test_client() as testing_client:
        with flask_app.app_context():
            return testing_client
예제 #12
0
from __init__ import db, create_app
db.create_all(app=create_app())
예제 #13
0
import sys
import models
from getpass import getpass
from werkzeug.security import generate_password_hash
from __init__ import create_app, db
from models import User

username = input("Enter your username: "******"Enter a new password: "******"Re-enter new password: "******"Did not match."

# pylint: disable=E1101
with create_app().app_context():
    admin = User.query.filter_by(username=username).first()
    if not admin:
        yorn = input(f"Superuser '{username}' not found, create? [Y/N]: ")
        if yorn in ("Y", "y"):
            admin = User(username=username, password_hash="")
            db.session.add(admin)
        else:
            sys.exit(0)
    admin.password_hash = generate_password_hash(new_password)
    db.session.commit()
예제 #14
0
from __init__ import create_app

application = create_app()
application.run()
예제 #15
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
from __init__ import create_app, db
from models import User, Role, Post
from flask.ext.script import Manager, Shell, Server
from flask.ext.migrate import Migrate, MigrateCommand

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


#创建shell命令上下文。。这里的app,db等无需手动在shell中import
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Post=Post)


@manager.command
def deploy():
    "Run deployment tasks"
    from flask.ext.migrate import upgrade
    from models import User, Role, Post

    #数据库迁移到最新修订版本
    # upgrade()

    #创建用户角色
    Role.insert_roles()
예제 #16
0
파일: f_app.py 프로젝트: Mihail12/prototype
import random
import time

from celery import Celery
from flask import render_template, request, jsonify, session
from flask_socketio import SocketIO, join_room
from random import randint

import celeryconfig
from __init__ import create_app

flask_app = create_app()
flask_app.secret_key = "DataRoadReflect"

celery_app = Celery('demo', broker='redis://localhost:6379', include=['tasks'])
celery_app.config_from_object(celeryconfig)

applogger = flask_app.logger
socketio = SocketIO(flask_app, message_queue='redis://')

user_1 = {
    'id': 1,
    'name': 'John',
    'role': 'manager',
    'age': 60,
}

user_2 = {
    'id': 2,
    'name': 'Bob',
    'role': 'manager',
예제 #17
0
def client():
    app = create_app()
    app.config["TESTING"] = True

    with app.test_client() as client:
        yield client
예제 #18
0
파일: manage.py 프로젝트: wupperwufei/marry
from flask import render_template
from __init__ import create_app
from flask_script import Manager, Shell, Server
from flask_migrate import Migrate, MigrateCommand
from models import *

app = create_app('default')
manager = Manager(app)
migrate = Migrate(app, db)


# db.create_all(app=create_app('default'))
# print(app.url_map)
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)
manager.add_command('start', Server(host='0.0.0.0', port=9002))


@app.errorhandler(404)
def page_not_found(error):
    return '未找到你的页面'


if __name__ == '__main__':
    manager.run()
예제 #19
0
# -*- coding: utf-8 -*-
import __init__
import json
from flask import Flask

app = __init__.create_app()

app.run(debug=True)
예제 #20
0
# -*- coding: utf-8 -*-

import os

# from flask_script import Manager, Server
from flask_script import Manager, Server

from __init__ import create_app

# Get the ENV from os_environ
# 现在的 manager shell 在每次启动的时候,都会获取一次 OS 的环境变量,并以此来创建 app 对象。
# 默认使用 DevConfig 配置
env = os.environ.get('demo_ENV', 'develop')

# Create thr app instance via Factory Method
app = create_app('main.resources.config.%s' % env)

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

# Create a new commands: server
# This command will be run the Flask development_env server
# manager.add_command("server", Server(use_debugger=True))
manager.add_command("server", Server(host='127.0.0.1', port=8089))
# new command
# manager.add_command("db", MigrateCommand)

# @manager.shell
# def make_shell_context():
#     """Ceate a python CLI.
#
예제 #21
0
# worker_service/intro.py
import eventlet
import eventlet.wsgi
from flask.cli import FlaskGroup
from flask import jsonify, Flask

# config
from __init__ import create_app, setup_logging

# initialization
setup_logging()
socketio, app = create_app()

# Run server
if __name__ == '__main__':
    eventlet.wsgi.server(eventlet.listen(('0.0.0.0', 49153)), app)
예제 #22
0
파일: manage.py 프로젝트: louyanqi/leo
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from filters import add_one
import models
from __init__ import create_app
import config
from flask_assets import ManageAssets
from ext import assets_env

app = create_app(config.DevConfig)
app.DEBUG = True
manager = Manager(app)
migrate = Migrate(app, models.db)
app.jinja_env.filters['add_one'] = add_one

manager.add_command("server", Server(threaded=True))
manager.add_command('db', MigrateCommand)
manager.add_command('assets', ManageAssets(assets_env))


@manager.shell
def make_shell_context():
    return dict(
        app=app,
        db=models.db,  # db,create_all()
        User=models.User,
        Article=models.Article,
        Comment=models.Comment,
        Tag=models.Tag,
        Server=Server)
예제 #23
0
from flask_script import Manager
from config import config
from __init__ import create_app

config_class = config['development']
app = create_app(config_class)

if __name__ == '__main__':
    manager = Manager(app)
    manager.run()
예제 #24
0
#!/usr/bin/env python3
from flask_frozen import Freezer
import __init__

freezer = Freezer(__init__.create_app())

if __name__ == '__main__':
    freezer.freeze()
예제 #25
0
파일: run.py 프로젝트: dan-may/translation
#!/usr/bin/env python
from __init__ import create_app

if __name__ == '__main__':
    app = create_app()
    app.run()
예제 #26
0
def app(request):
    """
    Returns session-wide application.
    """
    return create_app(TestConfig)
예제 #27
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-



import os
import sys
from __init__ import create_app,db
from models import User,Role,Post
from flask.ext.script import Manager,Shell,Server
from flask.ext.migrate import Migrate,MigrateCommand



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


#创建shell命令上下文。。这里的app,db等无需手动在shell中import
def make_shell_context():
	return dict(app = app,db = db,User = User,Role = Role,Post = Post)

@manager.command
def deploy():
	"Run deployment tasks"
	from flask.ext.migrate import upgrade
	from models import User,Role,Post

	#数据库迁移到最新修订版本
	# upgrade()
예제 #28
0
# _*_ coding:utf-8 _*_
# Filename: main_v2.py
# Author: pang song
# python 2.7
# Date: 2018/06/24
# 352工具 服务器测试

from __init__ import create_app

if __name__ == '__main__':
    # 局域网访问调试
    create_app().run(host='0.0.0.0', port=8190, debug=True)

    # 本机调试
    # app.run(debug=True)
예제 #29
0
from flask import Blueprint, render_template, flash
from flask_login import login_required, current_user
from __init__ import create_app, db

main = Blueprint('main', __name__)


@main.route('/')  # home page that return 'index'
def index():
    return render_template('index.html')


@main.route('/profile')  # profile page that return 'profile'
@login_required
def profile():
    return render_template('profile.html', name=current_user.name)


app = create_app(
)  # we initialize our flask app using the __init__.py function
if __name__ == '__main__':
    db.create_all(app=create_app())  # create the SQLite database
    app.run(debug=True)  # run the flask app on debug mode
예제 #30
0
#!/usr/bin/env python3
import os
import sys
import tempfile
import pytest

ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
# add the project directory to the sys.path
if ROOT not in sys.path:
    sys.path = [ROOT] + sys.path
from __init__ import create_app
from dbquery import init_db

meownotes = create_app()

# test user credentials
TEST_USER = "******"
TEST_PASSWORD = "******"

# a fixture is called by the tests when running
# created using the flask documentation http://flask.pocoo.org/docs/1.0/testing/


# START section based on documentation
@pytest.fixture
def client():
    """
    Used for all tests; sets up test db
    """
    db_fd, meownotes.config["DATABASE"] = tempfile.mkstemp()
    meownotes.config["TESTING"] = True
예제 #31
0
import os
from datetime import datetime, timedelta
from __init__ import create_app
from models import db, Workload
from tasks import stop_workload

app = create_app()

timedelta_hours = int(os.getenv('HOURS_KEEP_DEPLOYMENTS', '1'))

with app.app_context():
    data = db.session.query(
        Workload.id, Workload.workload, Workload.workload_type,
        Workload.namespace).filter(Workload.created < datetime.utcnow() -
                                   timedelta(hours=timedelta_hours)).all()
    for workload in data:
        stop_workload.send(workload.id, workload.workload,
                           workload.workload_type, workload.namespace)
예제 #32
0
from flask import Flask
import os, config
from __init__ import create_app

app = Flask(__name__)

if __name__ == "__main__":
    create_app(app).run()