mardi 7 mars 2017

Testing Wagtail page views using client.get

I want to test my views functionality for a Wagtail Page that uses the RoutablePageMixin. I've found that Wagtail includes some testing functionality, but I'm trying to check the content on different urls. Although the Wagtail test functions work, testing using self.client.get doesn't work -- I get an 404 response. I'm trying the following test:

def test_subpage(self):
    response = self.client.get(
        self.page.full_url + self.page.reverse_subpage('subpage')
    )
    self.assertEqual(response.status_code, 200,
                     'Request the open positions page')

I assume the error lies in the way in which the page is created. I have used several ways, but cannot find one for which this works. The most intuitive way I found to create the page is the following:

def setUp(self):
    self.login()
    parent = Page.get_root_nodes()[0] # Home

    self.assertCanCreate(parent, MyPage, {
        'title': 'Title!',
        'title_sv': 'Title2!',
        'slug': 'test',
        'published': datetime.datetime.now(),
    })

    self.page = MyPage.objects.get(slug='apply')

The subpages have been manually tested and do seem to work.

Aucun commentaire:

Enregistrer un commentaire