App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / regressiontests / admin_registration / tests.py
blob1b2d291691e7691d52e143f467a6b340f8f21bcf
1 from __future__ import absolute_import
3 from django.contrib import admin
4 from django.core.exceptions import ImproperlyConfigured
5 from django.test import TestCase
7 from .models import Person, Place, Location
10 class NameAdmin(admin.ModelAdmin):
11 list_display = ['name']
12 save_on_top = True
14 class TestRegistration(TestCase):
15 def setUp(self):
16 self.site = admin.AdminSite()
18 def test_bare_registration(self):
19 self.site.register(Person)
20 self.assertTrue(
21 isinstance(self.site._registry[Person], admin.options.ModelAdmin)
24 def test_registration_with_model_admin(self):
25 self.site.register(Person, NameAdmin)
26 self.assertTrue(
27 isinstance(self.site._registry[Person], NameAdmin)
30 def test_prevent_double_registration(self):
31 self.site.register(Person)
32 self.assertRaises(admin.sites.AlreadyRegistered,
33 self.site.register,
34 Person)
36 def test_registration_with_star_star_options(self):
37 self.site.register(Person, search_fields=['name'])
38 self.assertEqual(self.site._registry[Person].search_fields, ['name'])
40 def test_star_star_overrides(self):
41 self.site.register(Person, NameAdmin,
42 search_fields=["name"], list_display=['__str__'])
43 self.assertEqual(self.site._registry[Person].search_fields, ['name'])
44 self.assertEqual(self.site._registry[Person].list_display,
45 ['__str__'])
46 self.assertTrue(self.site._registry[Person].save_on_top)
48 def test_iterable_registration(self):
49 self.site.register([Person, Place], search_fields=['name'])
50 self.assertTrue(
51 isinstance(self.site._registry[Person], admin.options.ModelAdmin)
53 self.assertEqual(self.site._registry[Person].search_fields, ['name'])
54 self.assertTrue(
55 isinstance(self.site._registry[Place], admin.options.ModelAdmin)
57 self.assertEqual(self.site._registry[Place].search_fields, ['name'])
59 def test_abstract_model(self):
60 """
61 Exception is raised when trying to register an abstract model.
62 Refs #12004.
63 """
64 self.assertRaises(ImproperlyConfigured, self.site.register, Location)