Ejemplo n.º 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'])
Ejemplo n.º 2
0
    def test_http_auth_config(self):
        """Test HttpAuthConfig class."""
        cfg = Config()
        self.assertFalse(cfg.has_attr('httpauth'))

        cfg = Config(basicauth=False)
        self.assertFalse(cfg.has_attr('httpauth'))

        cfg = Config(httpauth=True)
        self.assertTrue(cfg.has_attr('httpauth'))
Ejemplo n.º 3
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')
Ejemplo n.º 4
0
    def test_bootstrap_config(self):
        """Test BootstrapConfig class."""
        cfg = Config()
        self.assertFalse(cfg.has_attr('bootstrap'))

        cfg = Config(bootstrap=False)
        self.assertFalse(cfg.has_attr('bootstrap'))

        cfg = Config(bootstrap=True)
        self.assertTrue(cfg.has_attr('bootstrap'))
Ejemplo n.º 5
0
    def test_index_blueprint_config(self):
        """Test IndexConfig class."""
        cfg = Config()
        self.assertFalse(cfg.has_attr('index'))

        cfg = Config(index=False)
        self.assertFalse(cfg.has_attr('index'))

        cfg = Config(index=True)
        self.assertTrue(cfg.has_attr('index'))
Ejemplo n.º 6
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)
Ejemplo n.º 7
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), '')
Ejemplo n.º 8
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'])
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
 def setUp(self):
     """Initialize tests."""
     app = create_app(
         Config(
             bootstrap=True,
             db=True,
             httpauth=True,
             index=True,
         ))
     app.app_context().push()
Ejemplo n.º 11
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),
Ejemplo n.º 12
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']
Ejemplo n.º 13
0
 def test_basic_config(self):
     """Test BasicConfig class."""
     cfg = Config()
     self.assertTrue(cfg.has_attr('basic'))