Exemple #1
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))
 def test_version_menu_for_none_version(self):
     # Version menu shouldnt be generated if version is None
     version = None
     toolbar = get_toolbar(version, preview_mode=True)
     toolbar.post_template_populate()
     version_menu = toolbar.toolbar.get_menu('version')
     self.assertIsNone(version_menu)
 def test_version_menu_for_non_version_content(self):
     # User objects are not registered with versioning, so attempting
     # to populate toolbar shouldn't contain a version menu
     toolbar = get_toolbar(UserFactory(), edit_mode=True)
     toolbar.post_template_populate()
     version_menu = toolbar.toolbar.get_menu('version')
     self.assertIsNone(version_menu)
 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...')
Exemple #5
0
    def test_dont_add_publish_for_models_not_registered_with_versioning(self):
        # User objects are not registered with versioning, so attempting
        # to populate a user toolbar should not attempt to add a publish
        # button
        toolbar = get_toolbar(UserFactory(), edit_mode=True)

        toolbar.post_template_populate()

        self.assertFalse(toolbar_button_exists("Publish", toolbar.toolbar))
Exemple #6
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())
Exemple #7
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))
 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))
Exemple #9
0
    def test_dont_add_edit_for_models_not_registered_with_versioning(self):
        # User objects are not registered with versioning, so attempting
        # to populate a user toolbar should not attempt to add a edit
        # button
        toolbar = get_toolbar(UserFactory(),
                              user=self.get_superuser(),
                              preview_mode=True)

        toolbar.post_template_populate()

        self.assertFalse(toolbar_button_exists("Edit", toolbar.toolbar))
Exemple #10
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)
    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'])
Exemple #12
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...")
    def test_edit_in_toolbar_in_preview_mode(self):
        version = PageVersionFactory(content__template="")
        toolbar = get_toolbar(version.content,
                              user=self.get_superuser(),
                              preview_mode=True)

        toolbar.post_template_populate()
        edit_button = find_toolbar_buttons('Edit', toolbar.toolbar)[0]

        self.assertEqual(edit_button.name, 'Edit')
        self.assertEqual(
            edit_button.url,
            self._get_edit_url(version, VersioningCMSConfig.versioning[0]))
        self.assertFalse(edit_button.disabled)
        self.assertListEqual(edit_button.extra_classes,
                             ['cms-btn-action', 'cms-versioning-js-edit-btn'])
Exemple #14
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))
Exemple #15
0
    def test_default_edit_button_from_cms_exists(self):
        """
        The default toolbar Edit button exists.
        """
        pagecontent = PageVersionFactory(content__template="")
        edit_url = self._get_edit_url(pagecontent.content,
                                      VersioningCMSConfig.versioning[0])

        toolbar = get_toolbar(
            pagecontent.content,
            user=self.get_superuser(),
            toolbar_class=PlaceholderToolbar,
            preview_mode=True,
        )
        toolbar.post_template_populate()
        found_button_list = find_toolbar_buttons("Edit", toolbar.toolbar)

        # The only edit button that exists is the default cms button and not the versioning edit button
        self.assertEqual(len(found_button_list), 1)
        self.assertNotEqual(found_button_list[0].url, edit_url)
Exemple #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 page version - the page content and version id
        # will be different.
        version = PageVersionFactory(content__template="")
        toolbar = get_toolbar(version.content,
                              user=self.get_superuser(),
                              preview_mode=True)
        edit_url = self._get_edit_url(version,
                                      VersioningCMSConfig.versioning[0])

        toolbar.post_template_populate()

        edit_button = find_toolbar_buttons("Edit", toolbar.toolbar)[0]
        self.assertEqual(edit_button.url, edit_url)