Exemplo n.º 1
0
def test_layout_rendering_with_global_type(rf):
    request = get_request(edit=False)
    with override_current_theme_class(None):
        with plugin_override():
            jeng = get_jinja2_engine()
            template = jeng.from_string("")

            (template, layout, gibberish,
             ctx) = get_test_template_bits(request)

            global_class = "xt-global-ph"
            result = six.text_type(
                render_placeholder(ctx,
                                   "test",
                                   layout,
                                   template.template.name,
                                   global_type=True))
            assert global_class in result

            result = six.text_type(
                render_placeholder(ctx,
                                   "test",
                                   layout,
                                   template.template.name,
                                   global_type=False))
            assert global_class not in result
Exemplo n.º 2
0
def test_without_rc():
    request = get_request()
    (template, layout, gibberish, ctx) = get_test_template_bits(request)
    assert not add_resource(ctx, "yes", "hello.js")
    content1 = "<html>"
    content2 = inject_resources(ctx, content1)
    assert content1 == content2
Exemplo n.º 3
0
def test_layout_edit_render():
    request = get_request(edit=True)
    with override_current_theme_class(None):
        with plugin_override():
            (template, layout, gibberish,
             ctx) = get_test_template_bits(request)
            result = six.text_type(
                render_placeholder(ctx, "test", layout, "test"))
            # Look for evidence of editing:
            assert "xt-ph-edit" in result
            assert "data-xt-placeholder-name" in result
            assert "data-xt-row" in result
            assert "data-xt-cell" in result
Exemplo n.º 4
0
def test_view_config_caches_into_context(rf):
    # This is a silly test...
    request = get_request(edit=False)
    with override_current_theme_class(None):
        (template, layout, gibberish, ctx) = get_test_template_bits(request)
        cfg1 = get_view_config(ctx)
        cfg2 = get_view_config(ctx)
        assert cfg1 is cfg2
        (template, layout, gibberish,
         ctx) = get_test_template_bits(request, False)
        cfg1 = get_view_config(ctx)
        cfg2 = get_view_config(ctx)
        assert cfg1 is cfg2
Exemplo n.º 5
0
def test_simple_addon_injection():
    request = get_request(edit=False)
    request.shop = get_default_shop()
    jeng = get_jinja2_engine()
    template = jeng.get_template("resinject.jinja")

    with override_current_theme_class():
        with override_provides("xtheme_resource_injection", [
                "wshop_tests.xtheme.test_addon_injections:add_test_injection",
        ]):
            # TestInjector should add alert to end of the body for every request
            output = template.render(request=request)
            head, body = output.split("</head>", 1)
            assert "window.injectedFromAddon=true;" in body
Exemplo n.º 6
0
def test_resources():
    request = get_request(edit=False)
    with override_current_theme_class(None):
        with plugin_override():
            jeng = get_jinja2_engine()
            template = jeng.get_template("resinject.jinja")
            output = template.render(request=request)
            head, body = output.split("</head>", 1)
            assert "alert('xss')" in body  # the inline script
            assert '"bars": [1, 2, 3]' in head  # the script vars
            assert '(unknown resource type:' in body  # the png
            assert 'href="://example.com/css.css"' in head  # the css
            assert 'src="://example.com/js.js"' in body  # the js
            assert head.count(
                ResourceInjectorPlugin.meta_markup) == 1  # the duplicate meta
            assert ResourceInjectorPlugin.message in output  # the actual message
Exemplo n.º 7
0
def test_layout_rendering(rf):
    request = get_request(edit=False)
    with override_current_theme_class(None):
        with plugin_override():
            (template, layout, gibberish,
             ctx) = get_test_template_bits(request)

            result = six.text_type(
                render_placeholder(ctx, "test", layout, "test"))
            expect = """
            <div class="xt-ph" id="xt-ph-test">
            <div class="row xt-ph-row">
            <div class="col-md-12 hidden-xs xt-ph-cell"><p>%s</p></div>
            </div>
            </div>
            """ % gibberish
            assert close_enough(result, expect)
Exemplo n.º 8
0
def test_rendering(edit, injectable, theme_class, global_type):
    request = get_request(edit)
    with override_current_theme_class(theme_class):
        with plugin_override():
            jeng = get_jinja2_engine()
            if global_type:
                template = jeng.get_template("global_complex.jinja")
            else:
                template = jeng.get_template("complex.jinja")
            view = FauxView()
            view.xtheme_injection = bool(injectable)
            output = template.render(context={
                "view": view,
            }, request=request)
            assert "wider column" in output
            assert "less wide column" in output
            if edit and injectable and theme_class:
                assert "xt-ph-edit" in output
                assert "data-xt-placeholder-name" in output
                assert "data-xt-row" in output
                assert "data-xt-cell" in output
                assert "XthemeEditorConfig" in output
Exemplo n.º 9
0
def test_injecting_into_weird_places():
    request = get_request()
    (template, layout, gibberish, ctx) = get_test_template_bits(
        request, **{RESOURCE_CONTAINER_VAR_NAME: ResourceContainer()})
    with pytest.raises(ValueError):
        add_resource(ctx, "yes", "hello.js")