Exemplo n.º 1
0
    def test_render_model_add_block(self):
        from django.core.cache import cache
        from cms.test_utils.project.sampleapp.models import Category

        cache.clear()
        page = create_page('Test', 'col_two.html', 'en', published=True)
        template = "{% load cms_tags %}{% render_model_add_block category %}wrapped{% endrender_model_add_block %}"
        user = self._create_user("admin", True, True)
        request = RequestFactory().get(page.get_absolute_url())
        request.user = user
        request.current_page = page
        request.session = {'cms_edit': True}
        request.toolbar = CMSToolbar(request)
        request.toolbar.is_staff = True
        with self.assertNumQueries(0):
            output = self.render_template_obj(template, {'category': Category()}, request)
        expected_start = '<template class="cms-plugin cms-plugin-start cms-plugin-sampleapp-category-add-0 '
        'cms-render-model-add"></template>'
        expected_end = '<template class="cms-plugin cms-plugin-end cms-plugin-sampleapp-category-add-0 '
        'cms-render-model-add"></template>'
        self.assertIn(expected_start, output)
        self.assertIn(expected_end, output)

        # Now test that it does NOT render when not in edit mode
        request = RequestFactory().get(page.get_absolute_url())
        request.user = user
        request.current_page = page
        request.session = {}
        request.toolbar = CMSToolbar(request)
        with self.assertNumQueries(0):
            output = self.render_template_obj(template, {'category': Category()}, request)
        expected = 'wrapped'
        self.assertEqual(expected, output)
Exemplo n.º 2
0
    def test_render_model_add_block(self):
        from django.core.cache import cache
        from cms.test_utils.project.sampleapp.models import Category

        cache.clear()
        page = create_page('Test', 'col_two.html', 'en', published=True)
        template = Template(
            "{% load cms_tags %}{% render_model_add_block category %}wrapped{% endrender_model_add_block %}"
        )
        user = self._create_user("admin", True, True)
        request = RequestFactory().get('/')
        request.user = user
        request.current_page = page
        request.session = {}
        request.toolbar = CMSToolbar(request)
        request.toolbar.edit_mode = True
        request.toolbar.is_staff = True
        context = RequestContext(request, {'category': Category()})
        with self.assertNumQueries(0):
            output = template.render(context)
        expected = 'cms_plugin cms_plugin-sampleapp-category-add-0 '
        'cms_render_model_add'
        self.assertIn(expected, output)

        # Now test that it does NOT render when not in edit mode
        request = RequestFactory().get('/')
        request.user = user
        request.current_page = page
        request.session = {}
        request.toolbar = CMSToolbar(request)
        context = RequestContext(request, {'category': Category()})
        with self.assertNumQueries(0):
            output = template.render(context)
        expected = 'wrapped'
        self.assertEqual(expected, output)