示例#1
0
    def test_queryset_filter_for_distinct_groupers(self):
        poll1_archived_version = PollVersionFactory(
            content__poll=self.initial_version.content.poll, state=ARCHIVED)
        poll1_published_version = PollVersionFactory(
            content__poll=self.initial_version.content.poll, state=PUBLISHED)
        poll2_version = PollVersionFactory()
        PollVersionFactory(content__poll=poll2_version.content.poll,
                           state=ARCHIVED)
        poll2_archived_version = PollVersionFactory(
            content__poll=poll2_version.content.poll, state=ARCHIVED)

        versionable = VersionableItem(
            content_model=PollContent,
            grouper_field_name="poll",
            copy_function=default_copy,
        )

        qs_published_filter = {"versions__state__in": [PUBLISHED]}
        # Should be one published version
        self.assertQuerysetEqual(
            versionable.distinct_groupers(**qs_published_filter),
            [poll1_published_version.pk],
            transform=lambda x: x.pk,
            ordered=False,
        )

        qs_archive_filter = {"versions__state__in": [ARCHIVED]}
        # Should be two archived versions
        self.assertQuerysetEqual(
            versionable.distinct_groupers(**qs_archive_filter),
            [poll1_archived_version.pk, poll2_archived_version.pk],
            transform=lambda x: x.pk,
            ordered=False,
        )
    def test_for_grouper(self):
        poll1_version2 = PollVersionFactory(
            content__poll=self.initial_version.content.poll, )
        poll2_version = PollVersionFactory()
        PollVersionFactory(content__poll=poll2_version.content.poll)
        PollVersionFactory(content__poll=poll2_version.content.poll)

        versionable = VersionableItem(content_model=PollContent,
                                      grouper_field_name='poll',
                                      copy_function=default_copy)

        self.assertQuerysetEqual(
            versionable.for_grouper(self.initial_version.content.poll),
            [self.initial_version.content.pk, poll1_version2.content.pk],
            transform=lambda x: x.pk,
            ordered=False)
示例#3
0
    def test_publish_not_in_toolbar_in_structure_mode(self):
        version = PollVersionFactory()
        toolbar = get_toolbar(version.content, structure_mode=True)

        toolbar.post_template_populate()

        self.assertFalse(toolbar_button_exists("Publish", toolbar.toolbar))
示例#4
0
    def test_success_url_for_cms_wizard(self):
        from cms.cms_wizards import cms_page_wizard, cms_subpage_wizard
        from cms.toolbar.utils import get_object_preview_url

        from djangocms_versioning.test_utils.polls.cms_wizards import poll_wizard

        # Test against page creations in different languages.
        version = PageVersionFactory(content__language="en")
        self.assertEqual(
            cms_page_wizard.get_success_url(version.content.page,
                                            language="en"),
            get_object_preview_url(version.content),
        )

        version = PageVersionFactory(content__language="en")
        self.assertEqual(
            cms_subpage_wizard.get_success_url(version.content.page,
                                               language="en"),
            get_object_preview_url(version.content),
        )

        version = PageVersionFactory(content__language="de")
        self.assertEqual(
            cms_page_wizard.get_success_url(version.content.page,
                                            language="de"),
            get_object_preview_url(version.content, language="de"),
        )

        # Test against a model that doesn't have a PlaceholderRelationField
        version = PollVersionFactory()
        self.assertEqual(
            poll_wizard.get_success_url(version.content),
            version.content.get_absolute_url(),
        )
示例#5
0
    def test_publish_not_in_toolbar_in_preview_mode(self):
        version = PollVersionFactory()
        toolbar = self._get_toolbar(version.content, preview_mode=True)

        toolbar.post_template_populate()

        buttons = toolbar.toolbar.get_right_items()[0].buttons
        self.assertListEqual([b for b in buttons if b.name == 'Publish'], [])
示例#6
0
    def test_publish_not_in_toolbar_in_structure_mode(self):
        version = PollVersionFactory()
        toolbar = self._get_toolbar(version.content, structure_mode=True)

        toolbar.post_template_populate()

        buttons = toolbar.toolbar.get_right_items()
        self.assertListEqual(buttons, [])
 def test_version_menu_for_version_content(self):
     # Versioned item should have versioning menu
     version = PollVersionFactory()
     toolbar = get_toolbar(version.content, preview_mode=True)
     toolbar.post_template_populate()
     version_menu = toolbar.toolbar.get_menu('version')
     self.assertEqual(version_menu.get_items()[0].name,
                      'Manage Versions...')
示例#8
0
    def test_edit_not_in_toolbar_in_structure_mode(self):
        version = PollVersionFactory()
        toolbar = get_toolbar(version.content,
                              user=self.get_superuser(),
                              structure_mode=True)

        toolbar.post_template_populate()

        self.assertFalse(toolbar_button_exists("Edit", toolbar.toolbar))
示例#9
0
 def test_version_menu_for_version_content_no_permission(self):
     """Manage versions entry shouldn't appear if user doesn't have
     access to that endpoint"""
     user = UserFactory(is_staff=True)
     version = PollVersionFactory()
     toolbar = get_toolbar(version.content, user=user, preview_mode=True)
     toolbar.post_template_populate()
     version_menu = toolbar.toolbar.get_menu("version")
     self.assertFalse(version_menu.get_items())
 def test_version_menu_and_url_for_version_content(self):
     # Versioned item should have versioning menu and url should be version list url
     version = PollVersionFactory()
     toolbar = get_toolbar(version.content, preview_mode=True)
     toolbar.post_template_populate()
     version_menu = toolbar.toolbar.get_menu('version')
     self.assertIsNotNone(version_menu)
     self.assertEqual(version_menu.get_items()[0].url,
                      version_list_url(version.content))
示例#11
0
    def test_distinct_groupers(self):
        latest_poll1_version = PollVersionFactory(
            content__poll=self.initial_version.content.poll)
        poll2_version = PollVersionFactory()
        PollVersionFactory(content__poll=poll2_version.content.poll)
        latest_poll2_version = PollVersionFactory(
            content__poll=poll2_version.content.poll)

        versionable = VersionableItem(
            content_model=PollContent,
            grouper_field_name="poll",
            copy_function=default_copy,
        )

        self.assertQuerysetEqual(
            versionable.distinct_groupers(),
            [latest_poll1_version.pk, latest_poll2_version.pk],
            transform=lambda x: x.pk,
            ordered=False,
        )
示例#12
0
    def test_edit_in_toolbar_in_preview_mode(self):
        version = PollVersionFactory()
        toolbar = self._get_toolbar(version.content, preview_mode=True)

        toolbar.post_template_populate()

        edit_button = toolbar.toolbar.get_right_items()[0].buttons[0]
        self.assertEqual(edit_button.name, 'Edit')
        self.assertEqual(edit_button.url, self._get_edit_url(version))
        self.assertFalse(edit_button.disabled)
        self.assertListEqual(edit_button.extra_classes,
                             ['cms-btn-action', 'cms-versioning-js-edit-btn'])
    def test_publish_in_toolbar_in_edit_mode(self):
        version = PollVersionFactory()
        toolbar = get_toolbar(version.content, edit_mode=True)

        toolbar.post_template_populate()
        publish_button = find_toolbar_buttons('Publish', toolbar.toolbar)[0]

        self.assertEqual(publish_button.name, 'Publish')
        self.assertEqual(publish_button.url, self._get_publish_url(version))
        self.assertFalse(publish_button.disabled)
        self.assertListEqual(
            publish_button.extra_classes,
            ['cms-btn-action', 'cms-versioning-js-publish-btn'])
示例#14
0
    def test_version_menu_label(self):
        # Versioned item should have correct version menu label
        version = PollVersionFactory()
        toolbar = get_toolbar(version.content,
                              user=self.get_superuser(),
                              preview_mode=True)
        toolbar.post_template_populate()
        version_menu = toolbar.toolbar.get_menu("version")

        expected_label = "Version #{number} ({state})".format(
            number=version.number, state=version.state)

        self.assertEqual(expected_label, version_menu.name)
示例#15
0
 def test_version_menu_for_version_content(self):
     # Versioned item should have versioning menu
     user = UserFactory(is_staff=True)
     user.user_permissions.add(
         Permission.objects.get(
             content_type__app_label="djangocms_versioning",
             codename="change_pollcontentversion",
         ))
     version = PollVersionFactory()
     toolbar = get_toolbar(version.content, user=user, preview_mode=True)
     toolbar.post_template_populate()
     version_menu = toolbar.toolbar.get_menu("version")
     self.assertEqual(version_menu.get_items()[0].name,
                      "Manage Versions...")
示例#16
0
    def test_url_for_edit_uses_version_id_not_content_id(self):
        """Regression test for a bug. Make sure than when we generate
        the edit url, we use the id of the version record, not the
        id of the content record.
        """
        # All versions are stored in the version table so increase the
        # id of version id sequence by creating a blogpost version
        BlogPostVersionFactory()
        # Now create a poll version - the poll content and version id
        # will be different.
        version = PollVersionFactory()
        toolbar = self._get_toolbar(version.content, preview_mode=True)

        toolbar.post_template_populate()

        edit_button = toolbar.toolbar.get_right_items()[0].buttons[0]
        self.assertEqual(edit_button.url, self._get_edit_url(version))
示例#17
0
    def test_url_for_publish_uses_version_id_not_content_id(self):
        """Regression test for a bug. Make sure than when we generate
        the publish url, we use the id of the version record, not the
        id of the content record.
        """
        # All versions are stored in the version table so increase the
        # id of version id sequence by creating a blogpost version
        BlogPostVersionFactory()
        # Now create a poll version - the poll content and version id
        # will be different.
        version = PollVersionFactory()
        toolbar = get_toolbar(version.content,
                              user=self.get_superuser(),
                              edit_mode=True)
        toolbar.post_template_populate()
        publish_button = find_toolbar_buttons("Publish", toolbar.toolbar)[0]

        self.assertEqual(publish_button.url, self._get_publish_url(version))
示例#18
0
 def setUp(self):
     self.initial_version = PollVersionFactory()