Пример #1
0
def app():
    """Creates an app with a JSON enabled test client"""

    application = create_app()
    application.test_client_class = JSON_Client
    application.response_class = Load_JSON_Response
    return application
def migrations_database():
    app = create_app()
    database_url = app.config["SQLALCHEMY_DATABASE_URI"]
    database_url = replace(database_url, database="test_migrations")

    with disable_logging():
        create_empty_database(database_url)

    yield database_url

    with disable_logging():
        drop_database(database_url)
Пример #3
0
def run(ctx, config='dev'):
    """run the application
    config : ['prod','dev']
    """
    print('run test suite in {} mode'.format(config))
    # if the following import is called before installing requirements,
    # it would crash the file
    from service import create_app
    app = create_app()
    if config == 'prod':
        app.run(host='0.0.0.0')
    elif config == 'dev':
        app.run(debug=True)
def _database():
    app = create_app()
    database_url = app.config["SQLALCHEMY_DATABASE_URI"]
    with disable_logging():
        create_empty_database(database_url)
        engine = create_engine(app.config)
        Base.metadata.create_all(engine)

    yield app.config, engine

    with disable_logging():
        engine.dispose()
        drop_database(database_url)
Пример #5
0
def app():
    """Create and configure a new app instance for each test."""
    # create a temporary file to isolate the database for each test
    db_fd, db_path = tempfile.mkstemp()
    # create the app with common test config
    app = create_app({"TESTING": True, "DATABASE": db_path})

    # create the database and load test data
    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
def two_databases():
    app = create_app()
    database_url = app.config["SQLALCHEMY_DATABASE_URI"]
    migrations_url = replace(database_url, database="migrations_tdb")
    create_all_url = replace(database_url, database="create_all_tdb")
    with disable_logging():
        create_empty_database(migrations_url)
        create_empty_database(create_all_url)

    yield create_all_url, migrations_url

    # dispose sqlbag engines which has been created internally
    # in order to be able to drop databases
    for session in SCOPED_SESSION_MAKERS.values():
        session.bind.dispose()
    SCOPED_SESSION_MAKERS.clear()

    with disable_logging():
        drop_database(migrations_url)
        drop_database(create_all_url)
Пример #7
0
import service
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Service App')
    parser.add_argument('--instance',
                        help='service instance directory',
                        type=str,
                        required=True)

    args = parser.parse_args()

    app = service.create_app(args.instance)
    app.run('0.0.0.0')
Пример #8
0
"""
MIT License

Copyright (c) 2019 Jordan Maxwell
Written 10/20/2019

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

from service import create_app
import os

# Create app
app = create_app(env=os.environ.get('ENVIRONMENT', 'prod'))
Пример #9
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
Пример #10
0
import service
import config

app = service.create_app(config)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)
Пример #11
0
 def setUp(self):
     self.app = create_app()
     self.client = self.app.test_client()
Пример #12
0
import os

from service import create_app

env = os.environ.get('API_ENV', 'dev')
app = create_app('config.%sConfig' % env.capitalize())


if __name__ == '__main__':
    app.run()
from aiohttp import web
from os.path import join, dirname, realpath
from service import create_app
"""
This is the entry point for the request. Basic server initialization code.
"""

root_dir = dirname(realpath(__file__))
app = create_app(root_dir)

if __name__ == "__main__":
    web.run_app(app, host="0.0.0.0", port=8000)
from service import create_app,config

# 플라스크 어플리케이션 서버 생성
application = create_app()       ## 보안 절차 !  

# 구동
if __name__ == '__main__':
    print(application.config['TEST_PORT'])
    print(application.config['REAL_URL'])
    host = None
    port = None
    if application.config['ENV'] == 'production': ## 상용
        host=application.config['REAL_URL']
        port=application.config['REAL_PORT']
    else: ## 개발/테스트
        host=application.config['TEST_URL']
        port=application.config['TEST_PORT']     ## IP나 Port를 자동으로 설정할 수 있게 설정 ( 환경 변수로 __init__ line 16)
    application.run(
        host=host,
        port=port,                        ## 실제 배포한다는 가정을 하면 ~
        debug=application.config['SERVER_RUN_MODE_DEBUG'])
Пример #15
0
def main():
    """
    Main entry point for the application
    """

    # CLI arguments
    parser = argparse.ArgumentParser(description='Linkify Server')
    parser.add_argument('port',
                        metavar='Port',
                        type=int,
                        nargs='?',
                        default=8080,
                        help='port to run the application')
    parser.add_argument('--env',
                        '-e',
                        dest='environment',
                        action='store',
                        default='dev',
                        help='type of environment')
    parser.add_argument('--tornado',
                        '-t',
                        dest='tornado',
                        action='store_true',
                        help='run the server as tornado wsgi')
    parser.add_argument('--ssl',
                        '-s',
                        dest='use_ssl',
                        action='store_true',
                        help='run server with ssl certs')
    parser.add_argument('--ssl-certfile',
                        '-c',
                        dest='ssl_certfile',
                        action='store',
                        default='server.crt',
                        help='ssl certificate file')
    parser.add_argument('--ssl-keyfile',
                        '-k',
                        dest='ssl_keyfile',
                        action='store',
                        default='server.key',
                        help='ssl key file')
    parser.add_argument('--upload-s3',
                        '-s3',
                        dest='upload_s3',
                        action='store_true',
                        help='deploy s3 assets to AWS')
    parser.add_argument('--create-tables',
                        '-ct',
                        dest='create_tables',
                        action='store_true',
                        help='creates dynamodb tables in AWS')
    args = parser.parse_args()

    # Configure logging
    log_level = logging.INFO if args.environment == 'prod' else logging.DEBUG
    logging.basicConfig(format='[%(levelname)s]: %(message)s', level=log_level)

    # Create the app
    logging.info('Creating application environment: %s' % args.environment)
    app = create_app(env=args.environment)

    # Start app in tornado wsgi container
    if args.tornado:

        if HAS_TORNADO:
            try:
                logging.info('Starting Tornado Server on port %d' % args.port)
                if args.use_ssl:
                    ssl_options = {
                        'certfile': os.path.join(args.ssl_certfile),
                        'keyfile': os.path.join(args.ssl_keyfile)
                    }
                else:
                    ssl_options = None

                http_server = HTTPServer(WSGIContainer(app),
                                         ssl_options=ssl_options)
                http_server.listen(args.port)
                IOLoop.instance().start()
            except KeyboardInterrupt as e:
                logging.info('Stopping Tornado Server by Ctrl+C')
        else:
            logging.warning(
                'Failed to start Tornado server. Tornado not installed')
    elif args.upload_s3:
        logging.info('Uploading to S3...')
        import flask_s3
        flask_s3.create_all(app)
        logging.info('Upload complete.')
    elif args.create_tables:
        logging.info('Creating Dynamodb Tables')
        from service.models import create_tables
        create_tables()
        logging.info('Table creation complete')
    else:
        logging.info('Starting Flask Internal (dev) Server')
        app.run(port=args.port)
        logging.info('Stopping Flask Internal (dev) Server')

    logging.info('Shutting down...')
    return 0
Пример #16
0
import os
import unittest
from flask import current_app
from flask_testing import TestCase
from service import create_app

app = create_app()


class TestDevelopmentConfig(TestCase):
    def create_app(self):
        app.config.from_object('service.config.DevelopmentConfig')
        return app

    def test_app_is_development(self):
        self.assertEqual(app.config['SECRET_KEY'],
                         os.environ.get('SECRET_KEY'))
        self.assertFalse(current_app is None)
        self.assertEqual(app.config['SQLALCHEMY_DATABASE_URI'],
                         os.environ.get('DATABASE_URL'))
        self.assertTrue(app.config['DEBUG_TB_ENABLED'])


class TestTestingConfig(TestCase):
    def create_app(self):
        app.config.from_object('service.config.TestingConfig')
        return app

    def test_app_is_testing(self):
        self.assertEqual(app.config['SECRET_KEY'], "testing-and-thats-it")
        self.assertTrue(app.config['TESTING'])
Пример #17
0
from flask.ext.script import Manager, Shell, prompt_bool
from flask.ext.migrate import MigrateCommand
from service import db, config, create_app, models
from subprocess import Popen, call

"Main python process which allows database creation/modification and executes flask server"


app = create_app(config.DevelopmentConfig)

manager = Manager(app, with_default_commands=False)
manager.add_command('db', MigrateCommand)
manager.add_command('shell', Shell())


@manager.command
def build():
    "Builds frontend dependencies"
    call('gulp default', cwd='service/frontend', shell=True)


@manager.command
def run():
    "Runs the Flask development server i.e. app.run()"
    Popen('gulp', cwd='service/frontend', shell=True)
    app.run(host='localhost', port=5000)


@MigrateCommand.command
def create():
    "Creates database tables from sqlalchemy models"
Пример #18
0
from service import create_app, config

# 플라스크 어플리케이션 서버 생성
application = create_app()

# 구동 
if __name__ == '__main__':
    print(application.config['TEST_PORT'])
    print(application.config['TEST_URL'])
    host = None
    port = None
    if application.config['ENV'] == 'production': #상용
        host = application.config['REAL_URL']
        port = application.config['REAL_PORT']
    else : #개발, 테스트
        host = application.config['TEST_URL']
        port = application.config['TEST_PORT']
        
    application.run(
        host =host,
        port =3000,
        debug=application.config['SERVER_RUN_MODE_DEBUG'])
Пример #19
0
from alembic import context

from service import create_app
from core.database import Base

config = context.config


target_metadata = Base.metadata
app_config = create_app().config
if not config.get_main_option("sqlalchemy.url"):
    config.set_main_option("sqlalchemy.url", app_config["SQLALCHEMY_DATABASE_URI"])
Пример #20
0
def app(database, config):
    app = create_app(config)
    with app.app_context():
        yield app
Пример #21
0
# -*- coding: utf-8 -*-
import datetime as dt

from service import create_app, create_celery

app = create_app(config='config.py')
celery = create_celery(app)

celery.start()
Пример #22
0
from flask.ext.script import Manager
from service import create_app

app = create_app()
manager = Manager(app)

if __name__ == '__main__':
    manager.run()