Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

section "Creating Page objects within tests" does not actually work #11913

Open
ramonakira opened this issue May 1, 2024 · 0 comments
Open

Comments

@ramonakira
Copy link
Contributor

Trying to write tests for a few Wagtail 6 websites and looking at https://docs.wagtail.org/en/stable/advanced_topics/testing.html#creating-page-objects-within-tests, it seems this code is maybe old?

Pertinent section of the Wagtail docs

https://docs.wagtail.org/en/stable/advanced_topics/testing.html#creating-page-objects-within-tests

Details

The testing code that is there now returns an error:

django.db.utils.IntegrityError: null value in column "root_page_id" of relation "wagtailcore_site" violates not-null constraint
DETAIL: Failing row contains (1, testserver, 80, testserver, null, t).

The reason being that root = Page.get_first_root_node() does not actually return anything.

If we change the code to the following (just an example):

from wagtail.models import Locale, Site
from wagtail.test.utils import WagtailPageTestCase

...

class ContentPageTests(WagtailPageTestCase):
    @classmethod
    def setUpTestData(cls):
        # create a home page
        locale = Locale.objects.create(language_code="nl")

        cls.home_page = ContentPage.objects.create(
            title="Home Page", slug="home", locale=locale, depth=1, path="0001"
        )

        # Create a site with the home page set as the root
        cls.site = Site.objects.create(is_default_site=True, root_page=cls.home_page)

It works! (But not sure that it is even correct?)

Working on this

I could of course update the docs myself but I'm not sure if we maybe are missing something?

BTW, thanks for all your hard work, keep it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant