#35265: Add test for AdminSite with custom headers.
-------------------------------------+-------------------------------------
     Reporter:  Kasun Herath         |                    Owner:  Kasun
         Type:                       |  Herath
  Cleanup/optimization               |                   Status:  assigned
    Component:  contrib.admin        |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * stage:  Unreviewed => Accepted
 * summary:  Adjust unit tests on admin custom site titles => Add test for
     AdminSite with custom headers.
 * type:  Bug => Cleanup/optimization

Comment:

 Thanks for the ticket, there is no need to adjust existing tests, I'd
 rather add a new one, e.g.
 {{{#!diff
 diff --git a/tests/admin_views/test_adminsite.py
 b/tests/admin_views/test_adminsite.py
 index 68a32567d8..cb1da92003 100644
 --- a/tests/admin_views/test_adminsite.py
 +++ b/tests/admin_views/test_adminsite.py
 @@ -1,6 +1,6 @@
  from django.contrib import admin
  from django.contrib.admin.actions import delete_selected
 -from django.contrib.auth.models import User
 +from django.contrib.auth.models import Group, User
  from django.test import SimpleTestCase, TestCase, override_settings
  from django.test.client import RequestFactory
  from django.urls import path, reverse
 @@ -11,8 +11,18 @@ site = admin.AdminSite(name="test_adminsite")
  site.register(User)
  site.register(Article)

 +
 +class CustomAdminSite(admin.AdminSite):
 +    site_title = "My title"
 +    site_header = "My admin site"
 +
 +
 +custom_site = CustomAdminSite(name="test_custom_adminsite")
 +custom_site.register(Group)
 +
  urlpatterns = [
      path("test_admin/admin/", site.urls),
 +    path("test_custom_admin/admin/", custom_site.urls),
  ]


 @@ -43,6 +53,13 @@ class SiteEachContextTest(TestCase):
          self.assertEqual(ctx["site_url"], "/")
          self.assertIs(ctx["has_permission"], True)

 +    def test_admin_custom_headers(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"], "My title")
 +        self.assertEqual(ctx["site_header"], "My admin 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/"

 }}}
 For the future, extra test coverage doesn't require a ticket.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35265#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e045aade3-fbef9773-ccfc-4ea8-b57c-f392185e57c9-000000%40eu-central-1.amazonses.com.

Reply via email to