parts/django/tests/regressiontests/admin_registration/tests.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from django.test import TestCase
       
     2 
       
     3 from django.contrib import admin
       
     4 
       
     5 from models import Person, Place
       
     6 
       
     7 class NameAdmin(admin.ModelAdmin):
       
     8     list_display = ['name']
       
     9     save_on_top = True
       
    10 
       
    11 class TestRegistration(TestCase):
       
    12     def setUp(self):
       
    13         self.site = admin.AdminSite()
       
    14 
       
    15     def test_bare_registration(self):
       
    16         self.site.register(Person)
       
    17         self.assertTrue(
       
    18             isinstance(self.site._registry[Person], admin.options.ModelAdmin)
       
    19         )
       
    20 
       
    21     def test_registration_with_model_admin(self):
       
    22         self.site.register(Person, NameAdmin)
       
    23         self.assertTrue(
       
    24             isinstance(self.site._registry[Person], NameAdmin)
       
    25         )
       
    26 
       
    27     def test_prevent_double_registration(self):
       
    28         self.site.register(Person)
       
    29         self.assertRaises(admin.sites.AlreadyRegistered,
       
    30                           self.site.register,
       
    31                           Person)
       
    32 
       
    33     def test_registration_with_star_star_options(self):
       
    34         self.site.register(Person, search_fields=['name'])
       
    35         self.assertEqual(self.site._registry[Person].search_fields, ['name'])
       
    36 
       
    37     def test_star_star_overrides(self):
       
    38         self.site.register(Person, NameAdmin,
       
    39                            search_fields=["name"], list_display=['__str__'])
       
    40         self.assertEqual(self.site._registry[Person].search_fields, ['name'])
       
    41         self.assertEqual(self.site._registry[Person].list_display,
       
    42                          ['action_checkbox', '__str__'])
       
    43         self.assertTrue(self.site._registry[Person].save_on_top)
       
    44 
       
    45     def test_iterable_registration(self):
       
    46         self.site.register([Person, Place], search_fields=['name'])
       
    47         self.assertTrue(
       
    48             isinstance(self.site._registry[Person], admin.options.ModelAdmin)
       
    49         )
       
    50         self.assertEqual(self.site._registry[Person].search_fields, ['name'])
       
    51         self.assertTrue(
       
    52             isinstance(self.site._registry[Place], admin.options.ModelAdmin)
       
    53         )
       
    54         self.assertEqual(self.site._registry[Place].search_fields, ['name'])