Пример #1
0
    def test_copy_language_copies_from_page_with_different_placeholders(self):
        """
        PageContents stores the template, this means that each PageContent can have
        a different template and placeholders. We should only copy plugins from common placeholders.

        This test contains different templates and a partially populated source and target placeholders.
        All plugins in the source should be left unnafected
        """
        source_placeholder_1 = PlaceholderFactory(
            source=self.source_version.content, slot="source_placeholder_1")
        self.source_version.content.placeholders.add(source_placeholder_1)
        TextPluginFactory(placeholder=source_placeholder_1)
        target_placeholder_1 = PlaceholderFactory(
            source=self.target_version.content, slot="target_placeholder_1")
        self.target_version.content.placeholders.add(target_placeholder_1)
        TextPluginFactory(placeholder=target_placeholder_1)

        self.source_version.publish(self.user)

        with self.login_user_context(self.user):
            response = self.client.post(self.copy_url, self.copy_url_data)

        self.assertEqual(response.status_code, 200)

        source_placeholder_different = self.source_version.content.placeholders.get(
            slot="source_placeholder_1").cmsplugin_set.all()
        target_placeholder_different = self.target_version.content.placeholders.get(
            slot="target_placeholder_1").cmsplugin_set.all()

        self.assertEqual(source_placeholder_different.count(), 1)
        self.assertEqual(target_placeholder_different.count(), 1)
        self.assertNotEqual(
            source_placeholder_different[0].djangocms_text_ckeditor_text.body,
            target_placeholder_different[0].djangocms_text_ckeditor_text.body)
    def test_check_locked_for_the_same_user(self):
        user = self.get_superuser()
        version = PageVersionFactory(created_by=user)
        placeholder = PlaceholderFactory(source=version.content)

        self.assertTrue(
            placeholder_content_is_unlocked_for_user(placeholder, user))
    def test_check_locked_for_the_other_user(self):
        user1 = self.get_superuser()
        user2 = self.get_standard_user()
        version = PageVersionFactory(created_by=user1)
        placeholder = PlaceholderFactory(source=version.content)

        self.assertFalse(placeholder_content_is_unlocked_for_user(placeholder, user2))
    def test_check_no_lock(self):
        user = self.get_superuser()
        version = PageVersionFactory(state=ARCHIVED)
        placeholder = PlaceholderFactory(source=version.content)

        self.assertTrue(
            placeholder_content_is_unlocked_for_user(placeholder, user))
Пример #5
0
    def setUp(self):
        self.user = self.get_superuser()
        page = PageFactory()
        self.source_version = PageVersionFactory(content__page=page,
                                                 content__language="en")
        self.target_version = PageVersionFactory(content__page=page,
                                                 content__language="it")
        # Add default placeholders
        source_placeholder = PlaceholderFactory(
            source=self.source_version.content, slot="content")
        self.source_version.content.placeholders.add(source_placeholder)
        target_placeholder = PlaceholderFactory(
            source=self.target_version.content, slot="content")
        self.target_version.content.placeholders.add(target_placeholder)
        # Populate only the source placeholder as this is what we will be copying!
        TextPluginFactory(placeholder=source_placeholder)

        # Use the endpoint that the toolbar copy uses, this indirectly runs the monkey patched logic!
        # Simulating the user selecting in the Language menu "Copy all plugins" in the Versioned Page toolbar
        self.copy_url = admin_reverse('cms_pagecontent_copy_language',
                                      args=(self.source_version.content.pk, ))
        self.copy_url_data = {'source_language': "en", 'target_language': "it"}
Пример #6
0
    def test_is_placeholder_review_unlocked(
        self, mock_is_registered_for_moderation, mock_is_obj_review_locked
    ):
        """
        Check that the monkeypatch returns expected value
        """
        version = PageVersionFactory()
        placeholder = PlaceholderFactory.create(source=version.content)

        mock_is_registered_for_moderation.return_value = True
        mock_is_obj_review_locked.return_value = True

        self.assertFalse(_is_placeholder_review_unlocked(placeholder, self.user))

        mock_is_registered_for_moderation.return_value = True
        mock_is_obj_review_locked.return_value = False

        self.assertTrue(_is_placeholder_review_unlocked(placeholder, self.user))

        mock_is_registered_for_moderation.return_value = False
        mock_is_obj_review_locked.return_value = True

        self.assertTrue(_is_placeholder_review_unlocked(placeholder, self.user))
 def test_check_unversioned_model(self):
     user = self.get_superuser()
     placeholder = PlaceholderFactory(source=FancyPollFactory())
     self.assertTrue(is_content_editable(placeholder, user))
 def test_check_published_state(self):
     user = self.get_superuser()
     version = PageVersionFactory(state=PUBLISHED)
     placeholder = PlaceholderFactory(source=version.content)
     self.assertFalse(is_content_editable(placeholder, user))
 def test_check_draft_state(self):
     user = self.get_superuser()
     version = PageVersionFactory(state=DRAFT)
     placeholder = PlaceholderFactory(source=version.content)
     self.assertTrue(is_content_editable(placeholder, user))
    def test_check_no_lock_for_unversioned_model(self):
        user2 = self.get_standard_user()
        placeholder = PlaceholderFactory(source=FancyPollFactory())

        self.assertTrue(placeholder_content_is_unlocked_for_user(placeholder, user2))