def setUp(self): logging.disable(logging.CRITICAL) app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///:memory:" app.config['TESTING'] = True app.app_context().push() self.app = app.test_client() with app.app_context(): setup_database(app)
def setUp(self): logging.disable(logging.CRITICAL) app.config["TESTING"] = True app.app_context().push() self.app = app.test_client() db_session.commit() Base.metadata.drop_all(engine) db_session.commit() Base.metadata.create_all(engine) db_session.commit() logging.info("Setting up database") setup_database(app)
def sendEmail(message): with app.app_context(): msg = Message('Attention Please!', sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = message mail.send(msg)
def client(): db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['FLASK_ENV'] = 'test' ctx = app.app_context() ctx.push() client = app.test_client() yield client os.close(db_fd) os.unlink(app.config['DATABASE'])
def ws_run(message): with app.app_context(): current_app.gol = GOL() X = np.zeros((17, 17)) X[2, 4:7] = 1 X[4:7, 7] = 1 X += X.T X += X[:, ::-1] X += X[::-1, :] X = np.array(message["data"]) current_app.gol.start(X)
def send_email(recipient, subject, template, **kwargs): with app.app_context(): msg = Message( subject, sender=("MIT Endurance Project", "*****@*****.**"), recipients=[recipient], ) # msg.body = render_template(template + '.txt', **kwargs) msg.html = render_template(template + ".html", **kwargs) result = mail.send(msg) print("RESULT\n\n\n\n") print(result)
def recreate_database_and_admin(app, admin_password='******', delect_table=False): """重建数据库和新建管理员""" if delect_table is True: db.drop_all(app=app) db.create_all(app=app) db.reflect() sha1_password = '******' % ('admin', admin_password, app.config['SALT']) last_password = hashlib.sha1(sha1_password.encode('utf-8')).hexdigest() new_use = Users(UserName='******', Password=last_password, CreateDate=datetime.now()) with app.app_context(): db.session.add(new_use) db.session.commit()
def myt_client(): app.config['TESTING'] = True app.app_context().push() with app.test_client() as client: yield client
def send_async_email(msg): with app.app_context(): mail.send(msg)
def setUp(self): """ Antes de las pruebas """ app.testing = True self.context = app.app_context()
def start(): with app.app_context(): print current_app.model return 'ok'
def index(): appdir = os.path.abspath(os.path.dirname(__file__)) with app.app_context(): current_app.model = None return make_response(open(os.path.join(appdir, 'views/index.html')).read())
def recreate_db(): with app.app_context(): metadata.drop_all() metadata.create_all()
from models import Upload, Video def iter_dicts(d, cb): stack = [d] while stack: el = stack.pop() if isinstance(el, dict): cb(el) stack.extend(el.values()) elif isinstance(el, list): stack.extend(el) if __name__ == '__main__': while True: print('starting index.') with app.app_context(): for u in Upload.query.all(): print('upload', u.id) t0 = time.time() doc = json.loads(gzip.decompress(u.payload)) t1 = time.time() print('loaded in', (t1-t0)*1000, 'ms') def cb(el): if 'compactVideoRenderer' in el: src_id = el['compactVideoRenderer']['navigationEndpoint']['watchEndpoint']['videoId'] title = el['compactVideoRenderer']['title']['simpleText'] print('found vid:', src_id, title) v = Video.query.filter_by(src='yt', src_id=src_id).first() if v is None:
def get_face_path(face_id): with app.app_context(): face = db.session.query(Face.id, Face.path).filter( Face.is_train == 0, Face.id == face_id).first() return face.path
def __call__(self, *args, **kwargs): with app.app_context(): return TaskBase.__call__(self, *args, **kwargs)
def ws_stop(): with app.app_context(): current_app.gol.stop()
def test_getiter(): with app.app_context(): str = current_app.gol.get_step() emit('update', str)
#!usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'LiTian' # from gevent import monkey # monkey.patch_all() from web import app app = app app.app_context().push() if __name__ == '__main__': ip = '0.0.0.0' port = 5000 # from web.tools.cookie_factory import recreate_database_and_admin # recreate_database_and_admin(app, admin_password='******', delect_table=True) # 重建数据库和创建管理员 # 直接运行时,gevent所需, from gevent import pywsgi server = pywsgi.WSGIServer((ip, port), app) print('运行web服务:' + ip + ':' + str(port)) server.serve_forever()