Esempio n. 1
0
def test_add_child_with_template(monkeypatch):
    """Test adding child.

    Whenever views are rendered, a tree should be rendered in parallel, that
    allows us to know where things are build.
    """

    view.render_main_view(lemon, primary_view='MainView')
    view_dict = view.MainView.instance.to_dict()
    children = view_dict.get('children')

    assert len(children) == 1
    assert children[0].get('path') == 'MainView'
Esempio n. 2
0
def test_main_view_rendering(monkeypatch):
    """Test the main view rendering.

    The main view does not add additional html into the response since it is
    meant to draw the shell of the site.
    """

    value = (
        'Hello {% if primary_view %}'
        '{{ primary_view|safe }}'
        '{% endif %}')

    app.app_context().push()
    create_template = app.jinja_env.from_string

    template = create_template(value)
    magic_template = MagicMock(return_value=template)
    monkeypatch.setattr(
        app.jinja_env, 'get_template', magic_template)

    my_view = view.MainView('Test')
    primary_view = view.View('PrimaryView')

    app.config.setdefault('LEMON_APP_VIEW', 'Test')
    value = view.render_main_view(lemon, primary_view='PrimaryView')

    assert magic_template.called
    assert value.find('View Primary') > 0
Esempio n. 3
0
def test_jinja2_render_with_tag_name():
    """Test jinja2 render with a different view tag.
    """

    response = view.render_main_view(lemon, primary_view='Button')
    create_template = app.jinja_env.from_string
    html = create_template("{{ view('Button') }}").render(lemon=lemon)
    assert html.find('<button') > -1
Esempio n. 4
0
def test_jinja2_render_with_tag_name():
    """Test jinja2 render with additional classes
    """

    response = view.render_main_view(lemon, primary_view='Button')
    create_template = app.jinja_env.from_string
    html = create_template(
        "{{ view('Button', params={'classes': ['Test']}) }}").render(
        lemon=lemon)
    assert html.find('Test') > -1
Esempio n. 5
0
def test_jinja2_render_with_attributes():
    """Test jinja2 render with additional classes
    """

    response = view.render_main_view(lemon, primary_view='Button')
    create_template = app.jinja_env.from_string
    html = create_template(
        "{{ view('Button', params={'attrs': {'data-id': 'foo'}}) }}").render(
            lemon=lemon)
    assert html.find('data-id') > -1
    assert html.find('foo') > -1
Esempio n. 6
0
    def callback(*args, **kwargs):
        check_access(options.get('access') or [])

        if isinstance(handler, str):  # pragma: no cover
            # Test in: tests/test_routes.py:test_route_fetch
            replacements = {'<' + k + '>': v for k, v in kwargs.items()}
            view_options = prepare(options, replacements)
            html = view.render_main_view(lemon, handler, **view_options)
            return html

        elif callable(handler):
            kwargs.update(options=options)
            return handler(request, *args, **kwargs)