Python app.create_app() Examples

The following are 30 code examples of app.create_app(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module app , or try the search function .
Example #1
Source File: conftest.py    From flask-rest-template with The Unlicense 7 votes vote down vote up
def app(request):
    """Creates a flask.Flask app with the 'development' config/context.

    :request: test request
    :returns: flask.Flask object

    """

    app = create_app('development')
    ctx = app.app_context()

    ctx.push()

    def tear_down():
        ctx.pop()

    request.addfinalizer(tear_down)
    return app 
Example #2
Source File: manage.py    From myblog with GNU General Public License v3.0 7 votes vote down vote up
def create_app():
    app = _create_app()

    @app.shell_context_processor
    def make_shell_context():
        return dict(
            app=app,
            db=db,
            create_db=create_db,
            drop_db=drop_db,
            UserModel=UserModel,
            create_user=create_user,
            PostModel=PostModel,
            TagModel=TagModel
        )

    print(app.url_map)
    print(app.config)
    return app 
Example #3
Source File: test_client.py    From circleci-demo-python-flask with MIT License 6 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles()
        self.client = self.app.test_client(use_cookies=True) 
Example #4
Source File: test_integration.py    From restful-todo with GNU General Public License v2.0 6 votes vote down vote up
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()


            db.drop_all()
            db.create_all()
            todo = Todo(title='title1', body='body1')
            db.session.add(todo)
            db.session.commit()


            threading.Thread(target=cls.app.run).start() 
Example #5
Source File: test_basics.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #6
Source File: salted_session.py    From elearning with MIT License 5 votes vote down vote up
def setUp(self):
        self.init()
        self.app = create_app()
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client(allow_subdomain_redirects=True) 
Example #7
Source File: main_test.py    From elearning with MIT License 5 votes vote down vote up
def setUp(self):
        self.init()
        self.app = create_app()
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client(allow_subdomain_redirects=True) 
Example #8
Source File: __init__.py    From tutorial-flask with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app(settings_module="config.testing")
        self.client = self.app.test_client()

        # Crea un contexto de aplicaciĆ³n
        with self.app.app_context():
            # Crea las tablas de la base de datos
            db.create_all()
            # Creamos un usuario administrador
            BaseTestClass.create_user('admin', 'admin@xyz.com', '1111', True)
            # Creamos un usuario invitado
            BaseTestClass.create_user('guest', 'guest@xyz.com', '1111', False) 
Example #9
Source File: test_basics.py    From flask-webcast with MIT License 5 votes vote down vote up
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() 
Example #10
Source File: test_user_model.py    From flask-blog with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #11
Source File: test_user_model.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles() 
Example #12
Source File: test_bucketlist.py    From flask-rest-api with MIT License 5 votes vote down vote up
def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client
        self.bucketlist = {'name': 'Go to Borabora for vacay'}

        # binds the app to the current context
        with self.app.app_context():
            # create all tables
            db.session.close()
            db.drop_all()
            db.create_all() 
Example #13
Source File: test_selenium.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='john@example.com',
                         username='john', password='cat',
                         role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1) 
Example #14
Source File: test_client.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles()
        self.client = self.app.test_client(use_cookies=True) 
Example #15
Source File: test_auth.py    From flask-rest-api with MIT License 5 votes vote down vote up
def setUp(self):
        """Set up test variables."""
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client
        self.user_data = {
            'email': 'test@example.com',
            'password': 'test_password'
        }

        with self.app.app_context():
            # create all tables
            db.session.close()
            db.drop_all()
            db.create_all() 
Example #16
Source File: conftest.py    From fitbit-api-example-python with Apache License 2.0 5 votes vote down vote up
def flask_app(monkeypatch):
    monkeypatch.setenv('FLASK_CONFIG', 'testing')
    f_app = create_app(config['testing'])
    db.create_all()
    yield f_app
    db.session.close()
    db.drop_all() 
Example #17
Source File: test_user_model.py    From oreilly-intro-to-flask-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()
        db.create_all() 
Example #18
Source File: tests.py    From oreilly-flask-apis-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.ctx = self.app.app_context()
        self.ctx.push()
        db.drop_all()
        db.create_all()
        u = User(username=self.default_username)
        u.set_password(self.default_password)
        db.session.add(u)
        db.session.commit()
        self.client = TestClient(self.app, u.generate_auth_token(), '') 
Example #19
Source File: test_client.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles()
        self.client = self.app.test_client(use_cookies=True) 
Example #20
Source File: test_selenium.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='john@example.com',
                         username='john', password='cat',
                         role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1) 
Example #21
Source File: test_basics.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #22
Source File: test_user_model.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles() 
Example #23
Source File: test_api.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles()
        self.client = self.app.test_client() 
Example #24
Source File: test_apis.py    From restful-todo with GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        self.client = self.app.test_client() 
Example #25
Source File: test_skeleton.py    From restful-todo with GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #26
Source File: test_basics.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #27
Source File: test_user_model.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #28
Source File: email.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def send_email(recipient, subject, template, **kwargs):
    app = create_app(os.getenv('FLASK_CONFIG') or 'default')
    with app.app_context():
        msg = Message(
            app.config['EMAIL_SUBJECT_PREFIX'] + ' ' + subject,
            sender=app.config['EMAIL_SENDER'],
            recipients=[recipient])
        msg.body = render_template(template + '.txt', **kwargs)
        msg.html = render_template(template + '.html', **kwargs)
        mail.send(msg) 
Example #29
Source File: api_base.py    From braindump with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        self.client = self.app.test_client() 
Example #30
Source File: client_base.py    From braindump with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = app.create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        app.db.create_all()
        self.client = self.app.test_client()