def test_init_app(app):
    """Initialization."""
    theme = InvenioTheme()
    assert theme.menu is None
    theme.init_app(app)
    assert theme.menu is not None
    assert 'THEME_SITENAME' in app.config
예제 #2
0
def test_init_app(app):
    """Initialization."""
    theme = InvenioTheme()
    assert theme.menu is None
    theme.init_app(app)
    assert theme.menu is not None
    assert 'THEME_SITENAME' in app.config
예제 #3
0
def test_invenio_theme_loading_order():
    """Test base template set correctly by invenio_theme."""
    app = Flask('testapp')
    InvenioAdmin(app)
    assert app.config.get('ADMIN_BASE_TEMPLATE') is None

    app = Flask('testapp')
    InvenioTheme(app)
    InvenioAdmin(app)
    assert app.config.get('ADMIN_BASE_TEMPLATE') is not None

    app = Flask('testapp')
    InvenioAdmin(app)
    InvenioTheme(app)
    assert app.config.get('ADMIN_BASE_TEMPLATE') is not None
예제 #4
0
def test_page_template_blocks(app):
    """Test template blocks in page.html."""
    base_tpl = r"""{% extends 'invenio_theme/page.html' %}
    {% block css %}{% endblock %}
    {% block javascript %}{% endblock %}
    """

    # Test template API
    blocks = [
        'head',
        'head_meta',
        'head_title',
        'head_links',
        'head_links_langs',
        'head_apple_icons',
        'header',
        'body',
        'browserupgrade',
        'page_header',
        'page_body',
        'page_footer',
        'trackingcode',
    ]
    InvenioTheme(app)
    InvenioAssets(app)

    with app.test_request_context():
        assert_template_blocks("invenio_theme/page.html",
                               blocks,
                               base_tpl=base_tpl)
예제 #5
0
def app_frontpage_handler(request):
    """Flask app error handler fixture."""
    app = Flask('myapp')

    # Creation of a fake theme error template file.
    temp_dir = make_fake_template(
        "{% extends 'invenio_theme/page.html' %}"
        "{% block css %}{% endblock %}"
        "{% block javascript %}{% endblock %}"
    )

    # Adding the temporal path to jinja engine.
    app.jinja_loader = jinja2.ChoiceLoader([
        jinja2.FileSystemLoader(temp_dir),
        app.jinja_loader
    ])

    # Setting by default fake.html as a BASE_TEMPLATE
    app.config['BASE_TEMPLATE'] = 'invenio_theme/fake.html'
    app.config['THEME_FRONTPAGE'] = True

    # Tear down method to clean the temp directory.
    def tear_down():
        shutil.rmtree(temp_dir)
    request.addfinalizer(tear_down)

    app.testing = True
    Babel(app)
    InvenioI18N(app)
    InvenioTheme(app)
    InvenioAssets(app)
    return app
예제 #6
0
def app_error_handler(request):
    """Flask app error handler fixture."""
    app = Flask('myapp')

    # Creation of a fake theme error template file.
    temp_dir = tempfile.mkdtemp()
    invenio_theme_dir = os.path.join(temp_dir, 'invenio_theme')
    os.mkdir(invenio_theme_dir)
    fake_file = open(os.path.join(invenio_theme_dir, 'fake.html'), 'w+')
    fake_file.write("{# -*- coding: utf-8 -*- -#}"
                    "<!DOCTYPE html>{% block message %}"
                    "{% endblock message %}")
    fake_file.close()

    # Adding the temporal path to jinja engine.
    app.jinja_loader = jinja2.ChoiceLoader(
        [jinja2.FileSystemLoader(temp_dir), app.jinja_loader])

    # Setting by default fake.html as a THEME_ERROR_TEMPLATE
    app.config['THEME_ERROR_TEMPLATE'] = 'invenio_theme/fake.html'

    # Tear down method to clean the temp directory.
    def tear_down():
        shutil.rmtree(temp_dir)

    request.addfinalizer(tear_down)

    app.testing = True
    Babel(app)
    InvenioTheme(app)
    return app
예제 #7
0
def app_error_handler(request):
    """Flask app error handler fixture."""
    app = Flask("myapp")

    # Creation of a fake theme error template file.
    temp_dir = make_fake_template("{# -*- coding: utf-8 -*- -#}"
                                  "<!DOCTYPE html>{% block message %}"
                                  "{% endblock message %}")
    # Adding the temporal path to jinja engine.
    app.jinja_loader = jinja2.ChoiceLoader(
        [jinja2.FileSystemLoader(temp_dir), app.jinja_loader])

    # Setting by default fake.html as a THEME_ERROR_TEMPLATE
    app.config["THEME_ERROR_TEMPLATE"] = "invenio_theme/fake.html"

    # Tear down method to clean the temp directory.
    def tear_down():
        shutil.rmtree(temp_dir)

    request.addfinalizer(tear_down)

    app.testing = True
    Babel(app)
    InvenioI18N(app)
    InvenioTheme(app)
    return app
예제 #8
0
def test_lazy_bundles(app):
    """Test configurable bundles."""
    InvenioTheme(app)
    InvenioAssets(app)

    with app.app_context():
        from invenio_theme.bundles import admin_lte_css, lazy_skin

        assert str(lazy_skin()) in admin_lte_css.contents
예제 #9
0
def test_base_template_override():
    """Test base template is set up correctly."""
    app = Flask('testapp')
    base_template = 'test_base_template.html'
    app.config['ADMIN_BASE_TEMPLATE'] = base_template
    InvenioTheme(app)
    state = InvenioAdmin(app)
    assert app.config.get('ADMIN_BASE_TEMPLATE') == base_template

    # Force call of before_first_request registered triggers.
    app.try_trigger_before_first_request_functions()
    assert state.admin.base_template == base_template
예제 #10
0
def test_render_template(app):
    """Test ability to render template."""
    # Remove assets to avoid problems compiling them.
    test_tpl = r"""{% extends 'invenio_theme/page.html' %}
    {% block css %}{% endblock %}
    {% block javascript %}{% endblock %}
    """

    InvenioTheme(app)
    InvenioAssets(app)
    with app.test_request_context():
        assert render_template_string(test_tpl)
예제 #11
0
def base_app(instance_path):
    """Flask application fixture."""
    app_ = Flask('testapp', instance_path=instance_path)
    app_.config.update(
        SECRET_KEY='SECRET_KEY',
        TESTING=True,
    )
    Babel(app_)
    InvenioI18N(app_)
    InvenioTheme(app_)
    InvenioAssets(app_)
    WekoRecords(app_)
    return app_
예제 #12
0
def test_settings_template_blocks(app):
    """Test template blocks in page_settings.html."""
    base_tpl = r"""{% extends 'invenio_theme/page_settings.html' %}
    {% block css %}{% endblock %}
    {% block javascript %}{% endblock %}
    """

    blocks = [
        'page_body', 'settings_menu', 'settings_content', 'settings_form'
    ]
    InvenioTheme(app)
    InvenioAssets(app)

    with app.test_request_context():
        assert_template_blocks(
            'invenio_theme/page_settings.html', blocks, base_tpl=base_tpl)
예제 #13
0
def test_header_template_blocks(app):
    """Test template blokcs in header.html."""
    blocks = [
        'navbar',
        'navbar_header',
        'brand',
        'navbar_inner',
        'navbar_right',
        'breadcrumbs',
        'flashmessages',
        'navbar_nav',
    ]
    InvenioTheme(app)
    InvenioAssets(app)
    with app.test_request_context():
        assert_template_blocks("invenio_theme/header.html", blocks)
예제 #14
0
def test_header_template_blocks(app):
    """Test template blokcs in header.html."""
    blocks = [
        'navbar', 'navbar_header', 'brand', 'navbar_inner', 'navbar_right',
        'breadcrumbs', 'flashmessages', 'navbar_nav', 'navbar_search',
    ]
    InvenioTheme(app)
    InvenioAssets(app)
    with app.test_request_context():
        assert_template_blocks('invenio_theme/header.html', blocks)

    app.config.update(dict(THEME_SEARCHBAR=False))
    with app.test_request_context():
        tpl = \
            r'{% extends "invenio_theme/header.html" %}' \
            r'{% block navbar_search %}TPLTEST{% endblock %}'
        assert 'TPLTEST' not in render_template_string(tpl)
예제 #15
0
def test_cover_template_blocks(app):
    """Test template blocks in page.html."""
    base_tpl = r"""{% extends 'invenio_theme/page_cover.html' %}
    {% set panel_title = 'Test' %}
    {% block css %}{% endblock %}
    {% block javascript %}{% endblock %}
    """

    # Test template API
    blocks = [
        'panel', 'page_header', 'page_body', 'page_footer', 'panel_content',
    ]
    InvenioTheme(app)
    InvenioAssets(app)

    with app.test_request_context():
        assert_template_blocks(
            'invenio_theme/page_cover.html', blocks, base_tpl=base_tpl)
예제 #16
0
def app(instance_path, static_folder):
    """Flask application fixture."""
    app = Flask(
        'testapp',
        instance_path=instance_path,
        static_folder=static_folder,
    )
    app.config.from_object(config)
    app.config.update(
        TESTING=True
    )
    InvenioTheme(app)
    InvenioI18N(app)

    @app.route('/')
    def index():
        """Test home page."""
        return render_template('cernopendata_theme/page.html')

    app.register_blueprint(blueprint)
    return app
예제 #17
0
def test_header_template_blocks(app):
    """Test template blokcs in header.html."""
    blocks = [
        "navbar",
        "navbar_header",
        "brand",
        "navbar_inner",
        "navbar_right",
        "breadcrumbs",
        "flashmessages",
        "navbar_nav",
        "navbar_search",
    ]
    InvenioTheme(app)
    InvenioAssets(app)
    with app.test_request_context():
        assert_template_blocks("invenio_theme/header.html", blocks)

    app.config.update(dict(THEME_SEARCHBAR=False))
    with app.test_request_context():
        tpl = (r'{% extends "invenio_theme/header.html" %}'
               r"{% block navbar_search %}TPLTEST{% endblock %}")
        assert "TPLTEST" not in render_template_string(tpl)
예제 #18
0
def test_html_lang(app):
    """Test HTML language attribute."""
    base_tpl = r"""{% extends 'invenio_theme/page.html' %}
    {% block css %}{% endblock %}
    {% block javascript %}{% endblock %}
    """

    @app.route('/index')
    def index():
        """Render default page."""
        return render_template_string(base_tpl)

    InvenioTheme(app)
    InvenioAssets(app)

    with app.test_client() as client:
        response = client.get('/index')
        assert b'lang="en" ' in response.data

        response = client.get('/index?ln=de')
        assert b'lang="de" ' in response.data

        response = client.get('/index?ln=en')
        assert b'lang="en" ' in response.data
예제 #19
0
        and os.environ.get('RECAPTCHA_PRIVATE_KEY') is not None:
    app.config.setdefault('RECAPTCHA_PUBLIC_KEY',
                          os.environ['RECAPTCHA_PUBLIC_KEY'])
    app.config.setdefault('RECAPTCHA_PRIVATE_KEY',
                          os.environ['RECAPTCHA_PRIVATE_KEY'])

Babel(app)
Mail(app)
InvenioDB(app)
InvenioAccounts(app)
InvenioI18N(app)

if INVENIO_ASSETS_AVAILABLE:
    InvenioAssets(app)
if INVENIO_THEME_AVAILABLE:
    InvenioTheme(app)
else:
    Menu(app)
if INVENIO_ADMIN_AVAILABLE:
    InvenioAdmin(app,
                 permission_factory=lambda x: x,
                 view_class_factory=lambda x: x)
app.register_blueprint(blueprint)


@app.route("/")
def index():
    """Basic test view."""
    if current_user.is_authenticated:
        return render_template("authenticated.html")
    else:
예제 #20
0
    SECRET_KEY='CHANGEME',
    THEME_BREADCRUMB_ROOT_ENDPOINT='index',
)
if InvenioI18N is not None:
    InvenioI18N(app)
else:
    Babel(app)

# Set jinja loader to first grab templates from the app's folder.
app.jinja_loader = jinja2.ChoiceLoader([
    jinja2.FileSystemLoader(join(dirname(__file__), "templates")),
    app.jinja_loader
])

# Load Invenio modules
theme = InvenioTheme(app)
assets = InvenioAssets(app)

# Register assets
assets.env.register('invenio_theme_js', js)
assets.env.register('invenio_theme_css', css)

# Register menu items
item = theme.menu.submenu('main.errors')
item.register('',
              _('Error pages'),
              active_when=lambda: request.endpoint == "error",
              order=3)
for err, title in app.config['ERRORS'].items():
    item = theme.menu.submenu('main.errors.err%s' % err)
    item.register('error',
예제 #21
0
def test_init(app):
    """Initialization."""
    theme = InvenioTheme(app)
    assert theme.menu is not None
    assert 'THEME_SITENAME' in app.config
    assert 'SASS_BIN' in app.config