Exemple #1
0
class TestCompareRevisionsWithPerUserEditHandlers(TestCase, WagtailTestUtils):
    fixtures = ["test.json"]

    def setUp(self):
        self.home = Page.objects.get(url_path="/home/")
        self.secret_page = SecretPage(
            title="Secret page",
            boring_data="InnocentCorp is the leading supplier of door hinges",
            secret_data="for flying saucers",
        )
        self.home.add_child(instance=self.secret_page)
        self.old_revision = self.secret_page.save_revision()
        self.secret_page.boring_data = (
            "InnocentCorp is the leading supplier of rubber sprockets")
        self.secret_page.secret_data = "for fake moon landings"
        self.new_revision = self.secret_page.save_revision()
        self.compare_url = reverse(
            "wagtailadmin_pages:revisions_compare",
            args=(self.secret_page.id, self.old_revision.id,
                  self.new_revision.id),
        )

    def test_comparison_as_superuser(self):
        self.login()
        response = self.client.get(self.compare_url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(
            response,
            'InnocentCorp is the leading supplier of <span class="deletion">door hinges</span><span class="addition">rubber sprockets</span>',
            html=True,
        )
        self.assertContains(
            response,
            'for <span class="deletion">flying saucers</span><span class="addition">fake moon landings</span>',
            html=True,
        )

    def test_comparison_as_ordinary_user(self):
        user = self.create_user(username="******", password="******")
        user.groups.add(Group.objects.get(name="Site-wide editors"))
        self.login(username="******", password="******")

        response = self.client.get(self.compare_url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(
            response,
            'InnocentCorp is the leading supplier of <span class="deletion">door hinges</span><span class="addition">rubber sprockets</span>',
            html=True,
        )
        self.assertNotContains(
            response,
            "moon landings",
        )
Exemple #2
0
 def setUp(self):
     self.home = Page.objects.get(url_path="/home/")
     self.secret_page = SecretPage(
         title="Secret page",
         boring_data="InnocentCorp is the leading supplier of door hinges",
         secret_data="for flying saucers",
     )
     self.home.add_child(instance=self.secret_page)
     self.old_revision = self.secret_page.save_revision()
     self.secret_page.boring_data = (
         "InnocentCorp is the leading supplier of rubber sprockets")
     self.secret_page.secret_data = "for fake moon landings"
     self.new_revision = self.secret_page.save_revision()
     self.compare_url = reverse(
         "wagtailadmin_pages:revisions_compare",
         args=(self.secret_page.id, self.old_revision.id,
               self.new_revision.id),
     )
Exemple #3
0
    def setUp(self):
        self.page = SimplePage(
            title="Hello world!",
            slug="hello-world",
            content="hello",
            live=False,
            expire_at=timezone.now() - timedelta(days=1),
        )

        Page.objects.get(id=2).add_child(instance=self.page)

        # Create empty revisions, which should not be converted to log entries
        for i in range(3):
            self.page.save_revision()

        # Add another revision with a content change
        self.page.title = "Hello world!!"
        revision = self.page.save_revision()
        revision.publish()

        # Do the same with a SecretPage (to check that the version comparison code doesn't
        # trip up on permission-dependent edit handlers)
        self.secret_page = SecretPage(
            title="The moon",
            slug="the-moon",
            boring_data="the moon",
            secret_data="is made of cheese",
            live=False,
        )

        Page.objects.get(id=2).add_child(instance=self.secret_page)

        # Create empty revisions, which should not be converted to log entries
        for i in range(3):
            self.secret_page.save_revision()

        # Add another revision with a content change
        self.secret_page.secret_data = "is flat"
        revision = self.secret_page.save_revision()
        revision.publish()

        # clean up log entries
        PageLogEntry.objects.all().delete()
Exemple #4
0
class TestCreateLogEntriesFromRevisionsCommand(TestCase):
    fixtures = ["test.json"]

    def setUp(self):
        self.page = SimplePage(
            title="Hello world!",
            slug="hello-world",
            content="hello",
            live=False,
            expire_at=timezone.now() - timedelta(days=1),
        )

        Page.objects.get(id=2).add_child(instance=self.page)

        # Create empty revisions, which should not be converted to log entries
        for i in range(3):
            self.page.save_revision()

        # Add another revision with a content change
        self.page.title = "Hello world!!"
        revision = self.page.save_revision()
        revision.publish()

        # Do the same with a SecretPage (to check that the version comparison code doesn't
        # trip up on permission-dependent edit handlers)
        self.secret_page = SecretPage(
            title="The moon",
            slug="the-moon",
            boring_data="the moon",
            secret_data="is made of cheese",
            live=False,
        )

        Page.objects.get(id=2).add_child(instance=self.secret_page)

        # Create empty revisions, which should not be converted to log entries
        for i in range(3):
            self.secret_page.save_revision()

        # Add another revision with a content change
        self.secret_page.secret_data = "is flat"
        revision = self.secret_page.save_revision()
        revision.publish()

        # clean up log entries
        PageLogEntry.objects.all().delete()

    def test_log_entries_created_from_revisions(self):
        management.call_command("create_log_entries_from_revisions")

        # Should not create entries for empty revisions.
        self.assertListEqual(
            list(PageLogEntry.objects.values_list("action", flat=True)),
            [
                "wagtail.publish",
                "wagtail.edit",
                "wagtail.create",
                "wagtail.publish",
                "wagtail.edit",
                "wagtail.create",
            ],
        )

    def test_command_doesnt_crash_for_revisions_without_page_model(self):
        with mock.patch(
                "wagtail.models.ContentType.model_class",
                return_value=None,
        ):
            management.call_command("create_log_entries_from_revisions")
            self.assertEqual(PageLogEntry.objects.count(), 0)