コード例 #1
0
    def test_new_published_version_doesnt_change_status_of_versions_with_other_states(
        self
    ):
        """When versions relating to the same grouper have non-published
        states, these should not change upon creating a new published version
        """
        poll = factories.PollFactory()
        factories.PollVersionFactory(
            state=constants.DRAFT, content__poll=poll, content__language="en"
        )
        factories.PollVersionFactory(
            state=constants.ARCHIVED, content__poll=poll, content__language="en"
        )
        user = factories.UserFactory()
        version = factories.PollVersionFactory(
            state=constants.DRAFT, content__poll=poll, content__language="en"
        )

        version.publish(user)

        # Nothing has an unpublished state cause there were no published versions
        self.assertEqual(
            Version.objects.exclude(pk=version.pk)
            .filter(state=constants.UNPUBLISHED)
            .count(),
            0,
        )
コード例 #2
0
    def test_new_published_version_doesnt_change_status_of_other_content_types(
            self):
        """Regression test for a bug in which filtering byt content_type
        was missed in the query that chooses versions to unpublish,
        thereby unpublishing all versions with a certain object_id, not
        just the versions we want to unpublish.
        """
        pv = factories.PollVersionFactory(state=constants.PUBLISHED,
                                          content__id=11,
                                          content__language='en')
        bv = factories.BlogPostVersionFactory(state=constants.PUBLISHED,
                                              content__id=11)
        version = factories.PollVersionFactory(
            state=constants.DRAFT,
            content__poll=pv.content.poll,
            content__language='en',
        )
        user = factories.UserFactory()

        version.publish(user)

        # Only poll version was changed
        pv_ = Version.objects.get(pk=pv.pk)
        self.assertEqual(pv_.state, constants.UNPUBLISHED)
        bv_ = Version.objects.get(pk=bv.pk)
        self.assertEqual(bv_.state, constants.PUBLISHED)
コード例 #3
0
    def test_new_published_version_doesnt_change_status_of_published_versions_from_other_groupers(
            self):
        """When versions relating to different groupers have a new
        published version created, then this should not change the other
        published versions' status to unpublished.
        """
        factories.PollVersionFactory(state=constants.PUBLISHED)
        user = factories.UserFactory()
        version = factories.PollVersionFactory(state=constants.DRAFT)

        version.publish(user)

        # Both are still published versions because they relate to different groupers
        self.assertEqual(
            Version.objects.filter(state=constants.PUBLISHED).count(), 2)
コード例 #4
0
 def test_modified_date(self):
     pv = factories.PollVersionFactory()
     dt = datetime(2016, 6, 6, tzinfo=timezone.utc)
     with freeze_time(dt):
         pv.content.save()
     pv = Version.objects.get(pk=pv.pk)
     self.assertEqual(pv.modified, dt)
コード例 #5
0
    def test_new_published_version_causes_old_published_versions_to_change_to_unpublished(
        self
    ):
        """When versions relating to the same grouper have a new published
        version created, all old published version should be marked unpublished
        """
        poll = factories.PollFactory()
        factories.PollVersionFactory.create_batch(
            3, state=constants.PUBLISHED, content__poll=poll, content__language="en"
        )
        user = factories.UserFactory()
        version = factories.PollVersionFactory(
            state=constants.DRAFT, content__poll=poll, content__language="en"
        )

        version.publish(user)

        # Only one published version
        self.assertEqual(Version.objects.filter(state=constants.PUBLISHED).count(), 1)
        # Everything other than the last published version has status unpublished
        self.assertEqual(
            Version.objects.exclude(pk=version.pk)
            .filter(state=constants.UNPUBLISHED)
            .count(),
            3,
        )
コード例 #6
0
    def test_content_object_gets_duplicated_with_default_copy(self):
        """When copying, the new version object should have a new
        related content object. The default copy method will copy all
        content fields (other than the pk) exactly as they were.
        """
        original_version = factories.PollVersionFactory()
        user = factories.UserFactory()
        versioning_app_ext = apps.get_app_config(
            "djangocms_versioning").cms_extension
        versionables_mock = self._create_versionables_mock(default_copy)

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

        # Created a new content record
        self.assertNotEqual(original_version.content.pk,
                            new_version.content.pk)
        # Has the same fields as the original version
        self.assertEqual(original_version.content.text,
                         new_version.content.text)
        self.assertEqual(original_version.content.language,
                         new_version.content.language)
        self.assertEqual(original_version.content.poll,
                         new_version.content.poll)
コード例 #7
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)
コード例 #8
0
    def test_archive_signals_fired(self):
        """
        When a version is changed to archived the correct signals are fired!
        """
        poll = factories.PollFactory()
        version = factories.PollVersionFactory(
            state=constants.DRAFT, content__poll=poll
        )

        with signal_tester(pre_version_operation, post_version_operation) as env:

            version.archive(self.superuser)

            self.assertEqual(env.call_count, 2)

            pre_call_kwargs = env.calls[0][1]
            post_call_kwargs = env.calls[1][1]

            # pre call
            self.assertTrue(pre_call_kwargs["token"] == post_call_kwargs["token"])
            self.assertEqual(pre_call_kwargs["operation"], constants.OPERATION_ARCHIVE)
            self.assertEqual(
                pre_call_kwargs["sender"], version.content_type.model_class()
            )
            self.assertEqual(pre_call_kwargs["obj"], version)
            # post call
            self.assertTrue("token" in post_call_kwargs)
            self.assertEqual(post_call_kwargs["operation"], constants.OPERATION_ARCHIVE)
            self.assertEqual(
                post_call_kwargs["sender"], version.content_type.model_class()
            )
            self.assertEqual(post_call_kwargs["obj"], version)
コード例 #9
0
    def test_versioned_queryset_return_full_with_helper_method(self):
        """With an extra helper method we can return the full queryset"""
        factories.PollVersionFactory()
        normal_count = PollContent.objects.all()
        full_count = remove_published_where(PollContent.objects.all())

        self.assertEqual(normal_count.count(), 0)
        self.assertEqual(full_count.count(), 1)
コード例 #10
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)
コード例 #11
0
    def test_grouper_selector_default_label(self):
        """
        Grouper selector shows the default label format when no override is set
        """
        version = factories.PollVersionFactory()
        form_class = grouper_form_factory(PollContent, language='en')

        self.assertIn(
            (version.content.poll.pk, str(version.content.poll)),
            form_class.base_fields['grouper'].choices,
        )
コード例 #12
0
    def test_version_number_for_sequentially_created_versions(self):
        """
        An object being updated in sequential order without any other object versions
        increments for each version
        """
        poll_1 = factories.PollFactory()

        p1_version_1 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language="en")
        p1_version_2 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language="en")
        p1_version_3 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language="en")
        p1_version_4 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language="en")

        self.assertEqual(p1_version_1.number, 1)
        self.assertEqual(p1_version_2.number, 2)
        self.assertEqual(p1_version_3.number, 3)
        self.assertEqual(p1_version_4.number, 4)
コード例 #13
0
    def test_factory(self):
        pv = factories.PollVersionFactory()
        form_class = grouper_form_factory(PollContent, language='en')

        self.assertIn(forms.Form, form_class.mro())
        self.assertEqual(form_class.__name__, 'PollContentGrouperForm')
        self.assertIn('grouper', form_class.base_fields)
        self.assertIn(
            (pv.content.poll.pk, str(pv.content.poll)),
            form_class.base_fields['grouper'].choices,
        )
コード例 #14
0
    def test_filter_by_grouper(self):
        poll = factories.PollFactory()
        versions = factories.PollVersionFactory.create_batch(
            2, content__poll=poll)  # same grouper
        factories.PollVersionFactory()  # different grouper

        versions_for_grouper = Version.objects.filter_by_grouper(poll)

        self.assertQuerysetEqual(versions_for_grouper,
                                 [versions[0].pk, versions[1].pk],
                                 transform=lambda o: o.pk,
                                 ordered=False)
コード例 #15
0
    def test_published_change_to_unpublished_is_logged(self):
        version = factories.PollVersionFactory(state=constants.PUBLISHED)
        user = factories.UserFactory()

        version.unpublish(user)

        tracking = StateTracking.objects.get()
        self.assertEqual(tracking.version, version)
        self.assertEqual(tracking.date, now())
        self.assertEqual(tracking.old_state, constants.PUBLISHED)
        self.assertEqual(tracking.new_state, constants.UNPUBLISHED)
        self.assertEqual(tracking.user, user)
コード例 #16
0
    def test_draft_change_to_archived_is_logged(self):
        version = factories.PollVersionFactory(state=constants.DRAFT)
        user = factories.UserFactory()

        version.archive(user)

        tracking = StateTracking.objects.get()
        self.assertEqual(tracking.version, version)
        self.assertEqual(tracking.date, now())
        self.assertEqual(tracking.old_state, constants.DRAFT)
        self.assertEqual(tracking.new_state, constants.ARCHIVED)
        self.assertEqual(tracking.user, user)
コード例 #17
0
    def test_version_number_for_multiple_sources_created_versions_with_languages(
            self):
        """
        The same object with different laguages being updated at similar times
        makes no difference to the version numbers
        """
        poll_1 = factories.PollFactory()
        language_1 = "en"
        language_2 = "it"

        lang1_version_1 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_1)
        lang1_version_2 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_1)
        lang2_version_1 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_2)
        lang1_version_3 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_1)
        lang2_version_2 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_2)
        lang1_version_4 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_1)

        # Language 1 checks
        self.assertEqual(lang1_version_1.number, 1)
        self.assertEqual(lang1_version_2.number, 2)
        self.assertEqual(lang1_version_3.number, 3)
        self.assertEqual(lang1_version_4.number, 4)
        # Language 2 checks
        self.assertEqual(lang2_version_1.number, 1)
        self.assertEqual(lang2_version_2.number, 2)
コード例 #18
0
    def test_version_number_for_multiple_sources_created_versions(self):
        """
        Different objects being updated at similar times makes no difference to the version numbers
        P1 and P2 checks are mixed because versions can be created for different groupers at different times
        """
        poll_1 = factories.PollFactory()
        poll_2 = factories.PollFactory()
        language = "en"

        p1_version_1 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language=language)
        p1_version_2 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language=language)
        p2_version_1 = factories.PollVersionFactory(content__poll=poll_2,
                                                    content__language=language)
        p1_version_3 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language=language)
        p2_version_2 = factories.PollVersionFactory(content__poll=poll_2,
                                                    content__language=language)
        p1_version_4 = factories.PollVersionFactory(content__poll=poll_1,
                                                    content__language=language)

        # Poll 1 checks
        self.assertEqual(p1_version_1.number, 1)
        self.assertEqual(p1_version_2.number, 2)
        self.assertEqual(p1_version_3.number, 3)
        self.assertEqual(p1_version_4.number, 4)
        # Poll 2 checks
        self.assertEqual(p2_version_1.number, 1)
        self.assertEqual(p2_version_2.number, 2)
コード例 #19
0
    def test_deleting_last_version_deletes_grouper_as_well(self):
        """
        Deleting the last version deletes the grouper as well.
        """
        poll_1 = factories.PollFactory()
        language_1 = "en"
        language_2 = "it"

        lang1_version_1 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_1)
        lang2_version_1 = factories.PollVersionFactory(
            content__poll=poll_1, content__language=language_2)

        first_delete = lang1_version_1.delete()
        poll_exists = Poll.objects.filter(pk=poll_1.pk).exists()
        second_delete = lang2_version_1.delete()
        poll_removed = not Poll.objects.filter(pk=poll_1.pk).exists()

        self.assertEqual(first_delete[1]['last'], False)
        self.assertEqual(second_delete[1]['last'], True)
        self.assertEqual(poll_exists, True)
        self.assertEqual(poll_removed, True)
コード例 #20
0
    def test_convert_to_proxy(self):
        version = factories.PollVersionFactory()
        proxied_version = version.convert_to_proxy()

        cms_extension = apps.get_app_config(
            "djangocms_versioning").cms_extension
        versionable = cms_extension.versionables_by_content[PollContent]
        proxy_model = versionable.version_model_proxy

        self.assertNotEqual(version.__class__, proxied_version.__class__)
        # assert it's still a subclass of Version
        self.assertTrue(isinstance(proxied_version, Version))
        self.assertTrue(isinstance(proxied_version, proxy_model))
コード例 #21
0
 def test_version_list_url(self):
     pv = factories.PollVersionFactory(content__language="en")
     url = version_list_url(pv.content)
     parsed = urlparse(url)
     self.assertEqual(parsed.path,
                      "/en/admin/djangocms_versioning/pollcontentversion/")
     self.assertEqual(
         {k: v[0]
          for k, v in parse_qs(parsed.query).items()},
         {
             "poll": "1",
             "language": "en"
         },
     )
コード例 #22
0
    def test_filter_by_grouper_doesnt_include_other_content_types(self):
        """Regression test for a bug in which filtering by content_type
        field was missed in the query
        """
        pv = factories.PollVersionFactory(content__id=11)
        factories.BlogPostVersionFactory(content__id=11)

        versions_for_grouper = Version.objects.filter_by_grouper(
            pv.content.poll)

        # Only poll version included
        self.assertQuerysetEqual(versions_for_grouper, [pv.pk],
                                 transform=lambda o: o.pk,
                                 ordered=False)
コード例 #23
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)
コード例 #24
0
    def test_content_object_gets_duplicated_with_source(self):
        """When copying, the new version object should have a new
        related content object. The default copy method will copy all
        content fields (other than the pk) exactly as they were with source.
        """
        original_version = factories.PollVersionFactory()
        user = factories.UserFactory()
        versioning_app_ext = apps.get_app_config(
            "djangocms_versioning").cms_extension
        versionables_mock = self._create_versionables_mock(default_copy)

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

        self.assertEqual(original_version, new_version.source)
コード例 #25
0
    def test_new_version_object_gets_created(self):
        """When copying, a new version object should get created
        """
        with freeze_time("2017-07-07"):
            # Make sure created in the past
            original_version = factories.PollVersionFactory(state=PUBLISHED)
        user = factories.UserFactory()

        new_version = original_version.copy(user)

        # Created a new version record
        self.assertNotEqual(original_version.pk, new_version.pk)
        self.assertEqual(new_version.created, now())
        self.assertEqual(new_version.created_by, user)
        # The state should always be DRAFT no matter what the original
        # state was
        self.assertEqual(new_version.state, DRAFT)
コード例 #26
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)
コード例 #27
0
 def test_unpublished_cant_be_published(self):
     version = factories.PollVersionFactory(state=constants.UNPUBLISHED)
     self.assertFalse(version.can_be_published())
コード例 #28
0
 def test_unpublished_cant_change_to_unpublished(self):
     version = factories.PollVersionFactory(state=constants.UNPUBLISHED)
     user = factories.UserFactory()
     with self.assertRaises(TransitionNotAllowed):
         version.unpublish(user)
コード例 #29
0
 def test_published_can_change_to_unpublished(self):
     version = factories.PollVersionFactory(state=constants.PUBLISHED)
     user = factories.UserFactory()
     version.unpublish(user)
     self.assertEqual(version.state, constants.UNPUBLISHED)
コード例 #30
0
 def test_archived_cant_be_published(self):
     version = factories.PollVersionFactory(state=constants.ARCHIVED)
     self.assertFalse(version.can_be_published())