Ejemplo n.º 1
0
def test_current_app_and_config_not_visible(app):
    """Test current_app and config are not visible to template."""
    app.config.update(SECRET_KEY='super secret')
    InvenioPages(app)
    app.register_blueprint(blueprint)
    with app.app_context():
        page = Page(
            url='/dynamic',
            title='Dynamic page',
            content="{{SECRET_KEY}}",
            template_name='invenio_pages/dynamic.html',
        )
        db.session.add(page)
        db.session.commit()

        with app.test_request_context('/dynamic'):
            assert app.config['SECRET_KEY'] not in render_page('/dynamic')

            page.content = '{{config.SECRET_KEY}}'
            db.session.commit()
            with pytest.raises(UndefinedError):
                render_page('/dynamic')

            page.content = "{{current_app.config['SECRET_KEY']}}"
            db.session.commit()
            with pytest.raises(UndefinedError):
                render_page('/dynamic')
Ejemplo n.º 2
0
def test_current_app_and_config_not_visible(app):
    """Test current_app and config are not visible to template."""
    app.config.update(
        SECRET_KEY='super secret'
    )
    InvenioPages(app)
    app.register_blueprint(blueprint)
    with app.app_context():
        page = Page(
            url='/dynamic',
            title='Dynamic page',
            content="{{SECRET_KEY}}",
            template_name='invenio_pages/dynamic.html',
        )
        db.session.add(page)
        db.session.commit()

        with app.test_request_context('/dynamic'):
            assert app.config['SECRET_KEY'] not in render_page('/dynamic')

            page.content = '{{config.SECRET_KEY}}'
            db.session.commit()
            with pytest.raises(UndefinedError):
                render_page('/dynamic')

            page.content = "{{current_app.config['SECRET_KEY']}}"
            db.session.commit()
            with pytest.raises(UndefinedError):
                render_page('/dynamic')
Ejemplo n.º 3
0
def test_non_existing_page(pages_fixture):
    """Test non-existing page content."""
    app = pages_fixture
    InvenioPages(app)
    app.register_blueprint(blueprint)

    # render_page function
    with app.test_request_context('/invalid/url/errors'):
        with pytest.raises(NotFound):
            render_page('/invalid/url/errors')
Ejemplo n.º 4
0
def test_non_existing_page(pages_fixture):
    """Test non-existing page content."""
    app = pages_fixture
    InvenioPages(app)
    app.register_blueprint(blueprint)

    # render_page function
    with app.test_request_context('/invalid/url/errors'):
        with pytest.raises(NotFound):
            render_page('/invalid/url/errors')
Ejemplo n.º 5
0
def test_page_content(pages_fixture):
    """Test page content."""
    app = pages_fixture
    InvenioPages(app)
    app.register_blueprint(blueprint)

    with app.app_context():
        with app.test_client() as client:
            resp = client.get('/dogs/shiba')
            assert resp.status_code == 200
            assert 'so doge!' in str(resp.get_data())
            assert 'so doge!' in str(render_page('/dogs/shiba'))
Ejemplo n.º 6
0
def test_page_content(pages_fixture):
    """Test page content."""
    app = pages_fixture
    InvenioPages(app)
    app.register_blueprint(blueprint)

    with app.app_context():
        with app.test_client() as client:
            resp = client.get('/dogs/shiba')
            assert resp.status_code == 200
            assert 'so doge!' in str(resp.get_data())
            assert 'so doge!' in str(render_page('/dogs/shiba'))
Ejemplo n.º 7
0
def test_page_content_dynamic(app):
    """Test page content."""
    app.config['PAGES_WHITELIST_CONFIG_KEYS'] = ['MYVAR']
    InvenioPages(app)
    app.register_blueprint(blueprint)
    content = 'dynamic-content'
    with app.app_context():
        app.config['MYVAR'] = content
        page = Page(
            url='/dynamic',
            title='Dynamic page',
            content='{{MYVAR}}',
            template_name='invenio_pages/dynamic.html',
        )
        db.session.add(page)
        db.session.commit()

        with app.test_request_context('/dynamic'):
            assert content in render_page('/dynamic')

        with app.test_client() as client:
            resp = client.get('/dynamic')
            assert resp.status_code == 200
            assert content in resp.get_data(as_text=True)
Ejemplo n.º 8
0
def test_page_content_dynamic(app):
    """Test page content."""
    app.config['PAGES_WHITELIST_CONFIG_KEYS'] = ['MYVAR']
    InvenioPages(app)
    app.register_blueprint(blueprint)
    content = 'dynamic-content'
    with app.app_context():
        app.config['MYVAR'] = content
        page = Page(
            url='/dynamic',
            title='Dynamic page',
            content='{{MYVAR}}',
            template_name='invenio_pages/dynamic.html',
        )
        db.session.add(page)
        db.session.commit()

        with app.test_request_context('/dynamic'):
            assert content in render_page('/dynamic')

        with app.test_client() as client:
            resp = client.get('/dynamic')
            assert resp.status_code == 200
            assert content in resp.get_data(as_text=True)