0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-24 10:58:52 +01:00

Merge branch 'tests' into search-changes

Conflicts:
	runtests.py
This commit is contained in:
Karl Hobley 2014-02-23 16:13:58 +00:00
commit a3d8511f0b
11 changed files with 351 additions and 69 deletions

View File

@ -8,6 +8,7 @@ from django.core.management import execute_from_command_line
WAGTAIL_ROOT = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(WAGTAIL_ROOT, 'test-static')
MEDIA_ROOT = os.path.join(WAGTAIL_ROOT, 'test-media')
if not settings.configured:
settings.configure(
@ -21,6 +22,7 @@ if not settings.configured:
ROOT_URLCONF='wagtail.tests.urls',
STATIC_URL='/static/',
STATIC_ROOT=STATIC_ROOT,
MEDIA_ROOT=MEDIA_ROOT,
STATICFILES_FINDERS=(
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
@ -61,6 +63,7 @@ if not settings.configured:
'wagtail.wagtailembeds',
'wagtail.wagtailsearch',
'wagtail.wagtailredirects',
'wagtail.tests',
],
WAGTAILSEARCH_BACKENDS = {
'default': {
@ -77,6 +80,7 @@ def runtests():
execute_from_command_line(argv)
finally:
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
if __name__ == '__main__':

206
wagtail/tests/models.py Normal file
View File

@ -0,0 +1,206 @@
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel, PageChooserPanel
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel
EVENT_AUDIENCE_CHOICES = (
('public', "Public"),
('private', "Private"),
)
COMMON_PANELS = (
FieldPanel('slug'),
FieldPanel('seo_title'),
FieldPanel('show_in_menus'),
FieldPanel('search_description'),
)
# Link fields
class LinkFields(models.Model):
link_external = models.URLField("External link", blank=True)
link_page = models.ForeignKey(
'wagtailcore.Page',
null=True,
blank=True,
related_name='+'
)
link_document = models.ForeignKey(
'wagtaildocs.Document',
null=True,
blank=True,
related_name='+'
)
@property
def link(self):
if self.link_page:
return self.link_page.url
elif self.link_document:
return self.link_document.url
else:
return self.link_external
panels = [
FieldPanel('link_external'),
PageChooserPanel('link_page'),
DocumentChooserPanel('link_document'),
]
class Meta:
abstract = True
# Carousel items
class CarouselItem(LinkFields):
image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
embed_url = models.URLField("Embed URL", blank=True)
caption = models.CharField(max_length=255, blank=True)
panels = [
ImageChooserPanel('image'),
FieldPanel('embed_url'),
FieldPanel('caption'),
MultiFieldPanel(LinkFields.panels, "Link"),
]
class Meta:
abstract = True
# Related links
class RelatedLink(LinkFields):
title = models.CharField(max_length=255, help_text="Link title")
panels = [
FieldPanel('title'),
MultiFieldPanel(LinkFields.panels, "Link"),
]
class Meta:
abstract = True
# Event page
class EventPageCarouselItem(Orderable, CarouselItem):
page = ParentalKey('tests.EventPage', related_name='carousel_items')
class EventPageRelatedLink(Orderable, RelatedLink):
page = ParentalKey('tests.EventPage', related_name='related_links')
class EventPageSpeaker(Orderable, LinkFields):
page = ParentalKey('tests.EventPage', related_name='speakers')
first_name = models.CharField("Name", max_length=255, blank=True)
last_name = models.CharField("Surname", max_length=255, blank=True)
image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
@property
def name_display(self):
return self.first_name + " " + self.last_name
panels = [
FieldPanel('first_name'),
FieldPanel('last_name'),
ImageChooserPanel('image'),
MultiFieldPanel(LinkFields.panels, "Link"),
]
class EventPage(Page):
date_from = models.DateField("Start date", null=True)
date_to = models.DateField(
"End date",
null=True,
blank=True,
help_text="Not required if event is on a single day"
)
time_from = models.TimeField("Start time", null=True, blank=True)
time_to = models.TimeField("End time", null=True, blank=True)
audience = models.CharField(max_length=255, choices=EVENT_AUDIENCE_CHOICES)
location = models.CharField(max_length=255)
body = RichTextField(blank=True)
cost = models.CharField(max_length=255)
signup_link = models.URLField(blank=True)
feed_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
indexed_fields = ('get_audience_display', 'location', 'body')
search_name = "Event"
@property
def event_index(self):
# Find event index in ancestors
for ancestor in reversed(self.get_ancestors()):
if isinstance(ancestor.specific, EventIndexPage):
return ancestor
# No ancestors are event indexes,
# just return first event index in database
return EventIndexPage.objects.first()
def serve(self, request):
if "format" in request.GET:
if request.GET['format'] == 'ical':
# Export to ical format
response = HttpResponse(
export_event(self, 'ical'),
content_type='text/calendar',
)
response['Content-Disposition'] = 'attachment; filename=' + self.slug + '.ics'
return response
else:
# Unrecognised format error
message = 'Could not export event\n\nUnrecognised format: ' + request.GET['format']
return HttpResponse(message, content_type='text/plain')
else:
# Display event page as usual
return super(EventPage, self).serve(request)
EventPage.content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('date_from'),
FieldPanel('date_to'),
FieldPanel('time_from'),
FieldPanel('time_to'),
FieldPanel('location'),
FieldPanel('audience'),
FieldPanel('cost'),
FieldPanel('signup_link'),
InlinePanel(EventPage, 'carousel_items', label="Carousel items"),
FieldPanel('body', classname="full"),
InlinePanel(EventPage, 'speakers', label="Speakers"),
InlinePanel(EventPage, 'related_links', label="Related links"),
]
EventPage.promote_panels = [
MultiFieldPanel(COMMON_PANELS, "Common page configuration"),
ImageChooserPanel('feed_image'),
]

View File

@ -2,7 +2,7 @@ from wagtail.wagtailcore.models import Site
from django.contrib.auth.models import User
def get_default_host():
def get_host():
return Site.objects.filter(is_default_site=True).first().root_url.split('://')[1]
@ -11,4 +11,4 @@ def login(client):
User.objects.create_superuser(username='test', email='test@email.com', password='password')
# Login
client.login(username='test', password='password')
client.login(username='test', password='password')

View File

@ -1,14 +1,111 @@
from django.test import TestCase
from django.contrib.auth.models import User
import unittest
from wagtail.tests.models import EventPage
from wagtail.tests.utils import login, get_host
from wagtail.wagtailcore.models import Page
from django.core.urlresolvers import reverse
class TestPageExplorer(TestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
# Add child page
self.child_page = EventPage()
self.child_page.title = "Hello world!"
self.child_page.slug = "hello-world"
self.root_page.add_child(self.child_page)
# Login
login(self.client)
def test_explore(self):
response = self.client.get(reverse('wagtailadmin_explore', args=(self.root_page.id, )), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
self.assertEqual(self.root_page, response.context['parent_page'])
self.assertTrue(response.context['pages'].filter(id=self.child_page.id).exists())
class TestPageCreation(TestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
# Login
login(self.client)
def test_select_type(self):
response = self.client.get(reverse('wagtailadmin_pages_select_type'), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
@unittest.expectedFailure # For some reason, this returns a 302...
def test_select_location_testpage(self):
response = self.client.get(reverse('wagtailadmin_pages_select_location', args=('tests', 'eventpage')), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
def test_select_location_nonexistanttype(self):
response = self.client.get(reverse('wagtailadmin_pages_select_location', args=('notanapp', 'notamodel')), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 404)
def test_select_location_nonpagetype(self):
response = self.client.get(reverse('wagtailadmin_pages_select_location', args=('wagtailimages', 'image')), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 404)
def test_add_subpage_root(self):
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.root_page.id, )), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
def test_add_subpage_nonexistant(self):
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(100000, )), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 404)
def test_create_testpage_root(self):
response = self.client.get(reverse('wagtailadmin_pages_create', args=('tests', 'eventpage', self.root_page.id)), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
def test_create_testpage_nonexistantparent(self):
response = self.client.get(reverse('wagtailadmin_pages_create', args=('tests', 'testpage', 100000)), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 404)
@unittest.expectedFailure # FIXME: Crashes!
def test_create_nonpagetype(self):
response = self.client.get(reverse('wagtailadmin_pages_create', args=('wagtailimages', 'image', self.root_page.id)), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 404)
class TestPageEditDelete(TestCase):
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
# Add child page
self.child_page = EventPage()
self.child_page.title = "Hello world!"
self.child_page.slug = "hello-world"
self.root_page.add_child(self.child_page)
# Login
login(self.client)
def test_edit(self):
response = self.client.get(reverse('wagtailadmin_pages_edit', args=(self.child_page.id, )), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
def test_delete(self):
response = self.client.get(reverse('wagtailadmin_pages_delete', args=(self.child_page.id, )), HTTP_HOST=get_host())
self.assertEqual(response.status_code, 200)
class TestPageSearch(TestCase):
def test_root_can_appear_in_search_results(self):
User.objects.create_superuser(username='test', email='test@email.com', password='password')
self.client.login(username='test', password='password')
def setUp(self):
# Login
login(self.client)
def test_root_can_appear_in_search_results(self):
response = self.client.get('/admin/pages/search/?q=roo')
self.assertEqual(response.status_code, 200)
# 'pages' list in the response should contain root
results = response.context['pages']
self.assertTrue(any([r.slug == 'root' for r in results]))

View File

@ -1,6 +1,6 @@
from django.test import TestCase
from wagtail.wagtaildocs import models
from wagtail.wagtailcore.models import Site
from wagtail.tests.utils import login, get_host
from django.contrib.auth.models import User, Group, Permission
from django.core.urlresolvers import reverse
@ -37,24 +37,13 @@ class TestDocumentPermissions(TestCase):
## ===== ADMIN VIEWS =====
def get_default_host():
return Site.objects.filter(is_default_site=True).first().root_url.split('://')[1]
def login(client):
# Create a user
User.objects.create_superuser(username='test', email='test@email.com', password='password')
# Login
client.login(username='test', password='password')
class TestDocumentIndexView(TestCase):
def setUp(self):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_index'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_index'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -82,7 +71,7 @@ class TestDocumentAddView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_add_document'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_add_document'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -96,7 +85,7 @@ class TestDocumentEditView(TestCase):
self.document = models.Document.objects.create(title="Test document")
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_edit_document', args=(self.document.id,)), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_edit_document', args=(self.document.id,)), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -110,7 +99,7 @@ class TestDocumentDeleteView(TestCase):
self.document = models.Document.objects.create(title="Test document")
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_delete_document', args=(self.document.id,)), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_delete_document', args=(self.document.id,)), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -121,7 +110,7 @@ class TestDocumentChooserView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_chooser'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_chooser'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -146,7 +135,7 @@ class TestDocumentChooserChosenView(TestCase):
self.document = models.Document.objects.create(title="Test document")
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_document_chosen', args=(self.document.id,)), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_document_chosen', args=(self.document.id,)), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -157,7 +146,7 @@ class TestDocumentChooserUploadView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtaildocs_chooser_upload'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtaildocs_chooser_upload'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)

View File

@ -1,5 +1,6 @@
from django.test import TestCase
from django.test.client import Client
from wagtail.tests.utils import login, get_host
from wagtail.wagtailembeds import get_embed
@ -45,24 +46,13 @@ class TestEmbeds(TestCase):
}
def get_default_host():
from wagtail.wagtailcore.models import Site
return Site.objects.filter(is_default_site=True).first().root_url.split('://')[1]
class TestChooser(TestCase):
def setUp(self):
# Create a user
from django.contrib.auth.models import User
User.objects.create_superuser(username='test', email='test@email.com', password='password')
# Setup client
self.c = Client()
login = self.c.login(username='test', password='password')
self.assertEqual(login, True)
# login
login(self.client)
def test_chooser(self):
r = self.c.get('/admin/embeds/chooser/', HTTP_HOST=get_default_host())
r = self.client.get('/admin/embeds/chooser/', HTTP_HOST=get_host())
self.assertEqual(r.status_code, 200)
# TODO: Test submitting

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -2,13 +2,20 @@ from django.test import TestCase
from django import template
from django.contrib.auth.models import User, Group, Permission
from django.core.urlresolvers import reverse
from wagtail.wagtailcore.models import Site
from wagtail.tests.utils import login, get_host
from wagtail.wagtailimages.models import get_image_model
from wagtail.wagtailimages.templatetags import image_tags
def get_test_image_file():
return 'wagtail/wagtailimages/static/wagtailimages/images/test.png'
from StringIO import StringIO
from PIL import Image
from django.core.files.images import ImageFile
f = StringIO()
image = Image.new('RGB', (640, 480), 'white')
image.save(f, 'PNG')
return ImageFile(f, name='test.png')
Image = get_image_model()
@ -123,24 +130,13 @@ class TestImageTag(TestCase):
## ===== ADMIN VIEWS =====
def get_default_host():
return Site.objects.filter(is_default_site=True).first().root_url.split('://')[1]
def login(client):
# Create a user
User.objects.create_superuser(username='test', email='test@email.com', password='password')
# Login
client.login(username='test', password='password')
class TestImageIndexView(TestCase):
def setUp(self):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_index'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_index'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -168,7 +164,7 @@ class TestImageAddView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_add_image'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_add_image'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -185,7 +181,7 @@ class TestImageEditView(TestCase):
)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_edit_image', args=(self.image.id,)), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_edit_image', args=(self.image.id,)), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -202,7 +198,7 @@ class TestImageDeleteView(TestCase):
)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_delete_image', args=(self.image.id,)), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_delete_image', args=(self.image.id,)), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -213,7 +209,7 @@ class TestImageChooserView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_chooser'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_chooser'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -241,7 +237,7 @@ class TestImageChooserChosenView(TestCase):
)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_image_chosen', args=(self.image.id,)), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_image_chosen', args=(self.image.id,)), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -252,7 +248,7 @@ class TestImageChooserUploadView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get(reverse('wagtailimages_chooser_upload'), params, HTTP_HOST=get_default_host())
return self.client.get(reverse('wagtailimages_chooser_upload'), params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)

View File

@ -1,5 +1,5 @@
from django.test import TestCase
from .utils import get_default_host, login
from wagtail.tests.utils import login, get_host
from wagtail.wagtailsearch import models
@ -50,7 +50,7 @@ class TestEditorsPicksIndexView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get('/admin/search/editorspicks/', params, HTTP_HOST=get_default_host())
return self.client.get('/admin/search/editorspicks/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -72,7 +72,7 @@ class TestEditorsPicksAddView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get('/admin/search/editorspicks/add/', params, HTTP_HOST=get_default_host())
return self.client.get('/admin/search/editorspicks/add/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -87,7 +87,7 @@ class TestEditorsPicksEditView(TestCase):
self.query.editors_picks.create(page_id=1, description="Root page")
def get(self, params={}):
return self.client.get('/admin/search/editorspicks/' + str(self.query.id) + '/', params, HTTP_HOST=get_default_host())
return self.client.get('/admin/search/editorspicks/' + str(self.query.id) + '/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -102,7 +102,7 @@ class TestEditorsPicksDeleteView(TestCase):
self.query.editors_picks.create(page_id=1, description="Root page")
def get(self, params={}):
return self.client.get('/admin/search/editorspicks/' + str(self.query.id) + '/delete/', params, HTTP_HOST=get_default_host())
return self.client.get('/admin/search/editorspicks/' + str(self.query.id) + '/delete/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)

View File

@ -1,10 +1,10 @@
from django.test import TestCase
from .utils import get_default_host
from wagtail.tests.utils import get_host
class TestSearchView(TestCase):
def get(self, params={}):
return self.client.get('/search/', params, HTTP_HOST=get_default_host())
return self.client.get('/search/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)
@ -23,7 +23,7 @@ class TestSearchView(TestCase):
class TestSuggestionsView(TestCase):
def get(self, params={}):
return self.client.get('/search/suggest/', params, HTTP_HOST=get_default_host())
return self.client.get('/search/suggest/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)

View File

@ -1,7 +1,7 @@
from django.test import TestCase
from django.core import management
from wagtail.wagtailsearch import models
from .utils import get_default_host, login
from wagtail.tests.utils import login, get_host
from StringIO import StringIO
import unittest
@ -145,7 +145,7 @@ class TestQueryChooserView(TestCase):
login(self.client)
def get(self, params={}):
return self.client.get('/admin/search/queries/chooser/', params, HTTP_HOST=get_default_host())
return self.client.get('/admin/search/queries/chooser/', params, HTTP_HOST=get_host())
def test_status_code(self):
self.assertEqual(self.get().status_code, 200)