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)
    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)
    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)