def test_render_child_plugin_endpoint(self):
        simple_page = create_page('test page', 'page.html', u'en')
        simple_placeholder = simple_page.placeholders.get(slot='content')
        text_plugin = add_plugin(
            simple_placeholder,
            "TextPlugin",
            "en",
            body="I'm the first",
        )
        text_plugin_class = text_plugin.get_plugin_class_instance()
        child_plugin = self._add_child_plugin(text_plugin)
        text_plugin = self.add_plugin_to_text(text_plugin, child_plugin)

        with self.login_user_context(self.get_superuser()):
            request = self.get_request()
            action_token = text_plugin_class.get_action_token(
                request, text_plugin)
            endpoint = self.get_admin_url(Text, 'render_plugin')
            endpoint += '?token={}&plugin={}'.format(action_token,
                                                     child_plugin.pk)
            response = self.client.get(endpoint)

            self.assertEqual(response.status_code, 200)

            context = RequestContext(request)
            context['request'] = request
            rendered_content = _render_cms_plugin(child_plugin, context)
            rendered_child_plugin = plugin_to_tag(
                child_plugin,
                content=rendered_content,
                admin=True,
            )

            self.assertEqual(force_text(response.content),
                             rendered_child_plugin)

        child_plugin = self._add_child_plugin(
            text_plugin, plugin_type='PreviewDisabledPlugin')
        text_plugin = self.add_plugin_to_text(text_plugin, child_plugin)

        with self.login_user_context(self.get_superuser()):
            request = self.get_request()
            action_token = text_plugin_class.get_action_token(
                request, text_plugin)
            endpoint = self.get_admin_url(Text, 'render_plugin')
            endpoint += '?token={}&plugin={}'.format(action_token,
                                                     child_plugin.pk)
            response = self.client.get(endpoint)

            self.assertEqual(response.status_code, 200)

            rendered_child_plugin = (
                '<cms-plugin render-plugin=false '
                'alt="Preview Disabled Plugin - 3 '
                '"title="Preview Disabled Plugin - 3" '
                'id="3">\n<span>Preview is disabled for this plugin</span>'
                '\n</cms-plugin>')

            self.assertEqual(force_text(response.content),
                             rendered_child_plugin)
Example #2
0
    def test_render_child_plugin_endpoint_calls_context_processors(self):
        simple_page = create_page('test page', 'page.html', u'en')
        simple_placeholder = simple_page.placeholders.get(slot='content')
        text_plugin = add_plugin(
            simple_placeholder,
            "TextPlugin",
            "en",
            body="I'm the first",
        )
        text_plugin_class = text_plugin.get_plugin_class_instance()
        child_plugin = self._add_child_plugin(
            text_plugin,
            plugin_type='SekizaiPlugin',
        )
        text_plugin = self.add_plugin_to_text(text_plugin, child_plugin)

        with self.login_user_context(self.get_superuser()):
            request = self.get_request()
            action_token = text_plugin_class.get_action_token(request, text_plugin)
            endpoint = self.get_admin_url(Text, 'render_plugin')
            endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
            response = self.client.get(endpoint)

            self.assertEqual(response.status_code, 200)

            context = RequestContext(request)
            context['request'] = request
            rendered_content = _render_cms_plugin(child_plugin, context)
            rendered_child_plugin = plugin_to_tag(
                child_plugin,
                content=rendered_content,
                admin=True,
            )

            self.assertEqual(force_text(response.content), rendered_child_plugin)
    def test_render_child_plugin_endpoint_calls_context_processors(self):
        simple_page = create_page('test page', 'page.html', u'en')
        simple_placeholder = simple_page.placeholders.get(slot='content')
        text_plugin = add_plugin(
            simple_placeholder,
            "TextPlugin",
            "en",
            body="I'm the first",
        )
        text_plugin_class = text_plugin.get_plugin_class_instance()
        child_plugin = self._add_child_plugin(
            text_plugin,
            plugin_type='SekizaiPlugin',
        )
        text_plugin = self.add_plugin_to_text(text_plugin, child_plugin)

        with self.login_user_context(self.get_superuser()):
            request = self.get_request()
            action_token = text_plugin_class.get_action_token(request, text_plugin)
            endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
            endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
            response = self.client.get(endpoint)

            self.assertEqual(response.status_code, 200)

            context = RequestContext(request)
            context['request'] = request
            rendered_content = _render_cms_plugin(child_plugin, context)
            rendered_child_plugin = plugin_to_tag(
                child_plugin,
                content=rendered_content,
                admin=True,
            )

            self.assertEqual(force_text(response.content), rendered_child_plugin)
    def test_render_child_plugin_endpoint(self):
        simple_page = create_page('test page', 'page.html', u'en')
        simple_placeholder = simple_page.placeholders.get(slot='content')
        text_plugin = add_plugin(
            simple_placeholder,
            "TextPlugin",
            "en",
            body="I'm the first",
        )
        text_plugin_class = text_plugin.get_plugin_class_instance()
        child_plugin = self._add_child_plugin(text_plugin)
        text_plugin = self.add_plugin_to_text(text_plugin, child_plugin)

        with self.login_user_context(self.get_superuser()):
            request = self.get_request()
            action_token = text_plugin_class.get_action_token(request, text_plugin)
            endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
            endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
            response = self.client.get(endpoint)

            self.assertEqual(response.status_code, 200)

            context = RequestContext(request)
            context['request'] = request
            rendered_content = _render_cms_plugin(child_plugin, context)
            rendered_child_plugin = plugin_to_tag(
                child_plugin,
                content=rendered_content,
                admin=True,
            )

            self.assertEqual(force_text(response.content), rendered_child_plugin)

        child_plugin = self._add_child_plugin(text_plugin, plugin_type='PreviewDisabledPlugin')
        text_plugin = self.add_plugin_to_text(text_plugin, child_plugin)

        with self.login_user_context(self.get_superuser()):
            request = self.get_request()
            action_token = text_plugin_class.get_action_token(request, text_plugin)
            endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
            endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
            response = self.client.get(endpoint)

            self.assertEqual(response.status_code, 200)

            # it is important that we do not add any extra whitespace inside of
            # <cms-plugin></cms-plugin>
            rendered_child_plugin = ('<cms-plugin render-plugin=false '
                                     'alt="Preview Disabled Plugin - 3 '
                                     '"title="Preview Disabled Plugin - 3" '
                                     'id="3"><span>Preview is disabled for this plugin</span>'
                                     '</cms-plugin>')

            self.assertEqual(force_text(response.content), rendered_child_plugin)
    def test_render_extended_plugin(self):
        simple_page = create_page("test page", "page.html", u"en")
        simple_placeholder = simple_page.placeholders.get(slot="content")
        text_plugin = self._add_text_plugin(simple_placeholder, "ExtendedTextPlugin")

        for i in range(0, 10):
            plugin = self._add_child_plugin(text_plugin, plugin_type="LinkPlugin", data_suffix=i)

            text_plugin = self.add_plugin_to_text(text_plugin, plugin)

        with self.assertNumQueries(2):
            request = self.get_request()
            context = RequestContext(request)
            context["request"] = request
            rendered = _render_cms_plugin(text_plugin, context)

        for i in range(0, 10):
            self.assertTrue("LinkPlugin record %d" % i in rendered)
Example #6
0
    def test_render_plugin(self):
        simple_page = create_page('test page', 'page.html', u'en')
        simple_placeholder = simple_page.placeholders.get(slot='content')
        text_plugin = self._add_text_plugin(simple_placeholder)

        for i in range(0, 10):
            plugin = self._add_child_plugin(text_plugin,
                                            plugin_type='LinkPlugin',
                                            data_suffix=i)

            text_plugin = self.add_plugin_to_text(text_plugin, plugin)

        with self.assertNumQueries(2):
            request = self.get_request()
            context = RequestContext(request)
            context['request'] = request
            rendered = _render_cms_plugin(text_plugin, context)

        for i in range(0, 10):
            self.assertTrue('LinkPlugin record %d' % i in rendered)
    def test_render_extended_plugin(self):
        simple_page = create_page('test page', 'page.html', u'en')
        simple_placeholder = simple_page.placeholders.get(slot='content')
        text_plugin = self._add_text_plugin(simple_placeholder, 'ExtendedTextPlugin')

        for i in range(0, 10):
            plugin = self._add_child_plugin(
                text_plugin,
                plugin_type='LinkPlugin',
                data_suffix=i
            )

            text_plugin = self.add_plugin_to_text(text_plugin, plugin)

        with self.assertNumQueries(2):
            request = self.get_request()
            context = RequestContext(request)
            context['request'] = request
            rendered = _render_cms_plugin(text_plugin, context)

        for i in range(0, 10):
            self.assertTrue('LinkPlugin record %d' % i in rendered)