mirror of https://github.com/django/django.git
Updated tests to stop leaking models in shared AdminSite.
This would break upcoming changes and AdminSite assumptions about having an app_config for each application that has registered models.
This commit is contained in:
parent
97bb48d9ba
commit
a429a502ea
|
@ -77,6 +77,7 @@ class CarAdmin(admin.ModelAdmin):
|
||||||
request, obj, post_url_continue=reverse('admin:admin_custom_urls_car_history', args=[obj.pk]))
|
request, obj, post_url_continue=reverse('admin:admin_custom_urls_car_history', args=[obj.pk]))
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Action, ActionAdmin)
|
site = admin.AdminSite(name='admin_custom_urls')
|
||||||
admin.site.register(Person, PersonAdmin)
|
site.register(Action, ActionAdmin)
|
||||||
admin.site.register(Car, CarAdmin)
|
site.register(Person, PersonAdmin)
|
||||||
|
site.register(Car, CarAdmin)
|
||||||
|
|
|
@ -50,7 +50,7 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Ensure GET on the add_view works.
|
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/'))
|
self.assertTrue(add_url.endswith('/!add/'))
|
||||||
response = self.client.get(add_url)
|
response = self.client.get(add_url)
|
||||||
self.assertIsInstance(response, TemplateResponse)
|
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
|
Ensure GET on the add_view plus specifying a field value in the query
|
||||||
string works.
|
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.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'value="My Action"')
|
self.assertContains(response, 'value="My Action"')
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
"name": 'Action added through a popup',
|
"name": 'Action added through a popup',
|
||||||
"description": "Description of added action",
|
"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.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'dismissAddRelatedObjectPopup')
|
self.assertContains(response, 'dismissAddRelatedObjectPopup')
|
||||||
self.assertContains(response, 'Action added through a popup')
|
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
|
# Should get the change_view for model instance with PK 'add', not show
|
||||||
# the add_view
|
# 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'),))
|
args=(quote('add'),))
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
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
|
# 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)
|
# 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"),))
|
args=(quote("path/to/html/document.html"),))
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -110,11 +110,11 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
post_data = {'name': 'John Doe'}
|
post_data = {'name': 'John Doe'}
|
||||||
self.assertEqual(Person.objects.count(), 0)
|
self.assertEqual(Person.objects.count(), 0)
|
||||||
response = self.client.post(
|
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()
|
persons = Person.objects.all()
|
||||||
self.assertEqual(len(persons), 1)
|
self.assertEqual(len(persons), 1)
|
||||||
self.assertRedirects(
|
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):
|
def test_post_save_change_redirect(self):
|
||||||
"""
|
"""
|
||||||
|
@ -128,9 +128,9 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
person = Person.objects.all()[0]
|
person = Person.objects.all()[0]
|
||||||
post_data = {'name': 'Jack Doe'}
|
post_data = {'name': 'Jack Doe'}
|
||||||
response = self.client.post(
|
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(
|
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):
|
def test_post_url_continue(self):
|
||||||
"""
|
"""
|
||||||
|
@ -140,8 +140,8 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
post_data = {'name': 'SuperFast', '_continue': '1'}
|
post_data = {'name': 'SuperFast', '_continue': '1'}
|
||||||
self.assertEqual(Car.objects.count(), 0)
|
self.assertEqual(Car.objects.count(), 0)
|
||||||
response = self.client.post(
|
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()
|
cars = Car.objects.all()
|
||||||
self.assertEqual(len(cars), 1)
|
self.assertEqual(len(cars), 1)
|
||||||
self.assertRedirects(
|
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]))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
from django.contrib import admin
|
|
||||||
|
from .models import site
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(site.urls)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -16,4 +16,5 @@ class City(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
admin.site.register(City, admin.OSMGeoAdmin)
|
site = admin.AdminSite(name='admin_gis')
|
||||||
|
site.register(City, admin.OSMGeoAdmin)
|
||||||
|
|
|
@ -8,7 +8,7 @@ if HAS_GEOS:
|
||||||
from django.contrib.gis.geos import Point
|
from django.contrib.gis.geos import Point
|
||||||
|
|
||||||
from .admin import UnmodifiableAdmin
|
from .admin import UnmodifiableAdmin
|
||||||
from .models import City
|
from .models import site, City
|
||||||
|
|
||||||
|
|
||||||
@skipUnlessDBFeature("gis_enabled")
|
@skipUnlessDBFeature("gis_enabled")
|
||||||
|
@ -16,14 +16,14 @@ if HAS_GEOS:
|
||||||
class GeoAdminTest(TestCase):
|
class GeoAdminTest(TestCase):
|
||||||
|
|
||||||
def test_ensure_geographic_media(self):
|
def test_ensure_geographic_media(self):
|
||||||
geoadmin = admin.site._registry[City]
|
geoadmin = site._registry[City]
|
||||||
admin_js = geoadmin.media.render_js()
|
admin_js = geoadmin.media.render_js()
|
||||||
self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js))
|
self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js))
|
||||||
|
|
||||||
def test_olmap_OSM_rendering(self):
|
def test_olmap_OSM_rendering(self):
|
||||||
delete_all_btn = """<a href="javascript:geodjango_point.clearFeatures()">Delete all Features</a>"""
|
delete_all_btn = """<a href="javascript:geodjango_point.clearFeatures()">Delete all Features</a>"""
|
||||||
|
|
||||||
original_geoadmin = admin.site._registry[City]
|
original_geoadmin = site._registry[City]
|
||||||
params = original_geoadmin.get_map_widget(City._meta.get_field('point')).params
|
params = original_geoadmin.get_map_widget(City._meta.get_field('point')).params
|
||||||
result = original_geoadmin.get_map_widget(City._meta.get_field('point'))(
|
result = original_geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||||
).render('point', Point(-79.460734, 40.18476), params)
|
).render('point', Point(-79.460734, 40.18476), params)
|
||||||
|
@ -33,21 +33,21 @@ class GeoAdminTest(TestCase):
|
||||||
|
|
||||||
self.assertIn(delete_all_btn, result)
|
self.assertIn(delete_all_btn, result)
|
||||||
|
|
||||||
admin.site.unregister(City)
|
site.unregister(City)
|
||||||
admin.site.register(City, UnmodifiableAdmin)
|
site.register(City, UnmodifiableAdmin)
|
||||||
try:
|
try:
|
||||||
geoadmin = admin.site._registry[City]
|
geoadmin = site._registry[City]
|
||||||
params = geoadmin.get_map_widget(City._meta.get_field('point')).params
|
params = geoadmin.get_map_widget(City._meta.get_field('point')).params
|
||||||
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||||
).render('point', Point(-79.460734, 40.18476), params)
|
).render('point', Point(-79.460734, 40.18476), params)
|
||||||
|
|
||||||
self.assertNotIn(delete_all_btn, result)
|
self.assertNotIn(delete_all_btn, result)
|
||||||
finally:
|
finally:
|
||||||
admin.site.unregister(City)
|
site.unregister(City)
|
||||||
admin.site.register(City, original_geoadmin.__class__)
|
site.register(City, original_geoadmin.__class__)
|
||||||
|
|
||||||
def test_olmap_WMS_rendering(self):
|
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'))(
|
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||||
).render('point', Point(-79.460734, 40.18476))
|
).render('point', Point(-79.460734, 40.18476))
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
|
@ -59,7 +59,7 @@ class GeoAdminTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Check that changes are accurately noticed by OpenLayersWidget.
|
Check that changes are accurately noticed by OpenLayersWidget.
|
||||||
"""
|
"""
|
||||||
geoadmin = admin.site._registry[City]
|
geoadmin = site._registry[City]
|
||||||
form = geoadmin.get_changelist_form(None)()
|
form = geoadmin.get_changelist_form(None)()
|
||||||
has_changed = form.fields['point'].has_changed
|
has_changed = form.fields['point'].has_changed
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,6 @@ from django.contrib import admin
|
||||||
|
|
||||||
from .models import ProxyTrackerUser, TrackerUser
|
from .models import ProxyTrackerUser, TrackerUser
|
||||||
|
|
||||||
admin.site.register(TrackerUser)
|
site = admin.AdminSite(name='admin_proxy')
|
||||||
admin.site.register(ProxyTrackerUser)
|
site.register(TrackerUser)
|
||||||
|
site.register(ProxyTrackerUser)
|
||||||
|
|
|
@ -433,17 +433,17 @@ class ProxyModelAdminTests(TestCase):
|
||||||
proxy = ProxyTrackerUser.objects.get(name='Django Pony')
|
proxy = ProxyTrackerUser.objects.get(name='Django Pony')
|
||||||
|
|
||||||
user_str = 'Tracker user: <a href="%s">%s</a>' % (
|
user_str = 'Tracker user: <a href="%s">%s</a>' % (
|
||||||
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: <a href="%s">%s</a>' % (
|
proxy_str = 'Proxy tracker user: <a href="%s">%s</a>' % (
|
||||||
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')
|
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]
|
delete_str = response.context['deleted_objects'][0]
|
||||||
self.assertEqual(delete_str, user_str)
|
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]
|
delete_str = response.context['deleted_objects'][0]
|
||||||
self.assertEqual(delete_str, proxy_str)
|
self.assertEqual(delete_str, proxy_str)
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
from django.contrib import admin
|
|
||||||
|
from .admin import site
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(site.urls)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,10 +6,10 @@ from .models import Event, Timestamp
|
||||||
class EventAdmin(admin.ModelAdmin):
|
class EventAdmin(admin.ModelAdmin):
|
||||||
list_display = ('dt',)
|
list_display = ('dt',)
|
||||||
|
|
||||||
admin.site.register(Event, EventAdmin)
|
|
||||||
|
|
||||||
|
|
||||||
class TimestampAdmin(admin.ModelAdmin):
|
class TimestampAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ('created', 'updated')
|
readonly_fields = ('created', 'updated')
|
||||||
|
|
||||||
admin.site.register(Timestamp, TimestampAdmin)
|
site = admin.AdminSite(name='admin_tz')
|
||||||
|
site.register(Event, EventAdmin)
|
||||||
|
site.register(Timestamp, TimestampAdmin)
|
||||||
|
|
|
@ -1100,26 +1100,26 @@ class AdminTests(TestCase):
|
||||||
@requires_tz_support
|
@requires_tz_support
|
||||||
def test_changelist(self):
|
def test_changelist(self):
|
||||||
e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
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())
|
self.assertContains(response, e.dt.astimezone(EAT).isoformat())
|
||||||
|
|
||||||
def test_changelist_in_other_timezone(self):
|
def test_changelist_in_other_timezone(self):
|
||||||
e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
||||||
with timezone.override(ICT):
|
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())
|
self.assertContains(response, e.dt.astimezone(ICT).isoformat())
|
||||||
|
|
||||||
@requires_tz_support
|
@requires_tz_support
|
||||||
def test_change_editable(self):
|
def test_change_editable(self):
|
||||||
e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
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).date().isoformat())
|
||||||
self.assertContains(response, e.dt.astimezone(EAT).time().isoformat())
|
self.assertContains(response, e.dt.astimezone(EAT).time().isoformat())
|
||||||
|
|
||||||
def test_change_editable_in_other_timezone(self):
|
def test_change_editable_in_other_timezone(self):
|
||||||
e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
||||||
with timezone.override(ICT):
|
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).date().isoformat())
|
||||||
self.assertContains(response, e.dt.astimezone(ICT).time().isoformat())
|
self.assertContains(response, e.dt.astimezone(ICT).time().isoformat())
|
||||||
|
|
||||||
|
@ -1128,7 +1128,7 @@ class AdminTests(TestCase):
|
||||||
Timestamp.objects.create()
|
Timestamp.objects.create()
|
||||||
# re-fetch the object for backends that lose microseconds (MySQL)
|
# re-fetch the object for backends that lose microseconds (MySQL)
|
||||||
t = Timestamp.objects.get()
|
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())
|
self.assertContains(response, t.created.astimezone(EAT).isoformat())
|
||||||
|
|
||||||
def test_change_readonly_in_other_timezone(self):
|
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)
|
# re-fetch the object for backends that lose microseconds (MySQL)
|
||||||
t = Timestamp.objects.get()
|
t = Timestamp.objects.get()
|
||||||
with timezone.override(ICT):
|
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())
|
self.assertContains(response, t.created.astimezone(ICT).isoformat())
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
from . import admin as tz_admin # NOQA: register tz_admin
|
from . import admin as tz_admin # NOQA: register tz_admin
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(tz_admin.site.urls)),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue