Exemple #1
0
    def test_init_app_wrong_url(self):
        self.app.extensions.pop('redis')
        self.app.config['REDIS_URL'] = 'redis://wrong-host:8080/9'

        redis = Redis()
        redis.init_app(self.app)
        self.assertRaises(ConnectionError, redis.ping)
Exemple #2
0
    def test_custom_behaviour_url_init_app(self):
        app.config['REDIS_URL'] = 'redis://wrong-host:8080/0'

        obj = Redis()
        self.assertRaises(AttributeError, obj.ping)

        obj.init_app(app)
        self.assertRaises(ConnectionError, obj.ping)
Exemple #3
0
    def test_init_app(self):
        self.assertIn('redis', self.app.extensions)
        self.app.extensions.pop('redis')

        redis = Redis()
        self.assertFalse(hasattr(redis, 'ping'))
        redis.init_app(self.app)
        redis.ping()
Exemple #4
0
    def test_config_prefix_wrong_url(self):
        self.app.config['REDIS2_URL'] = 'redis://wrong-host:8080/9'
        redis = Redis(self.app, 'REDIS2')
        self.assertRaises(ConnectionError, redis.ping)

        self.app.config['REDIS3_URL'] = 'redis://wrong-host:8080/9'
        redis = Redis()
        redis.init_app(self.app, 'REDIS3')
        self.assertRaises(ConnectionError, redis.ping)
Exemple #5
0
    def test_config_prefix_url(self):
        self.app.config['REDIS2_URL'] = 'redis://localhost:6379/0'
        redis = Redis(self.app, 'REDIS2')
        redis.ping()

        self.app.config['REDIS3_URL'] = 'redis://127.0.0.1:6379/0'
        redis = Redis()
        redis.init_app(self.app, 'REDIS3')
        redis.ping()
Exemple #6
0
    def test_custom_behaviour_init_app(self):
        app.config['REDIS_HOST'] = 'wrong-host'
        app.config['REDIS_PORT'] = 8080
        app.config['REDIS_DB'] = 0

        obj = Redis()
        self.assertRaises(AttributeError, obj.ping)

        obj.init_app(app)
        self.assertRaises(ConnectionError, obj.ping)
Exemple #7
0
    def test_init_app_wrong_config(self):
        self.app.extensions.pop('redis')

        self.app.config['REDIS_HOST'] = 'wrong-host'
        self.app.config['REDIS_PORT'] = 8080
        self.app.config['REDIS_DB'] = 9

        redis = Redis()
        redis.init_app(self.app)
        self.assertRaises(ConnectionError, redis.ping)
Exemple #8
0
    def test_config_prefix(self):
        redis = Redis(self.app, 'REDIS_BACKUP')
        self.assertIn('REDIS_BACKUP', self.app.extensions['redis'])
        redis.ping()
        self.assertRaises(ValueError, Redis, self.app, 'REDIS_BACKUP')

        redis = Redis()
        redis.init_app(self.app, 'REDIS_SLAVE')
        self.assertIn('REDIS_SLAVE', self.app.extensions['redis'])
        redis.ping()
        self.assertRaises(ValueError, redis.init_app, self.app, 'REDIS_SLAVE')
Exemple #9
0
    def test_init_app_url(self):
        self.app.extensions.pop('redis')

        self.app.config.pop('REDIS_HOST')
        self.app.config.pop('REDIS_PORT')
        self.app.config.pop('REDIS_DB')

        self.app.config['REDIS_URL'] = 'redis://localhost:6379/0'
        redis = Redis()
        redis.init_app(self.app)
        redis.ping()
Exemple #10
0
    def test_default_behaviour_url_init_app(self):
        host = app.config.pop('REDIS_HOST')
        port = app.config.pop('REDIS_PORT')
        db = app.config.pop('REDIS_DB')

        app.config['REDIS_URL'] = 'redis://%s:%d/%d' % (host, port, db)

        obj = Redis()
        self.assertRaises(AttributeError, obj.ping)

        obj.init_app(app)
        obj.ping()
if not app.config['DEBUG']:
    import logging
    from logging.handlers import RotatingFileHandler

    file_handler = RotatingFileHandler(os.path.join(os.path.split(os.path.abspath(__file__))[0], 'log', 'flask.log'),
                                       maxBytes=1024 * 1024, backupCount=5, encoding="UTF-8")
    file_handler.setLevel(logging.WARNING)
    app.logger.addHandler(file_handler)

# Register template filters
app.jinja_env.filters['datetime_to_seconds'] = datetime_to_seconds
app.jinja_env.filters['seconds_to_datetime'] = seconds_to_datetime

# Setup Redis connection
redis = Redis()
redis.init_app(app)


@app.route('/', methods=['GET'])
def handle_list_events():
    """
    Display frontpage form
    """
    upcoming_events = get_upcoming_events()
    ongoing_events = get_ongoing_events()

    # Setup Are You A Human check
    ayah.configure(app.config['ARE_YOU_HUMAN_PUBLISHER_KEY'], app.config['ARE_YOU_HUMAN_SCORING_KEY'])
    ayah_html = ayah.get_publisher_html()

    return render_template('index.html', upcoming_events=upcoming_events, ongoing_events=ongoing_events,