summaryrefslogtreecommitdiff
path: root/tests/admin_ordering
diff options
context:
space:
mode:
authorRiccardo Magliocchetti <riccardo.magliocchetti@gmail.com>2015-05-14 14:14:34 +0200
committerTim Graham <timograham@gmail.com>2015-05-14 09:57:13 -0400
commitadf5d75af1418b044d7ea335896e75277da06b77 (patch)
tree1ea6c9e8ae76834216266564b2fc6fba27cdaf11 /tests/admin_ordering
parent4157c502a5202798d0f73645181cb82aa71d34d9 (diff)
downloaddjango-adf5d75af1418b044d7ea335896e75277da06b77.tar.gz
Refs #24553 -- Isolated admin_* tests.
This fixes a regression with runtests.py --reverse after bd53db5eab05099ae371348529c6428e0da95c6a We need to avoid leaking model registration in the default AdminSite.
Diffstat (limited to 'tests/admin_ordering')
-rw-r--r--tests/admin_ordering/tests.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/tests/admin_ordering/tests.py b/tests/admin_ordering/tests.py
index e984395469..e23195d8d7 100644
--- a/tests/admin_ordering/tests.py
+++ b/tests/admin_ordering/tests.py
@@ -25,6 +25,8 @@ class MockSuperUser(object):
request = MockRequest()
request.user = MockSuperUser()
+site = admin.AdminSite()
+
class TestAdminOrdering(TestCase):
"""
@@ -46,7 +48,7 @@ class TestAdminOrdering(TestCase):
The default ordering should be by name, as specified in the inner Meta
class.
"""
- ma = ModelAdmin(Band, admin.site)
+ ma = ModelAdmin(Band, site)
names = [b.name for b in ma.get_queryset(request)]
self.assertListEqual(['Aerosmith', 'Radiohead', 'Van Halen'], names)
@@ -57,7 +59,7 @@ class TestAdminOrdering(TestCase):
"""
class BandAdmin(ModelAdmin):
ordering = ('rank',) # default ordering is ('name',)
- ma = BandAdmin(Band, admin.site)
+ ma = BandAdmin(Band, site)
names = [b.name for b in ma.get_queryset(request)]
self.assertListEqual(['Radiohead', 'Van Halen', 'Aerosmith'], names)
@@ -69,7 +71,7 @@ class TestAdminOrdering(TestCase):
other_user = User.objects.create(username='other')
request = self.request_factory.get('/')
request.user = super_user
- ma = DynOrderingBandAdmin(Band, admin.site)
+ ma = DynOrderingBandAdmin(Band, site)
names = [b.name for b in ma.get_queryset(request)]
self.assertListEqual(['Radiohead', 'Van Halen', 'Aerosmith'], names)
request.user = other_user
@@ -96,7 +98,7 @@ class TestInlineModelAdminOrdering(TestCase):
The default ordering should be by name, as specified in the inner Meta
class.
"""
- inline = SongInlineDefaultOrdering(self.band, admin.site)
+ inline = SongInlineDefaultOrdering(self.band, site)
names = [s.name for s in inline.get_queryset(request)]
self.assertListEqual(['Dude (Looks Like a Lady)', 'Jaded', 'Pink'], names)
@@ -104,7 +106,7 @@ class TestInlineModelAdminOrdering(TestCase):
"""
Let's check with ordering set to something different than the default.
"""
- inline = SongInlineNewOrdering(self.band, admin.site)
+ inline = SongInlineNewOrdering(self.band, site)
names = [s.name for s in inline.get_queryset(request)]
self.assertListEqual(['Jaded', 'Pink', 'Dude (Looks Like a Lady)'], names)
@@ -119,16 +121,16 @@ class TestRelatedFieldsAdminOrdering(TestCase):
# for the related model
class SongAdmin(admin.ModelAdmin):
pass
- admin.site.register(Song, SongAdmin)
+ site.register(Song, SongAdmin)
def tearDown(self):
- admin.site.unregister(Song)
- if Band in admin.site._registry:
- admin.site.unregister(Band)
+ site.unregister(Song)
+ if Band in site._registry:
+ site.unregister(Band)
def check_ordering_of_field_choices(self, correct_ordering):
- fk_field = admin.site._registry[Song].formfield_for_foreignkey(Song.band.field)
- m2m_field = admin.site._registry[Song].formfield_for_manytomany(Song.other_interpreters.field)
+ fk_field = site._registry[Song].formfield_for_foreignkey(Song.band.field)
+ m2m_field = site._registry[Song].formfield_for_manytomany(Song.other_interpreters.field)
self.assertListEqual(list(fk_field.queryset), correct_ordering)
self.assertListEqual(list(m2m_field.queryset), correct_ordering)
@@ -140,7 +142,7 @@ class TestRelatedFieldsAdminOrdering(TestCase):
def test_admin_with_no_ordering_fallback_to_model_ordering(self):
class NoOrderingBandAdmin(admin.ModelAdmin):
pass
- admin.site.register(Band, NoOrderingBandAdmin)
+ site.register(Band, NoOrderingBandAdmin)
# should be ordered by name (as defined by the model)
self.check_ordering_of_field_choices([self.b2, self.b1])
@@ -148,7 +150,7 @@ class TestRelatedFieldsAdminOrdering(TestCase):
def test_admin_ordering_beats_model_ordering(self):
class StaticOrderingBandAdmin(admin.ModelAdmin):
ordering = ('rank',)
- admin.site.register(Band, StaticOrderingBandAdmin)
+ site.register(Band, StaticOrderingBandAdmin)
# should be ordered by rank (defined by the ModelAdmin)
self.check_ordering_of_field_choices([self.b1, self.b2])
@@ -170,8 +172,8 @@ class TestRelatedFieldsAdminOrdering(TestCase):
class StaticOrderingBandAdmin(admin.ModelAdmin):
ordering = ('rank',)
- admin.site.unregister(Song)
- admin.site.register(Song, SongAdmin)
- admin.site.register(Band, StaticOrderingBandAdmin)
+ site.unregister(Song)
+ site.register(Song, SongAdmin)
+ site.register(Band, StaticOrderingBandAdmin)
self.check_ordering_of_field_choices([self.b2])