I need to create some tests against my APIs. APIs use wagtail pages and serve me the contents of them. I'm at the point of creating the database for the tests, but I'm not able to create wagtail pages, because I always get
ValidationError: {'path': [u'This field cannot be blank.'], 'depth': [u'This field cannot be null.']}
How can I do it? Do I have to create the entire site from the root down to the tree?
depth - it's a nesting level. The ROOT page has level 1, the main page has level 2, Obviously, only 1 page can be on the first and second level
path - this is a specific value, which I have not yet understood.
The ROOT page (depth = 1) has this path: 0001,
The main page on the second nesting level (depth = 2) has the path 00010001.
The first page on the third nesting level (depth = 3) has the path 000100010001
I can not guarantee that I give you advice that will work, since I did it for a long time, But if you want to generate fake pages at the same level of nesting, you only need to change the path, adding + 1 to the last digit, and leaving the depth unchanged.
By example:
from yourapp.models import FakePage
k = 1
for i in range(5):
k = k + 1
page = FakePage(
title = ('faketitle{}').format(k),
path = ('{0:04}').format(k)
depth = 3,
)
page.save()
But there is a better way:
from wagtail.wagtailcore.models import Page
from yourapp.models import FakePage
pages = Page.objects.all() # Get all pages
page = Page.objects.get(pk=3) # For example, take a page with pk = 3
fakepage = FakePage(title='fakepage title') # Create the desired page
page.add_child(instance=fakepage) # Add children page to the parrent page
In this case, you do not need to worry about the depth and the path.