Repository: wagtail/wagtail
File: wagtail/tests/test_page_model.py (Python)

Code before:

        homepage = Page.objects.get(url_path="/home/")
        new_page = page.copy(to=homepage)

        self.assertNotEqual(page.id, new_page.id)

    def test_copy_page_with_additional_excluded_fields(self):
        homepage = Page.objects.get(url_path="/home/")
        page = PageWithExcludedCopyField(
            title="Discovery",
            slug="disco",
            content="NCC-1031",
            special_field="Context is for Kings",
            special_stream=[("item", "non-default item")],
        )
        page.special_notes = [ExcludedCopyPageNote(note="Some note")]
        homepage.add_child(instance=page)
        page.save_revision()
        new_page = page.copy(to=homepage, update_attrs={"slug": "disco-2"})
        revision_content = new_page.latest_revision.content

        self.assertEqual(page.title, new_page.title)
        self.assertNotEqual(page.id, new_page.id)
        self.assertNotEqual(page.path, new_page.path)

        # special_field and special_Stream are in the list to be excluded,
        # and should revert to the default
        self.assertEqual(new_page.special_field, "Very Special")
        self.assertEqual(revision_content["special_field"], "Very Special")
        self.assertEqual(new_page.special_stream[0].value, "default item")
        stream_data = json.loads(revision_content["special_stream"])
        self.assertEqual(stream_data[0]["value"], "default item")

        # The special_notes relation should be cleared on the new page
        self.assertEqual(new_page.special_notes.count(), 0)
        self.assertEqual(revision_content["special_notes"], [])

    def test_page_with_generic_relation(self):
        """Test that a page with a GenericRelation will have that relation ignored when
        copying.
        """
        homepage = Page.objects.get(url_path="/home/")
        original_page = homepage.add_child(
            instance=PageWithGenericRelation(
                title="PageWithGenericRelation",
                slug="page-with-generic-relation",
                live=True,
                has_unpublished_changes=False,
            )
        )
        RelatedGenericRelation.objects.create(content_object=original_page)

Review comment (suggestion):
```suggestion
        # special_field and special_stream are in the list to be excluded,
```

Code after:

        homepage = Page.objects.get(url_path="/home/")
        new_page = page.copy(to=homepage)

        self.assertNotEqual(page.id, new_page.id)

    def test_copy_page_with_additional_excluded_fields(self):
        homepage = Page.objects.get(url_path="/home/")
        page = PageWithExcludedCopyField(
            title="Discovery",
            slug="disco",
            content="NCC-1031",
            special_field="Context is for Kings",
            special_stream=[("item", "non-default item")],
        )
        page.special_notes = [ExcludedCopyPageNote(note="Some note")]
        homepage.add_child(instance=page)
        page.save_revision()
        new_page = page.copy(to=homepage, update_attrs={"slug": "disco-2"})
        revision_content = new_page.latest_revision.content

        self.assertEqual(page.title, new_page.title)
        self.assertNotEqual(page.id, new_page.id)
        self.assertNotEqual(page.path, new_page.path)

        # special_field and special_stream are in the list to be excluded,
        # and should revert to the default
        self.assertEqual(new_page.special_field, "Very Special")
        self.assertEqual(revision_content["special_field"], "Very Special")
        self.assertEqual(new_page.special_stream[0].value, "default item")
        stream_data = json.loads(revision_content["special_stream"])
        self.assertEqual(stream_data[0]["value"], "default item")

        # The special_notes relation should be cleared on the new page
        self.assertEqual(new_page.special_notes.count(), 0)
        self.assertEqual(revision_content["special_notes"], [])

    def test_page_with_generic_relation(self):
        """Test that a page with a GenericRelation will have that relation ignored when
        copying.
        """
        homepage = Page.objects.get(url_path="/home/")
        original_page = homepage.add_child(
            instance=PageWithGenericRelation(
                title="PageWithGenericRelation",
                slug="page-with-generic-relation",
                live=True,
                has_unpublished_changes=False,
            )
        )
        RelatedGenericRelation.objects.create(content_object=original_page)