kopia lustrzana https://github.com/wagtail/wagtail
Add test fixtures and tests for URL construction in wagtailcore
rodzic
d7e5c33c1a
commit
2851e3fea1
|
@ -0,0 +1,97 @@
|
|||
[
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "wagtailcore.page",
|
||||
"fields": {
|
||||
"title": "Root",
|
||||
"numchild": 1,
|
||||
"show_in_menus": false,
|
||||
"live": true,
|
||||
"depth": 1,
|
||||
"content_type": [
|
||||
"wagtailcore",
|
||||
"page"
|
||||
],
|
||||
"path": "0001",
|
||||
"url_path": "/",
|
||||
"slug": "root"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "wagtailcore.page",
|
||||
"fields": {
|
||||
"title": "Welcome to the Wagtail test site!",
|
||||
"numchild": 1,
|
||||
"show_in_menus": false,
|
||||
"live": true,
|
||||
"depth": 2,
|
||||
"content_type": ["wagtailcore", "page"],
|
||||
"path": "00010001",
|
||||
"url_path": "/home/",
|
||||
"slug": "home"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pk": 3,
|
||||
"model": "wagtailcore.page",
|
||||
"fields": {
|
||||
"title": "Events",
|
||||
"numchild": 1,
|
||||
"show_in_menus": true,
|
||||
"live": true,
|
||||
"depth": 3,
|
||||
"content_type": ["tests", "simplepage"],
|
||||
"path": "000100010001",
|
||||
"url_path": "/home/events/",
|
||||
"slug": "events"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 3,
|
||||
"model": "tests.simplepage",
|
||||
"fields": {
|
||||
"content": "Look at our lovely events."
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pk": 4,
|
||||
"model": "wagtailcore.page",
|
||||
"fields": {
|
||||
"title": "Christmas",
|
||||
"numchild": 1,
|
||||
"show_in_menus": true,
|
||||
"live": true,
|
||||
"depth": 4,
|
||||
"content_type": ["tests", "eventpage"],
|
||||
"path": "0001000100010001",
|
||||
"url_path": "/home/events/christmas/",
|
||||
"slug": "christmas"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 4,
|
||||
"model": "tests.eventpage",
|
||||
"fields": {
|
||||
"date_from": "2014-12-25",
|
||||
"audience": "public",
|
||||
"location": "The North Pole",
|
||||
"body": "<p>Chestnuts roasting on an open fire</p>",
|
||||
"cost": "Free"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "wagtailcore.site",
|
||||
"fields": {
|
||||
"root_page": 2,
|
||||
"hostname": "localhost",
|
||||
"port": 80,
|
||||
"is_default_site": true
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,19 +1,40 @@
|
|||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from django.test import TestCase
|
||||
from wagtail.wagtailcore.models import Page, Site
|
||||
|
||||
|
||||
@unittest.skip("Need real tests")
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
||||
class TestRouting(TestCase):
|
||||
fixtures = ['test.json']
|
||||
|
||||
def test_urls(self):
|
||||
default_site = Site.objects.get(is_default_site=True)
|
||||
homepage = Page.objects.get(url_path='/home/')
|
||||
christmas_page = Page.objects.get(url_path='/home/events/christmas/')
|
||||
|
||||
# Basic installation only has one site configured, so page.url will return local URLs
|
||||
self.assertEqual(homepage.full_url, 'http://localhost/')
|
||||
self.assertEqual(homepage.url, '/')
|
||||
self.assertEqual(homepage.relative_url(default_site), '/')
|
||||
|
||||
self.assertEqual(christmas_page.full_url, 'http://localhost/events/christmas/')
|
||||
self.assertEqual(christmas_page.url, '/events/christmas/')
|
||||
self.assertEqual(christmas_page.relative_url(default_site), '/events/christmas/')
|
||||
|
||||
def test_urls_with_multiple_sites(self):
|
||||
events_page = Page.objects.get(url_path='/home/events/')
|
||||
events_site = Site.objects.create(hostname='events.example.com', root_page=events_page)
|
||||
|
||||
default_site = Site.objects.get(is_default_site=True)
|
||||
homepage = Page.objects.get(url_path='/home/')
|
||||
christmas_page = Page.objects.get(url_path='/home/events/christmas/')
|
||||
|
||||
# with multiple sites, page.url will return full URLs to ensure that
|
||||
# they work across sites
|
||||
self.assertEqual(homepage.full_url, 'http://localhost/')
|
||||
self.assertEqual(homepage.url, 'http://localhost/')
|
||||
self.assertEqual(homepage.relative_url(default_site), '/')
|
||||
self.assertEqual(homepage.relative_url(events_site), 'http://localhost/')
|
||||
|
||||
self.assertEqual(christmas_page.full_url, 'http://events.example.com/christmas/')
|
||||
self.assertEqual(christmas_page.url, 'http://events.example.com/christmas/')
|
||||
self.assertEqual(christmas_page.relative_url(default_site), 'http://events.example.com/christmas/')
|
||||
self.assertEqual(christmas_page.relative_url(events_site), '/christmas/')
|
||||
|
|
Ładowanie…
Reference in New Issue