def external_app(): """Create an external application for testing. Unlike app_context above, this function spawns a new process. This gives up a service that also includes Werkzeug. :return: (app, root), where app is the application and root is the top-level url. """ app = app_factory(testing=True) queue = Queue() server = Process(target=spawn_external, args=(app, queue)) server.start() root = queue.get() # It is likely that the app is not ready to process queries yet. Loop # with a timeout until it is. # See https://stackoverflow.com/questions/30548758/how-do-i-know-that-the-flask-application-is-ready-to-process-the-requests-withou for _ in range(10): try: requests.get(root, timeout=2) break except requests.exceptions.ConnectionError: pass else: raise RuntimeError("Unable to connect to app on %s" % root) yield app, root server.terminate() server.join()
def setUp(self): app = app_factory(fakeredis.FakeStrictRedis()) app.config.update( SERVER_NAME='127.0.0.1:5000', IIIF_SERVER='iiifhawk.klokantech.com' ) self.app = app.test_client() app.extensions['redis'].set('item_id@test_id', json.dumps({'url': ['http://unittest_url.org', 'http://unittest_url2.org'], 'title': 'Unittest title', 'creator': 'Unittest creator', 'source': 'http://unittest_source.org','institution': 'Unittest institution', 'institution_link': 'http://unittest_institution_link.org', 'license': 'http://unittest_license_link.org', 'description': 'Unittest description', 'image_meta': {'http://unittest_url.org': {'width': 1000, 'height': 1000, 'filename': 'test_id.jp2', 'order': 0}, 'http://unittest_url2.org': {'width': 100, 'height': 100, 'filename': 'test_id/1.jp2', 'order': 1}}, 'lock': False}))
def migration(request): """ Runs migrations before all tests and delete database at the end. """ api, app = app_factory() with app.app_context(): remove_test_db() run_migrations() request.addfinalizer(app_context(remove_test_db))
def setUp(self): app = app_factory(fakeredis.FakeStrictRedis()) app.config.update(SERVER_NAME='127.0.0.1:5000', IIIF_SERVER='iiifhawk.klokantech.com') self.app = app.test_client() app.extensions['redis'].set( 'item_id@test_id', json.dumps({ 'url': ['http://unittest_url.org', 'http://unittest_url2.org'], 'title': 'Unittest title', 'creator': 'Unittest creator', 'source': 'http://unittest_source.org', 'institution': 'Unittest institution', 'institution_link': 'http://unittest_institution_link.org', 'license': 'http://unittest_license_link.org', 'description': 'Unittest description', 'image_meta': { 'http://unittest_url.org': { 'width': 1000, 'height': 1000, 'filename': 'test_id.jp2', 'order': 0 }, 'http://unittest_url2.org': { 'width': 100, 'height': 100, 'filename': 'test_id/1.jp2', 'order': 1 } }, 'lock': False }))
# -*- coding: utf-8 -*- import sys import os from aiohttp.web import run_app from pathlib import Path src_path = str(Path(__file__).resolve().parent.joinpath('src')) sys.path.append(src_path) # --------------------------------------------------------- import asyncio import uvloop from app import app_factory asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.set_debug(True) run_app(app_factory(), host='0.0.0.0', port=5000)
''' To run the development version of this web application, start MongoDB (by running mongodb-path/mongod) and then run this module. The development server will serve webpages up at: http://localhost:5000/. Created on Dec 31, 2013 @author: kvlinden ''' from app import app_factory from utils.config import DevelopmentConfig config = DevelopmentConfig() app = app_factory(config) if __name__ == '__main__': app.run(config.URL) # Remove the host argument to default to 127.0.0.1.
def current_app(): from app import app_factory api, app = app_factory() return app
"""Script which starts embed aplication""" import os from app import app_factory app = app_factory() if __name__ == "__main__": app.run(host=app.config['HOST'], port=app.config['PORT'])
def setUp(self): self.app = app_factory(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.create_all()
#!/usr/bin/env python # -*- coding: utf-8 -*- from app import app_factory if __name__ == '__main__': app_factory().run()
#!/usr/bin/env python3.4 import os import sys from subprocess import call from flask_script import Manager from flask_migrate import MigrateCommand from config import config from app import app_factory, db app = app_factory('development') # TODO implement env variables manager = Manager(app) # The migrate comand manager.add_command('db', MigrateCommand) @manager.command def test(): call(['nosetests', '-v', '--with-coverage', '--cover-package=app', '--cover-branches', '--cover-erase', '--cover-html', '--cover-html-dir=cover']) @manager.command def createsuperuser(): """ Creates a superuser. """ from getpass import getpass
#!/usr/bin/env python3 import getpass import os import subprocess from flask.ext import script import flask from app import models import config import app _app = app.app_factory(config.config[os.getenv("AC_CONFIG") or "development"]) manager = script.Manager(_app) class _AddAPIUser(script.Command): option_list = script.Option("username") def __init__(self, app): super(script.Command.__init__()) self.app = app def run(self, username): while True: password = getpass.getpass(prompt="Enter Password: "******"Confirm Password: "******"Passwords did not match. Please try again.")
#!/usr/bin/env python3.4 import os import sys from subprocess import call from flask_script import Manager from flask_migrate import MigrateCommand from config import config from app import app_factory, db app = app_factory('development') # TODO implement env variables manager = Manager(app) # The migrate comand manager.add_command('db', MigrateCommand) @manager.command def test(): call([ 'nosetests', '-v', '--with-coverage', '--cover-package=app', '--cover-branches', '--cover-erase', '--cover-html', '--cover-html-dir=cover' ]) @manager.command def createsuperuser(): """ Creates a superuser.
from app import app_factory import os app = app_factory(os.environ.get("MODE_CONFIG") or "default") if __name__ == "__main__": app.run(host='0.0.0.0')
def app() -> Flask: api, app = app_factory() return app
from app import app_factory import uvicorn app = app_factory() def main(): uvicorn_config = {"host": "127.0.0.1", "port": 5000} uvicorn.run("main:app", **uvicorn_config) if __name__ == '__main__': main()
def create_app(self): app = app_factory(TestingConfig()) mail.init_app(app) return app