コード例 #1
0
    def test_basic_config_in_app(self):
        """Test basic configuration in flask app."""
        app = create_app(Config())
        self.assertTrue(app.config['SECRET_KEY'])
        self.assertFalse(app.config['DEBUG'])

        app = create_app(Config())
        app.config.update(DEBUG=True)
        self.assertTrue(app.config['DEBUG'])
コード例 #2
0
    def test_bootstrap_template(self):
        """Test base.html template when bootstrap not exists."""
        app = create_app(Config())
        with app.app_context():
            self.assertEqual(render_template('base.html'), '')

        app = create_app(Config(bootstrap=True))
        with app.app_context():
            with self.assertRaises(RuntimeError):
                render_template('base.html')
コード例 #3
0
    def test_http_auth(self):
        """Test http auth."""
        app = create_app(Config(index=True))
        app = app.test_client()
        rv = app.get('/_')
        self.assertEqual(rv.status_code, 200)

        app = create_app(Config(index=True, httpauth=True))
        app = app.test_client()
        rv = app.get('/_')
        self.assertEqual(rv.status_code, 401)
コード例 #4
0
    def test_index_blueprint_route(self):
        """Test index blueprint route."""
        app = create_app(Config())
        app = app.test_client()
        rv = app.get('/_')
        self.assertEqual(rv.status_code, 404)

        app = create_app(Config(index=True))
        app = app.test_client()
        rv = app.get('/_')
        self.assertEqual(rv.get_data(as_text=True), '')
コード例 #5
0
    def test_bootstrap_config_in_app(self):
        """Test bootstrap configuration in flask app."""
        app = create_app(Config())
        with self.assertRaises(KeyError):
            app.config['BOOTSTRAP_SERVE_LOCAL']
            app.config['BOOTSTRAP_ENABLED']

        app = create_app(Config(bootstrap=False))
        with self.assertRaises(KeyError):
            app.config['BOOTSTRAP_SERVE_LOCAL']
            app.config['BOOTSTRAP_ENABLED']

        app = create_app(Config(bootstrap=True))
        self.assertTrue(app.config['BOOTSTRAP_SERVE_LOCAL'])
        self.assertTrue(app.config['BOOTSTRAP_ENABLED'])
コード例 #6
0
    def test_http_auth_config_in_app(self):
        """Test http auth configuration in flask app."""
        app = create_app(Config())
        with self.assertRaises(KeyError):
            app.config['BASIC_AUTH_USERNAME']
            app.config['BASIC_AUTH_PASSWORD']
            app.config['BASIC_AUTH_FORCE']

        app = create_app(Config(httpauth=False))
        with self.assertRaises(KeyError):
            app.config['BASIC_AUTH_USERNAME']
            app.config['BASIC_AUTH_PASSWORD']
            app.config['BASIC_AUTH_FORCE']

        app = create_app(Config(httpauth=True))
        self.assertTrue(app.config['BASIC_AUTH_USERNAME'])
        self.assertTrue(app.config['BASIC_AUTH_PASSWORD'])
        self.assertTrue(app.config['BASIC_AUTH_FORCE'] in (True, False))
コード例 #7
0
 def setUp(self):
     """Initialize tests."""
     app = create_app(
         Config(
             bootstrap=True,
             db=True,
             httpauth=True,
             index=True,
         ))
     app.app_context().push()
コード例 #8
0
ファイル: flask_test_case.py プロジェクト: eunki7/scrapymon
    def setUp(self):
        self.app = create_app()
        self.app.testing = True
        self.client = self.app.test_client()

        # Update to in-memory db for test
        self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'

        # Suggested to be after modifying app configurations
        self.app_context = self.app.test_request_context()
        self.app_context.push()

        # Initialize db
        db.create_all(bind=None)
コード例 #9
0
import os
import argparse
import logging

from gevent.pywsgi import WSGIServer

from scrapymon.config import Config
from scrapymon.app import create_app

app = create_app(Config(
    bootstrap=True,
    httpauth=True,
    index=True,
))


def main():
    """Entrypoint for script or exe."""
    # Convenient reference
    app_name = 'scrapymon'

    # Customized HelpFomatter without prefix.
    class CustomHelpFormatter(argparse.HelpFormatter):
        def add_usage(self, usage, actions, groups, prefix=''):
            super().add_usage(usage, actions, groups, prefix=prefix)

    # Application usage.
    usage_ = '\n'.join([
        'Usage: {} [--host=<host>] [--port=<port>] '
        '[--server=<address_with_port>] '
        '[--auth=<username:password>'.format(app_name),
コード例 #10
0
 def test_index_blueprint_config_in_app(self):
     """Test index blueprint configuration in app."""
     app = create_app(Config(index=True))
     with self.assertRaises(KeyError):
         app.config['index_blueprint_prefix']