2014-12-07 23:21:07 +00:00
|
|
|
from django.apps import apps
|
2015-01-22 20:23:45 +00:00
|
|
|
from django.contrib.sites.models import Site
|
2014-12-07 23:21:07 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.utils import modify_settings, override_settings
|
|
|
|
|
|
|
|
|
|
|
|
@override_settings(
|
2022-02-03 19:24:19 +00:00
|
|
|
ROOT_URLCONF="flatpages_tests.urls",
|
2014-12-07 23:21:07 +00:00
|
|
|
SITE_ID=1,
|
|
|
|
)
|
2015-02-10 00:20:39 +00:00
|
|
|
@modify_settings(
|
|
|
|
INSTALLED_APPS={
|
2022-02-03 19:24:19 +00:00
|
|
|
"append": ["django.contrib.sitemaps", "django.contrib.flatpages"],
|
2015-02-10 00:20:39 +00:00
|
|
|
},
|
|
|
|
)
|
2014-12-07 23:21:07 +00:00
|
|
|
class FlatpagesSitemapTests(TestCase):
|
2015-01-22 20:23:45 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2017-01-21 13:13:44 +00:00
|
|
|
super().setUpClass()
|
2015-01-22 20:23:45 +00:00
|
|
|
# This cleanup is necessary because contrib.sites cache
|
|
|
|
# makes tests interfere with each other, see #11505
|
|
|
|
Site.objects.clear_cache()
|
|
|
|
|
2014-12-07 23:21:07 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
2022-02-03 19:24:19 +00:00
|
|
|
Site = apps.get_model("sites.Site")
|
2014-12-07 23:21:07 +00:00
|
|
|
current_site = Site.objects.get_current()
|
|
|
|
current_site.flatpage_set.create(url="/foo/", title="foo")
|
2022-02-03 19:24:19 +00:00
|
|
|
current_site.flatpage_set.create(
|
|
|
|
url="/private-foo/", title="private foo", registration_required=True
|
|
|
|
)
|
2014-12-07 23:21:07 +00:00
|
|
|
|
|
|
|
def test_flatpage_sitemap(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
response = self.client.get("/flatpages/sitemap.xml")
|
|
|
|
self.assertIn(
|
|
|
|
b"<url><loc>http://example.com/flatpage_root/foo/</loc></url>",
|
|
|
|
response.getvalue(),
|
|
|
|
)
|
2019-11-26 23:00:56 +00:00
|
|
|
self.assertNotIn(
|
2022-02-03 19:24:19 +00:00
|
|
|
b"<url><loc>http://example.com/flatpage_root/private-foo/</loc></url>",
|
2019-11-26 23:00:56 +00:00
|
|
|
response.getvalue(),
|
|
|
|
)
|