diff --git a/tests/admin_custom_urls/models.py b/tests/admin_custom_urls/models.py index 51725d42536..5a1b2f5c2e2 100644 --- a/tests/admin_custom_urls/models.py +++ b/tests/admin_custom_urls/models.py @@ -77,6 +77,7 @@ class CarAdmin(admin.ModelAdmin): request, obj, post_url_continue=reverse('admin:admin_custom_urls_car_history', args=[obj.pk])) -admin.site.register(Action, ActionAdmin) -admin.site.register(Person, PersonAdmin) -admin.site.register(Car, CarAdmin) +site = admin.AdminSite(name='admin_custom_urls') +site.register(Action, ActionAdmin) +site.register(Person, PersonAdmin) +site.register(Car, CarAdmin) diff --git a/tests/admin_custom_urls/tests.py b/tests/admin_custom_urls/tests.py index 8177a144bb4..2255ff59dcf 100644 --- a/tests/admin_custom_urls/tests.py +++ b/tests/admin_custom_urls/tests.py @@ -50,7 +50,7 @@ class AdminCustomUrlsTest(TestCase): """ Ensure GET on the add_view works. """ - add_url = reverse('admin:admin_custom_urls_action_add') + add_url = reverse('admin_custom_urls:admin_custom_urls_action_add') self.assertTrue(add_url.endswith('/!add/')) response = self.client.get(add_url) self.assertIsInstance(response, TemplateResponse) @@ -61,7 +61,7 @@ class AdminCustomUrlsTest(TestCase): Ensure GET on the add_view plus specifying a field value in the query string works. """ - response = self.client.get(reverse('admin:admin_custom_urls_action_add'), {'name': 'My Action'}) + response = self.client.get(reverse('admin_custom_urls:admin_custom_urls_action_add'), {'name': 'My Action'}) self.assertEqual(response.status_code, 200) self.assertContains(response, 'value="My Action"') @@ -74,7 +74,7 @@ class AdminCustomUrlsTest(TestCase): "name": 'Action added through a popup', "description": "Description of added action", } - response = self.client.post(reverse('admin:admin_custom_urls_action_add'), post_data) + response = self.client.post(reverse('admin_custom_urls:admin_custom_urls_action_add'), post_data) self.assertEqual(response.status_code, 200) self.assertContains(response, 'dismissAddRelatedObjectPopup') self.assertContains(response, 'Action added through a popup') @@ -85,7 +85,7 @@ class AdminCustomUrlsTest(TestCase): """ # Should get the change_view for model instance with PK 'add', not show # the add_view - url = reverse('admin:%s_action_change' % Action._meta.app_label, + url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label, args=(quote('add'),)) response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -93,7 +93,7 @@ class AdminCustomUrlsTest(TestCase): # Should correctly get the change_view for the model instance with the # funny-looking PK (the one with a 'path/to/html/document.html' value) - url = reverse('admin:%s_action_change' % Action._meta.app_label, + url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label, args=(quote("path/to/html/document.html"),)) response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -110,11 +110,11 @@ class AdminCustomUrlsTest(TestCase): post_data = {'name': 'John Doe'} self.assertEqual(Person.objects.count(), 0) response = self.client.post( - reverse('admin:admin_custom_urls_person_add'), post_data) + reverse('admin_custom_urls:admin_custom_urls_person_add'), post_data) persons = Person.objects.all() self.assertEqual(len(persons), 1) self.assertRedirects( - response, reverse('admin:admin_custom_urls_person_history', args=[persons[0].pk])) + response, reverse('admin_custom_urls:admin_custom_urls_person_history', args=[persons[0].pk])) def test_post_save_change_redirect(self): """ @@ -128,9 +128,9 @@ class AdminCustomUrlsTest(TestCase): person = Person.objects.all()[0] post_data = {'name': 'Jack Doe'} response = self.client.post( - reverse('admin:admin_custom_urls_person_change', args=[person.pk]), post_data) + reverse('admin_custom_urls:admin_custom_urls_person_change', args=[person.pk]), post_data) self.assertRedirects( - response, reverse('admin:admin_custom_urls_person_delete', args=[person.pk])) + response, reverse('admin_custom_urls:admin_custom_urls_person_delete', args=[person.pk])) def test_post_url_continue(self): """ @@ -140,8 +140,8 @@ class AdminCustomUrlsTest(TestCase): post_data = {'name': 'SuperFast', '_continue': '1'} self.assertEqual(Car.objects.count(), 0) response = self.client.post( - reverse('admin:admin_custom_urls_car_add'), post_data) + reverse('admin_custom_urls:admin_custom_urls_car_add'), post_data) cars = Car.objects.all() self.assertEqual(len(cars), 1) self.assertRedirects( - response, reverse('admin:admin_custom_urls_car_history', args=[cars[0].pk])) + response, reverse('admin_custom_urls:admin_custom_urls_car_history', args=[cars[0].pk])) diff --git a/tests/admin_custom_urls/urls.py b/tests/admin_custom_urls/urls.py index eb91d283d45..103f9b0121a 100644 --- a/tests/admin_custom_urls/urls.py +++ b/tests/admin_custom_urls/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import include, url -from django.contrib import admin + +from .models import site urlpatterns = [ - url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', include(site.urls)), ] diff --git a/tests/gis_tests/geoadmin/models.py b/tests/gis_tests/geoadmin/models.py index cf8470e792c..9769558f48b 100644 --- a/tests/gis_tests/geoadmin/models.py +++ b/tests/gis_tests/geoadmin/models.py @@ -16,4 +16,5 @@ class City(models.Model): def __str__(self): return self.name -admin.site.register(City, admin.OSMGeoAdmin) +site = admin.AdminSite(name='admin_gis') +site.register(City, admin.OSMGeoAdmin) diff --git a/tests/gis_tests/geoadmin/tests.py b/tests/gis_tests/geoadmin/tests.py index 86c8ce9a1ae..07af5a0d647 100644 --- a/tests/gis_tests/geoadmin/tests.py +++ b/tests/gis_tests/geoadmin/tests.py @@ -8,7 +8,7 @@ if HAS_GEOS: from django.contrib.gis.geos import Point from .admin import UnmodifiableAdmin - from .models import City + from .models import site, City @skipUnlessDBFeature("gis_enabled") @@ -16,14 +16,14 @@ if HAS_GEOS: class GeoAdminTest(TestCase): def test_ensure_geographic_media(self): - geoadmin = admin.site._registry[City] + geoadmin = site._registry[City] admin_js = geoadmin.media.render_js() self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js)) def test_olmap_OSM_rendering(self): delete_all_btn = """Delete all Features""" - original_geoadmin = admin.site._registry[City] + original_geoadmin = site._registry[City] params = original_geoadmin.get_map_widget(City._meta.get_field('point')).params result = original_geoadmin.get_map_widget(City._meta.get_field('point'))( ).render('point', Point(-79.460734, 40.18476), params) @@ -33,21 +33,21 @@ class GeoAdminTest(TestCase): self.assertIn(delete_all_btn, result) - admin.site.unregister(City) - admin.site.register(City, UnmodifiableAdmin) + site.unregister(City) + site.register(City, UnmodifiableAdmin) try: - geoadmin = admin.site._registry[City] + geoadmin = site._registry[City] params = geoadmin.get_map_widget(City._meta.get_field('point')).params result = geoadmin.get_map_widget(City._meta.get_field('point'))( ).render('point', Point(-79.460734, 40.18476), params) self.assertNotIn(delete_all_btn, result) finally: - admin.site.unregister(City) - admin.site.register(City, original_geoadmin.__class__) + site.unregister(City) + site.register(City, original_geoadmin.__class__) def test_olmap_WMS_rendering(self): - geoadmin = admin.GeoModelAdmin(City, admin.site) + geoadmin = admin.GeoModelAdmin(City, site) result = geoadmin.get_map_widget(City._meta.get_field('point'))( ).render('point', Point(-79.460734, 40.18476)) self.assertIn( @@ -59,7 +59,7 @@ class GeoAdminTest(TestCase): """ Check that changes are accurately noticed by OpenLayersWidget. """ - geoadmin = admin.site._registry[City] + geoadmin = site._registry[City] form = geoadmin.get_changelist_form(None)() has_changed = form.fields['point'].has_changed diff --git a/tests/proxy_models/admin.py b/tests/proxy_models/admin.py index 72556c34a50..ba67f7829f9 100644 --- a/tests/proxy_models/admin.py +++ b/tests/proxy_models/admin.py @@ -2,5 +2,6 @@ from django.contrib import admin from .models import ProxyTrackerUser, TrackerUser -admin.site.register(TrackerUser) -admin.site.register(ProxyTrackerUser) +site = admin.AdminSite(name='admin_proxy') +site.register(TrackerUser) +site.register(ProxyTrackerUser) diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py index 1aea80902e8..98244327a30 100644 --- a/tests/proxy_models/tests.py +++ b/tests/proxy_models/tests.py @@ -433,17 +433,17 @@ class ProxyModelAdminTests(TestCase): proxy = ProxyTrackerUser.objects.get(name='Django Pony') user_str = 'Tracker user: %s' % ( - reverse('admin:proxy_models_trackeruser_change', args=(user.pk,)), user + reverse('admin_proxy:proxy_models_trackeruser_change', args=(user.pk,)), user ) proxy_str = 'Proxy tracker user: %s' % ( - reverse('admin:proxy_models_proxytrackeruser_change', args=(proxy.pk,)), proxy + reverse('admin_proxy:proxy_models_proxytrackeruser_change', args=(proxy.pk,)), proxy ) self.client.login(username='super', password='secret') - response = self.client.get(reverse('admin:proxy_models_trackeruser_delete', args=(user.pk,))) + response = self.client.get(reverse('admin_proxy:proxy_models_trackeruser_delete', args=(user.pk,))) delete_str = response.context['deleted_objects'][0] self.assertEqual(delete_str, user_str) - response = self.client.get(reverse('admin:proxy_models_proxytrackeruser_delete', args=(proxy.pk,))) + response = self.client.get(reverse('admin_proxy:proxy_models_proxytrackeruser_delete', args=(proxy.pk,))) delete_str = response.context['deleted_objects'][0] self.assertEqual(delete_str, proxy_str) self.client.logout() diff --git a/tests/proxy_models/urls.py b/tests/proxy_models/urls.py index eb91d283d45..854ac780403 100644 --- a/tests/proxy_models/urls.py +++ b/tests/proxy_models/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import include, url -from django.contrib import admin + +from .admin import site urlpatterns = [ - url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', include(site.urls)), ] diff --git a/tests/timezones/admin.py b/tests/timezones/admin.py index bd6c4e10c87..a650e110cc7 100644 --- a/tests/timezones/admin.py +++ b/tests/timezones/admin.py @@ -6,10 +6,10 @@ from .models import Event, Timestamp class EventAdmin(admin.ModelAdmin): list_display = ('dt',) -admin.site.register(Event, EventAdmin) - class TimestampAdmin(admin.ModelAdmin): readonly_fields = ('created', 'updated') -admin.site.register(Timestamp, TimestampAdmin) +site = admin.AdminSite(name='admin_tz') +site.register(Event, EventAdmin) +site.register(Timestamp, TimestampAdmin) diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index d87e2d25665..8c1d5331655 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -1100,26 +1100,26 @@ class AdminTests(TestCase): @requires_tz_support def test_changelist(self): e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) - response = self.client.get(reverse('admin:timezones_event_changelist')) + response = self.client.get(reverse('admin_tz:timezones_event_changelist')) self.assertContains(response, e.dt.astimezone(EAT).isoformat()) def test_changelist_in_other_timezone(self): e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) with timezone.override(ICT): - response = self.client.get(reverse('admin:timezones_event_changelist')) + response = self.client.get(reverse('admin_tz:timezones_event_changelist')) self.assertContains(response, e.dt.astimezone(ICT).isoformat()) @requires_tz_support def test_change_editable(self): e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) - response = self.client.get(reverse('admin:timezones_event_change', args=(e.pk,))) + response = self.client.get(reverse('admin_tz:timezones_event_change', args=(e.pk,))) self.assertContains(response, e.dt.astimezone(EAT).date().isoformat()) self.assertContains(response, e.dt.astimezone(EAT).time().isoformat()) def test_change_editable_in_other_timezone(self): e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)) with timezone.override(ICT): - response = self.client.get(reverse('admin:timezones_event_change', args=(e.pk,))) + response = self.client.get(reverse('admin_tz:timezones_event_change', args=(e.pk,))) self.assertContains(response, e.dt.astimezone(ICT).date().isoformat()) self.assertContains(response, e.dt.astimezone(ICT).time().isoformat()) @@ -1128,7 +1128,7 @@ class AdminTests(TestCase): Timestamp.objects.create() # re-fetch the object for backends that lose microseconds (MySQL) t = Timestamp.objects.get() - response = self.client.get(reverse('admin:timezones_timestamp_change', args=(t.pk,))) + response = self.client.get(reverse('admin_tz:timezones_timestamp_change', args=(t.pk,))) self.assertContains(response, t.created.astimezone(EAT).isoformat()) def test_change_readonly_in_other_timezone(self): @@ -1136,5 +1136,5 @@ class AdminTests(TestCase): # re-fetch the object for backends that lose microseconds (MySQL) t = Timestamp.objects.get() with timezone.override(ICT): - response = self.client.get(reverse('admin:timezones_timestamp_change', args=(t.pk,))) + response = self.client.get(reverse('admin_tz:timezones_timestamp_change', args=(t.pk,))) self.assertContains(response, t.created.astimezone(ICT).isoformat()) diff --git a/tests/timezones/urls.py b/tests/timezones/urls.py index 1d1ec38f643..e5c88a0025a 100644 --- a/tests/timezones/urls.py +++ b/tests/timezones/urls.py @@ -1,8 +1,7 @@ from django.conf.urls import include, url -from django.contrib import admin from . import admin as tz_admin # NOQA: register tz_admin urlpatterns = [ - url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', include(tz_admin.site.urls)), ]