2013-02-24 20:12:41 +08:00
|
|
|
from django.contrib.flatpages.models import FlatPage
|
2019-11-27 07:00:56 +08:00
|
|
|
from django.test import SimpleTestCase, override_settings
|
2015-03-15 18:26:47 +08:00
|
|
|
from django.test.utils import override_script_prefix
|
2013-02-24 20:12:41 +08:00
|
|
|
|
|
|
|
|
2015-04-18 05:38:20 +08:00
|
|
|
class FlatpageModelTests(SimpleTestCase):
|
2013-02-24 20:12:41 +08:00
|
|
|
|
2017-10-12 03:27:15 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.page = FlatPage(title='Café!', url='/café/')
|
|
|
|
|
2013-02-24 20:12:41 +08:00
|
|
|
def test_get_absolute_url_urlencodes(self):
|
2017-10-12 03:27:15 +08:00
|
|
|
self.assertEqual(self.page.get_absolute_url(), '/caf%C3%A9/')
|
2013-02-24 20:12:41 +08:00
|
|
|
|
2017-10-12 03:27:15 +08:00
|
|
|
@override_script_prefix('/prefix/')
|
2013-02-24 20:25:17 +08:00
|
|
|
def test_get_absolute_url_honors_script_prefix(self):
|
2017-10-12 03:27:15 +08:00
|
|
|
self.assertEqual(self.page.get_absolute_url(), '/prefix/caf%C3%A9/')
|
2017-10-12 20:56:05 +08:00
|
|
|
|
|
|
|
def test_str(self):
|
|
|
|
self.assertEqual(str(self.page), '/café/ -- Café!')
|
2019-11-27 07:00:56 +08:00
|
|
|
|
|
|
|
@override_settings(ROOT_URLCONF='flatpages_tests.urls')
|
|
|
|
def test_get_absolute_url_include(self):
|
|
|
|
self.assertEqual(self.page.get_absolute_url(), '/flatpage_root/caf%C3%A9/')
|
|
|
|
|
|
|
|
@override_settings(ROOT_URLCONF='flatpages_tests.no_slash_urls')
|
|
|
|
def test_get_absolute_url_include_no_slash(self):
|
|
|
|
self.assertEqual(self.page.get_absolute_url(), '/flatpagecaf%C3%A9/')
|
|
|
|
|
|
|
|
@override_settings(ROOT_URLCONF='flatpages_tests.absolute_urls')
|
|
|
|
def test_get_absolute_url_with_hardcoded_url(self):
|
|
|
|
fp = FlatPage(title='Test', url='/hardcoded/')
|
|
|
|
self.assertEqual(fp.get_absolute_url(), '/flatpage/')
|