title: Testing Django Wagtail - assert that a child of the given Page type can be created under the parent, using the supplied POST data
body: <p>I've defined a custom page model (a blog post) as a child of a parent model (a blog index page) and I want to test that the child can be created under its parent.</p>
  <p>The BlogPage and BlogIndexPage models are copied from the wagtail &quot;basic blog&quot; example in the documentation, and works as expected.</p>
  <p>I'm trying to follow the <a href="https://docs.wagtail.org/en/v2.16.1/advanced_topics/testing.html#wagtail.tests.utils.WagtailPageTests.assertCanCreate" rel="nofollow noreferrer">documentation</a> but I get the following validation error:</p>
  <pre class="lang-sh prettyprint-override"><code>AssertionError: Validation errors found when creating a cms.blogpage:
  E             date:
  E               This field is required.
  E             intro:
  E               This field is required.
  E             slug:
  E               This field is required.
  E             title:
  E               This field is required.
  </code></pre>
  <p>I suspect that I'm defining my fixture incorrectly, but I am not what the correct form is. Any help is greatly appreciated! Can someone explain why it isn't working?</p>
  <p>fixture (apps.cms.tests.fixtures.blogPage.json):</p>
  <pre><code>[
    {
      &quot;model&quot;:&quot;wagtailcore.page&quot;,
      &quot;pk&quot;: 1,
      &quot;fields&quot;:{
        &quot;date&quot;:&quot;2022-02-28&quot;,
        &quot;intro&quot;:&quot;intro to the post...&quot;,
        &quot;slug&quot;:&quot;slug/&quot;,
        &quot;title&quot;:&quot;the title&quot;,
        &quot;body&quot;:&quot;body of the post...&quot;,
        &quot;categories&quot;:[
          1
        ],
        &quot;content_type&quot;: [&quot;cms&quot;, &quot;blogpage&quot;],
        &quot;depth&quot;: 2
      }
    },
    {
      &quot;model&quot;: &quot;cms.blogpage&quot;,
      &quot;pk&quot;: 1,
      &quot;fields&quot;: {}
    }
  ]
  </code></pre>
  <p>the test class (apps.cms.tests.test_pages.py):</p>
  <pre class="lang-py prettyprint-override"><code>class MyPageTests(WagtailPageTests):
      def setUp(self):
          self.login()
          page = BlogIndexPage(title=&quot;Home page&quot;, slug=&quot;home&quot;, path=&quot;foo&quot;, depth=1)
          page.save()
  
      def test_create_blog_post(self):
          cwd = Path.cwd()
          root_page = BlogIndexPage.objects.first()
          with open(f&quot;{cwd}/lettergun/apps/cms/tests/fixtures/BlogPage.json&quot;) as json_file:
              fixture = json.load(json_file)
  
          # Assert that a ContentPage can be made here, with this POST data
          self.assertCanCreate(root_page, BlogPage, nested_form_data(fixture))
  
  </code></pre>
  <p>the models (apps.cms.models.py):</p>
  <pre class="lang-py prettyprint-override"><code>class BlogIndexPage(Page):
      template = &quot;blog.html&quot;
      intro = models.TextField(blank=True)
  
      def get_context(self, request):
          # Update context to include only published posts, ordered by reverse-chron
          context = super().get_context(request)
          blogpages = self.get_children().live().order_by(&quot;-first_published_at&quot;)
          context[&quot;blogpages&quot;] = blogpages
          return context
  
      content_panels = Page.content_panels + [FieldPanel(&quot;intro&quot;, classname=&quot;full&quot;)]
  
  
  class BlogPageTag(TaggedItemBase):
      content_object = ParentalKey(&quot;BlogPage&quot;, related_name=&quot;tagged_items&quot;, on_delete=models.CASCADE)
  
  
  class BlogPage(Page):
      template = &quot;blog-post.html&quot;
  
      date = models.DateField(&quot;Post date&quot;)
      intro = models.CharField(max_length=250)
      body = RichTextField(blank=True)
      tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
      categories = ParentalManyToManyField(&quot;cms.BlogCategory&quot;, blank=True)
  
      def main_image(self):
          gallery_item = self.gallery_images.first()
          if gallery_item:
              return gallery_item.image
          else:
              return None
  
      search_fields = Page.search_fields + [
          index.SearchField(&quot;intro&quot;),
          index.SearchField(&quot;body&quot;),
      ]
  
      content_panels = Page.content_panels + [
          MultiFieldPanel(
              [
                  FieldPanel(&quot;date&quot;),
                  FieldPanel(&quot;tags&quot;),
                  FieldPanel(&quot;categories&quot;, widget=forms.CheckboxSelectMultiple),
              ],
              heading=&quot;Blog information&quot;,
          ),
          FieldPanel(&quot;intro&quot;),
          FieldPanel(&quot;body&quot;),
          InlinePanel(&quot;gallery_images&quot;, label=&quot;Gallery images&quot;),
      ]
  
  </code></pre>