Use WagtailTestCase class in admin page views tests

This commit is contained in:
Karl Hobley 2014-06-02 13:56:54 +01:00
parent a8ca4f14da
commit 00a06856a8

View file

@ -1,13 +1,12 @@
from django.test import TestCase
from wagtail.tests.models import SimplePage, EventPage
from wagtail.tests.utils import login, unittest
from wagtail.tests.utils import unittest, WagtailTestCase
from wagtail.wagtailcore.models import Page, PageRevision
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User, Permission
from django.core import mail
class TestPageExplorer(TestCase):
class TestPageExplorer(WagtailTestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
@ -19,7 +18,7 @@ class TestPageExplorer(TestCase):
self.root_page.add_child(instance=self.child_page)
# Login
login(self.client)
self.login()
def test_explore(self):
response = self.client.get(reverse('wagtailadmin_explore', args=(self.root_page.id, )))
@ -28,13 +27,13 @@ class TestPageExplorer(TestCase):
self.assertTrue(response.context['pages'].filter(id=self.child_page.id).exists())
class TestPageCreation(TestCase):
class TestPageCreation(WagtailTestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
# Login
self.user = login(self.client)
self.user = self.login()
def test_add_subpage(self):
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.root_page.id, )))
@ -86,6 +85,7 @@ class TestPageCreation(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# Find the page and check it
page = Page.objects.get(path__startswith=self.root_page.path, slug='hello-world').specific
@ -104,6 +104,7 @@ class TestPageCreation(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# Find the page and check it
page = Page.objects.get(path__startswith=self.root_page.path, slug='hello-world').specific
@ -126,6 +127,7 @@ class TestPageCreation(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# Find the page and check it
page = Page.objects.get(path__startswith=self.root_page.path, slug='hello-world').specific
@ -186,7 +188,7 @@ class TestPageCreation(TestCase):
self.assertContains(response, "New page!")
class TestPageEdit(TestCase):
class TestPageEdit(WagtailTestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
@ -206,7 +208,7 @@ class TestPageEdit(TestCase):
self.root_page.add_child(instance=self.event_page)
# Login
self.user = login(self.client)
self.user = self.login()
def test_page_edit(self):
# Tests that the edit page loads
@ -238,6 +240,7 @@ class TestPageEdit(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# The page should have "has_unpublished_changes" flag set
child_page_new = SimplePage.objects.get(id=self.child_page.id)
@ -255,6 +258,7 @@ class TestPageEdit(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# Check that the page was edited
child_page_new = SimplePage.objects.get(id=self.child_page.id)
@ -278,6 +282,7 @@ class TestPageEdit(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# The page should have "has_unpublished_changes" flag set
child_page_new = SimplePage.objects.get(id=self.child_page.id)
@ -306,7 +311,7 @@ class TestPageEdit(TestCase):
self.assertContains(response, "I've been edited!")
class TestPageDelete(TestCase):
class TestPageDelete(WagtailTestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
@ -318,7 +323,7 @@ class TestPageDelete(TestCase):
self.root_page.add_child(instance=self.child_page)
# Login
self.user = login(self.client)
self.user = self.login()
def test_page_delete(self):
response = self.client.get(reverse('wagtailadmin_pages_delete', args=(self.child_page.id, )))
@ -344,15 +349,16 @@ class TestPageDelete(TestCase):
# Should be redirected to explorer page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# Check that the page is gone
self.assertEqual(Page.objects.filter(path__startswith=self.root_page.path, slug='hello-world').count(), 0)
class TestPageSearch(TestCase):
class TestPageSearch(WagtailTestCase):
def setUp(self):
# Login
login(self.client)
self.login()
def get(self, params=None, **extra):
return self.client.get(reverse('wagtailadmin_pages_search'), params or {}, **extra)
@ -390,7 +396,7 @@ class TestPageSearch(TestCase):
self.assertTrue(any([r.slug == 'root' for r in results]))
class TestPageMove(TestCase):
class TestPageMove(WagtailTestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
@ -413,7 +419,7 @@ class TestPageMove(TestCase):
self.section_a.add_child(instance=self.test_page)
# Login
self.user = login(self.client)
self.user = self.login()
def test_page_move(self):
response = self.client.get(reverse('wagtailadmin_pages_move', args=(self.test_page.id, )))
@ -442,18 +448,18 @@ class TestPageMove(TestCase):
self.assertEqual(response.status_code, 200)
class TestPageUnpublish(TestCase):
class TestPageUnpublish(WagtailTestCase):
def setUp(self):
self.user = login(self.client)
self.user = self.login()
# Create a page to unpublish
root_page = Page.objects.get(id=2)
self.root_page = Page.objects.get(id=2)
self.page = SimplePage(
title="Hello world!",
slug='hello-world',
live=True,
)
root_page.add_child(instance=self.page)
self.root_page.add_child(instance=self.page)
def test_unpublish_view(self):
"""
@ -502,14 +508,15 @@ class TestPageUnpublish(TestCase):
'foo': "Must post something or the view won't see this as a POST request",
})
# Check that the user was redirected
# Check that the user was redirected to the explore page
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_explore', args=(self.root_page.id, )))
# Check that the page was unpublished
self.assertFalse(SimplePage.objects.get(id=self.page.id).live)
class TestApproveRejectModeration(TestCase):
class TestApproveRejectModeration(WagtailTestCase):
def setUp(self):
self.submitter = User.objects.create_superuser(
username='submitter',
@ -517,7 +524,7 @@ class TestApproveRejectModeration(TestCase):
password='password',
)
self.user = login(self.client)
self.user = self.login()
# Create a page and submit it for moderation
root_page = Page.objects.get(id=2)
@ -540,8 +547,9 @@ class TestApproveRejectModeration(TestCase):
'foo': "Must post something or the view won't see this as a POST request",
})
# Check that the user was redirected
# Check that the user was redirected to the dashboard
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_home'))
# Page must be live
self.assertTrue(Page.objects.get(id=self.page.id).live)
@ -591,8 +599,9 @@ class TestApproveRejectModeration(TestCase):
'foo': "Must post something or the view won't see this as a POST request",
})
# Check that the user was redirected
# Check that the user was redirected to the dashboard
self.assertEqual(response.status_code, 302)
self.assertURLEqual(response.url, reverse('wagtailadmin_home'))
# Page must not be live
self.assertFalse(Page.objects.get(id=self.page.id).live)
@ -645,11 +654,11 @@ class TestApproveRejectModeration(TestCase):
self.assertContains(response, "Hello world!")
class TestContentTypeUse(TestCase):
class TestContentTypeUse(WagtailTestCase):
fixtures = ['test.json']
def setUp(self):
self.user = login(self.client)
self.user = self.login()
def test_content_type_use(self):
# Get use of event page