Repository: wagtail/wagtail
File: wagtail/admin/tests/pages/test_create_page.py (Python)

Code before:
        page = Page.objects.get(
            path__startswith=self.root_page.path, slug="hello-world"
        ).specific

        self.assertTrue(
            PageViewRestriction.objects.filter(
                page=page, restriction_type="password"
            ).count()
            == 1
        )

        SimplePage.get_default_privacy_setting = original_default_privacy_setting

    def test_create_default_privacy_page_user_groups(self):
        original_default_privacy_setting = SimplePage.get_default_privacy_setting
        post_data = {
            "title": "New page!",
            "content": "Some content",
            "slug": "hello-world",
            "action-publish": "Publish",
        }

        def get_default_privacy_setting(self, request):
            return {"type": "groups", "groups": []}

        SimplePage.get_default_privacy_setting = get_default_privacy_setting

        self.client.post(
            reverse(
                "wagtailadmin_pages:add",
                args=("tests", "simplepage", self.root_page.id),
            ),
            post_data,
        )

        # Find the page and check it
        page = Page.objects.get(
            path__startswith=self.root_page.path, slug="hello-world"
        ).specific

        self.assertTrue(
            PageViewRestriction.objects.filter(
                page=page, restriction_type="groups"
            ).count()
            == 1
        )

        SimplePage.get_default_privacy_setting = original_default_privacy_setting

    def test_create_nonexistantparent(self):
        response = self.client.get(

Review comment (bug):
Issue: If this test fails part way though, it can corrupt the model. If you need to change how this works, I'd recommend using `unittest.mock` instead.

Code after:
        post_data = {
            "title": "New page!",
            "content": "Some content",
            "slug": "hello-world",
            "action-publish": "Publish",
        }

        self.client.post(
            reverse(
                "wagtailadmin_pages:add",
                args=("tests", "simplepage", self.root_page.id),
            ),
            post_data,
        )

        # Find the page and check it
        page = Page.objects.get(
            path__startswith=self.root_page.path, slug="hello-world"
        ).specific

        self.assertEqual(
            PageViewRestriction.objects.filter(
                page=page, restriction_type="password"
            ).count(),
            1,
        )

    @mock.patch("wagtail.test.testapp.models.SimplePage.get_default_privacy_setting")
    def test_create_default_privacy_page_user_groups(
        self, mock_get_default_privacy_setting
    ):
        mock_get_default_privacy_setting.return_value = {"type": "groups", "groups": []}

        post_data = {
            "title": "New page!",
            "content": "Some content",
            "slug": "hello-world",
            "action-publish": "Publish",
        }

        self.client.post(
            reverse(
                "wagtailadmin_pages:add",
                args=("tests", "simplepage", self.root_page.id),
            ),
            post_data,
        )

        # Find the page and check it
        page = Page.objects.get(
            path__startswith=self.root_page.path, slug="hello-world"