Fixed #35265 -- Added AdminSite tests for changing titles.

This commit is contained in:
Kasun Herath 2024-03-04 10:04:42 +05:30 committed by GitHub
parent c187417611
commit f5ed4306bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -564,6 +564,7 @@ answer newbie questions, and generally made Django that much better:
Karderio <karderio@gmail.com>
Karen Tracey <kmtracey@gmail.com>
Karol Sikora <elektrrrus@gmail.com>
Kasun Herath <kasunh01@gmail.com>
Katherine “Kati” Michel <kthrnmichel@gmail.com>
Kathryn Killebrew <kathryn.killebrew@gmail.com>
Katie Miller <katie@sub50.com>

View File

@ -11,8 +11,19 @@ site = admin.AdminSite(name="test_adminsite")
site.register(User)
site.register(Article)
class CustomAdminSite(admin.AdminSite):
site_title = "Custom title"
site_header = "Custom site"
custom_site = CustomAdminSite(name="test_custom_adminsite")
custom_site.register(User)
urlpatterns = [
path("test_admin/admin/", site.urls),
path("test_custom_admin/admin/", custom_site.urls),
]
@ -43,6 +54,13 @@ class SiteEachContextTest(TestCase):
self.assertEqual(ctx["site_url"], "/")
self.assertIs(ctx["has_permission"], True)
def test_custom_admin_titles(self):
request = self.request_factory.get(reverse("test_custom_adminsite:index"))
request.user = self.u1
ctx = custom_site.each_context(request)
self.assertEqual(ctx["site_title"], "Custom title")
self.assertEqual(ctx["site_header"], "Custom site")
def test_each_context_site_url_with_script_name(self):
request = self.request_factory.get(
reverse("test_adminsite:index"), SCRIPT_NAME="/my-script-name/"