def setUp(self):
     self.factory = RequestFactory()
     self.superuser = self.get_superuser()
     self.page = PageContentFactory()
     self.content = ContentType.objects.get_for_model(self.page)
     self.view_url = self.get_view_url(self.content.pk, self.page.id)
     self.language = "en"
示例#2
0
    def test_view_poll_plugin_attached_to_page_should_return_related_page(
            self):
        request = self.factory.get(self.view_url)
        request.user = self.superuser

        page_content = PageContentFactory(title="test", language=self.language)
        page = page_content.page
        placeholder = PlaceholderFactory(
            content_type=ContentType.objects.get_for_model(page_content),
            object_id=page_content.id,
        )

        poll = PollFactory()
        # add poll plugin to page
        poll_plugin_1 = add_plugin(placeholder,
                                   "PollPlugin",
                                   "en",
                                   poll=poll,
                                   template=0)

        view = ReferencesView()
        view.request = request
        view.kwargs = {
            "content_type_id": ContentType.objects.get_for_model(poll).pk,
            "object_id": poll.id,
        }
        response = view.get_context_data()

        self.assertIn("querysets", response)

        # queryset should contain page
        self.assertEqual(response["querysets"][0].count(), 1)
        self.assertIn(page_content, response["querysets"][0])
示例#3
0
 def test_object_preview_url_rendered_with_string_arg(self):
     obj = PageContentFactory()
     context = Context({"obj": obj})
     template_to_render = Template("{% load djangocms_references_tags %}"
                                   "{% object_preview_url 'dummy' %}")
     self.assertRaises(TemplateSyntaxError, template_to_render.render,
                       context)
示例#4
0
 def test_object_model_rendered_with_int_argument(self):
     obj = PageContentFactory()
     context = Context({"obj": obj})
     template_to_render = Template("{% load djangocms_references_tags %}"
                                   "{% object_model 1 %}")
     self.assertRaises(TemplateSyntaxError, template_to_render.render,
                       context)
示例#5
0
 def test_cms_toolbar_button_not_shown_if_no_permission(self):
     user = self.get_standard_user()
     page_content = PageContentFactory(created_by=user)
     toolbar = self._get_toolbar(page_content, user=user, edit_mode=True)
     toolbar.populate()
     toolbar.post_template_populate()
     self.assertFalse(toolbar.toolbar.left_items)
示例#6
0
 def test_object_model_rendered_with_obj_arg(self):
     obj = PageContentFactory()
     context = Context({"obj": obj})
     expected_model = obj._meta.model_name
     template_to_render = Template("{% load djangocms_references_tags %}"
                                   "{% object_model obj %}")
     rendered_template = template_to_render.render(context)
     self.assertEqual(expected_model, rendered_template)
示例#7
0
 def test_object_preview_url_rendered_with_obj_arg(self):
     obj = PageContentFactory()
     context = Context({"obj": obj})
     expected_url = get_object_preview_url(obj)
     template_to_render = Template("{% load djangocms_references_tags %}"
                                   "{% object_preview_url obj %}")
     rendered_template = template_to_render.render(context)
     self.assertInHTML(expected_url, rendered_template)
示例#8
0
 def test_extra_column(self):
     obj = PageContentFactory()
     context = Context({
         "obj": obj,
         "column": ExtraColumn(lambda o: id(o), "Foo")
     })
     template_to_render = Template("{% load djangocms_references_tags %}"
                                   "{% extra_column obj column %}")
     rendered_template = template_to_render.render(context)
     self.assertEqual(str(id(obj)), rendered_template)
 def test_cms_toolbar_has_show_references(self):
     page_content = PageContentFactory(created_by=self.user)
     toolbar = self._get_toolbar(page_content,
                                 user=self.user,
                                 edit_mode=True)
     toolbar.populate()
     toolbar.post_template_populate()
     self.assertIsInstance(toolbar.toolbar.left_items[-1].buttons[0],
                           SideframeButton)
     self.assertEqual(toolbar.toolbar.left_items[-1].buttons[0].name,
                      "Show References")
示例#10
0
    def test_get_reference_objects_from_plugins(self):
        page_content = PageContentFactory(title="test", language="en")
        placeholder = PlaceholderFactory(
            content_type=ContentType.objects.get_for_model(page_content),
            object_id=page_content.id,
        )
        poll = PollFactory()
        add_plugin(placeholder, "PollPlugin", "en", poll=poll, template=0)

        querysets = list(get_reference_objects_from_plugins(poll))
        self.assertEqual(len(querysets), 1)
        self.assertIn(page_content, querysets[0])
示例#11
0
 def setUp(self):
     self.factory = RequestFactory()
     self.superuser = self.get_superuser()
     self.page = PageContentFactory()
     self.content = ContentType.objects.get_for_model(self.page)
     self.view_url = reverse(
         "djangocms_references:references-index",
         kwargs={
             "content_type_id": self.content.pk,
             "object_id": self.page.id
         },
     )
     self.language = "en"
示例#12
0
    def test_not_versioned(self):
        content = PageContentFactory()

        func = Mock()
        decorated = version_attr(func)

        with patch(
                "djangocms_references.helpers.get_versionable_for_content",
                return_value=False,
        ) as mock:
            result = decorated(content)
            mock.assert_called_once_with(content)
            func.assert_not_called()
            self.assertIsNone(result)
示例#13
0
 def test_cms_toolbar_has_show_references(self):
     user = self.get_standard_user()
     user.user_permissions.add(
         Permission.objects.get(
             content_type__app_label="djangocms_references",
             codename="show_references",
         ))
     page_content = PageContentFactory(created_by=user)
     toolbar = self._get_toolbar(page_content, user=user, edit_mode=True)
     toolbar.populate()
     toolbar.post_template_populate()
     self.assertIsInstance(toolbar.toolbar.left_items[-1].buttons[0],
                           SideframeButton)
     self.assertEqual(toolbar.toolbar.left_items[-1].buttons[0].name,
                      "Show References")