コード例 #1
0
    def test_new_draft_doesnt_change_status_of_drafts_of_other_content_types(
            self):
        """Regression test for a bug in which filtering by content_type
        was missed in the query that chooses versions to archive,
        thereby archiving all versions with a certain object_id, not
        just the versions we want to archive.
        """
        pv = factories.PollVersionFactory(
            state=constants.DRAFT,
            content__id=11,
            content__language='en',
        )
        bv = factories.BlogPostVersionFactory(state=constants.DRAFT,
                                              content__id=11)

        Version.objects.create(content=factories.PollContentFactory(
            poll=pv.content.poll,
            language='en',
        ),
                               created_by=factories.UserFactory(),
                               state=constants.DRAFT)

        # Only poll version was changed
        pv_ = Version.objects.get(pk=pv.pk)
        self.assertEqual(pv_.state, constants.ARCHIVED)
        bv_ = Version.objects.get(pk=bv.pk)
        self.assertEqual(bv_.state, constants.DRAFT)
コード例 #2
0
 def test_new_version_is_draft_by_default(self):
     # Not using PollVersionFactory for this as PollVersionFactory
     # could potentially be overriding the value of state and we
     # want to know the default
     version = Version.objects.create(
         content=factories.PollContentFactory(), created_by=factories.UserFactory()
     )
     self.assertEqual(version.state, constants.DRAFT)
コード例 #3
0
    def test_new_draft_doesnt_change_status_of_drafts_from_other_groupers(self):
        """When versions relating to different groupers have a new draft
        created, then this should not change the other draft's status to
        archived.
        """
        factories.PollVersionFactory(state=constants.DRAFT)

        Version.objects.create(
            content=factories.PollContentFactory(),
            state=constants.DRAFT,
            created_by=factories.UserFactory(),
        )

        # Both are still drafts because they relate to different groupers
        self.assertEqual(Version.objects.filter(state=constants.DRAFT).count(), 2)
コード例 #4
0
    def test_the_copy_method_is_configurable(self):
        """When copying, the new version object should have a new
        related content object. How the content object will be
        copied can be configured.
        """
        original_version = factories.PollVersionFactory()
        user = factories.UserFactory()
        new_content = factories.PollContentFactory(
            poll=original_version.content.poll)
        mocked_copy = Mock(return_value=new_content)
        versionables_mock = self._create_versionables_mock(mocked_copy)
        versioning_app_ext = apps.get_app_config(
            'djangocms_versioning').cms_extension

        with patch.object(versioning_app_ext, 'versionables_by_content', versionables_mock):
            new_version = original_version.copy(user)

        self.assertEqual(new_version.content.pk, new_content.pk)
コード例 #5
0
    def test_new_draft_doesnt_change_status_of_drafts_with_other_states(self):
        """When versions relating to the same grouper have non-draft
        states, these should not change upon creating a new draft
        """
        poll = factories.PollFactory()
        factories.PollVersionFactory(state=constants.UNPUBLISHED,
                                     content__poll=poll)
        factories.PollVersionFactory(state=constants.PUBLISHED,
                                     content__poll=poll)

        version = Version.objects.create(
            content=factories.PollContentFactory(poll=poll),
            created_by=factories.UserFactory(),
            state=constants.DRAFT)

        # Nothing has an archived state cause there were no drafts
        self.assertEqual(
            Version.objects.exclude(pk=version.pk).filter(
                state=constants.ARCHIVED).count(), 0)
コード例 #6
0
    def test_new_draft_causes_old_drafts_to_change_to_archived(self):
        """When versions relating to the same grouper have a new draft
        created, all old drafts should be marked archived
        """
        poll = factories.PollFactory()
        factories.PollVersionFactory.create_batch(3,
                                                  state=constants.DRAFT,
                                                  content__poll=poll)

        version = Version.objects.create(
            content=factories.PollContentFactory(poll=poll),
            created_by=factories.UserFactory(),
            state=constants.DRAFT)

        # Only one draft
        self.assertEqual(
            Version.objects.filter(state=constants.DRAFT).count(), 1)
        # Everything other than the last draft we created has status archived
        self.assertEqual(
            Version.objects.exclude(pk=version.pk).filter(
                state=constants.ARCHIVED).count(), 3)