Esempio n. 1
0
 def test__cache_config(self):
     """ Test that cache headers are set correctly. """
     new_app = Flask("test_cache_param")
     new_app.config['FLASKS3_USE_CACHE_CONTROL'] = True
     new_app.config['FLASKS3_CACHE_CONTROL'] = '3600'
     flask_s3.FlaskS3(new_app)
     expected = {'Cache-Control': '3600'}
     self.assertEqual(expected, new_app.config['FLASKS3_HEADERS'])
Esempio n. 2
0
def get_app(config=None):
    """App factory.

    :param config: configuration that can override config from `settings.py`
    :return: a new SuperdeskEve app instance
    """
    if config is None:
        config = {}

    config['APP_ABSPATH'] = os.path.abspath(os.path.dirname(__file__))

    for key in dir(settings):
        if key.isupper():
            config.setdefault(key, getattr(settings, key))

    media_storage = None
    if config['AMAZON_CONTAINER_NAME']:
        from superdesk.storage.amazon.amazon_media_storage import AmazonMediaStorage
        media_storage = AmazonMediaStorage

    config['DOMAIN'] = {}

    # Create superdesk app instance.
    app = superdesk_app(config, media_storage, init_elastic=True)

    # Add custom jinja2 template loader.
    custom_loader = jinja2.ChoiceLoader(
        [jinja2.FileSystemLoader('superdesk/templates'), app.jinja_loader])
    app.jinja_loader = custom_loader

    # Caching.
    app.cache = Cache(app, config={'CACHE_TYPE': 'simple'})
    app.blog_cache = BlogCache(cache=app.cache)

    # Amazon S3 support.
    s3 = flask_s3.FlaskS3()
    s3.init_app(app)

    # Embed feature.
    app.register_blueprint(embed_blueprint)

    # Embed bloglist.
    app.register_blueprint(bloglist_assets_blueprint)
    app.register_blueprint(bloglist_blueprint)

    # Analytics.
    app.register_blueprint(analytics_blueprint)

    # Syndication feature.
    app.register_blueprint(producers_blueprint)
    app.register_blueprint(consumers_blueprint)
    app.register_blueprint(syndication_blueprint)
    app.register_blueprint(syndication_blogs_blueprint)

    # Marketplace.
    app.register_blueprint(marketers_blueprint)

    return app
Esempio n. 3
0
    def test__url_for_uses_prefix(self, mock_current_app):
        bucket_path = 'foo.s3.amazonaws.com'
        flask_s3.FlaskS3(self.app)
        mock_current_app.config = self.app.config
        mock_bind = mock_current_app.url_map.bind

        flask_s3.url_for('static', **{'filename': 'test_file.txt'})
        self.assertEqual(mock_bind.call_args_list, [call(bucket_path, url_scheme='https')])

        for supported_prefix in ['bar', '/bar', 'bar/', '/bar/']:
            mock_bind.reset_mock()
            self.app.config['FLASKS3_PREFIX'] = supported_prefix
            flask_s3.url_for('static', **{'filename': 'test_file.txt'})
            expected_path = '%s/%s' % (bucket_path, 'bar')
            self.assertEqual(mock_bind.call_args_list,
                             [call(expected_path, url_scheme='https')])
Esempio n. 4
0
def get_app(config=None):
    """App factory.

    :param config: configuration that can override config from `settings.py`
    :return: a new SuperdeskEve app instance
    """
    if config is None:
        config = {}

    config['APP_ABSPATH'] = os.path.abspath(os.path.dirname(__file__))

    for key in dir(settings):
        if key.isupper():
            config.setdefault(key, getattr(settings, key))

    media_storage = None
    if config['AMAZON_CONTAINER_NAME']:
        from superdesk.storage.amazon.amazon_media_storage import AmazonMediaStorage
        media_storage = AmazonMediaStorage

    config['DOMAIN'] = {}

    app = superdesk_app(config, media_storage)

    custom_loader = jinja2.ChoiceLoader(
        [jinja2.FileSystemLoader('superdesk/templates'), app.jinja_loader])
    app.jinja_loader = custom_loader

    # cache
    app.cache = Cache(app, config={'CACHE_TYPE': 'simple'})
    app.blog_cache = BlogCache(cache=app.cache)
    # s3
    s3 = flask_s3.FlaskS3()
    s3.init_app(app)
    # embed feature
    app.register_blueprint(embed_blueprint)
    return app
Esempio n. 5
0
def get_app(config=None):
    """App factory.

    :param config: configuration that can override config from `settings.py`
    :return: a new SuperdeskEve app instance
    """
    if config is None:
        config = {}

    config['APP_ABSPATH'] = os.path.abspath(os.path.dirname(__file__))

    for key in dir(settings):
        if key.isupper():
            config.setdefault(key, getattr(settings, key))

    media_storage = None
    if config.get('AMAZON_CONTAINER_NAME'):
        from superdesk.storage.amazon_media_storage import AmazonMediaStorage
        media_storage = AmazonMediaStorage

    config['DOMAIN'] = {}

    # Create superdesk app instance.
    app = superdesk_app(config, media_storage)

    # Add custom jinja2 template loader.
    custom_loader = jinja2.ChoiceLoader(
        [jinja2.FileSystemLoader('superdesk/templates'), app.jinja_loader])
    app.jinja_loader = custom_loader

    # Caching. By default 'simple' cache will be used
    cache_config = {'CACHE_TYPE': settings.LIVEBLOG_CACHE_TYPE}
    if cache_config['CACHE_TYPE'] == 'redis':
        cache_config.update({
            'CACHE_REDIS_URL': settings.LIVEBLOG_CACHE_REDIS_URL,
            'CACHE_KEY_PREFIX': instance_prefix('_lb-cache_')
        })

    app.cache = Cache(app, config=cache_config)
    app.blog_cache = BlogCache(cache=app.cache)

    # Amazon S3 support.
    s3 = flask_s3.FlaskS3()
    s3.init_app(app)

    # Embed feature.
    app.register_blueprint(embed_blueprint)

    # Embed bloglist.
    app.register_blueprint(bloglist_assets_blueprint)
    app.register_blueprint(bloglist_blueprint)

    # Analytics.
    app.register_blueprint(analytics_blueprint)

    # Advertisements.
    app.register_blueprint(advertisements_blueprint)

    # Syndication feature.
    app.register_blueprint(producers_blueprint)
    app.register_blueprint(consumers_blueprint)
    app.register_blueprint(syndication_blueprint)
    app.register_blueprint(syndication_blogs_blueprint)

    # Marketplace.
    app.register_blueprint(marketers_blueprint)

    # Drag and drop
    app.register_blueprint(drag_and_drop_blueprint)

    # New posts endpoint
    app.register_blueprint(blog_posts_blueprint)

    # Video upload endpoint
    app.register_blueprint(video_upload_blueprint)

    return app
Esempio n. 6
0
import flask_s3
from app import create_app

app = create_app()

s3 = flask_s3.FlaskS3(app)

flask_s3.create_all(app)