diff options
author | Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> | 2015-03-30 18:33:26 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-04-15 09:45:26 -0400 |
commit | a429a502ea0e8297deef82442d481fc9a8f6cd9d (patch) | |
tree | 695a0ef067a5681dea414eb52de0d38dfa37228e /tests/admin_custom_urls | |
parent | 97bb48d9ba864060d57a3137fb9c456b98ecc79b (diff) | |
download | django-a429a502ea0e8297deef82442d481fc9a8f6cd9d.tar.gz |
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.
Diffstat (limited to 'tests/admin_custom_urls')
-rw-r--r-- | tests/admin_custom_urls/models.py | 7 | ||||
-rw-r--r-- | tests/admin_custom_urls/tests.py | 22 | ||||
-rw-r--r-- | tests/admin_custom_urls/urls.py | 5 |
3 files changed, 18 insertions, 16 deletions
diff --git a/tests/admin_custom_urls/models.py b/tests/admin_custom_urls/models.py index 51725d4253..5a1b2f5c2e 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 8177a144bb..2255ff59dc 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 eb91d283d4..103f9b0121 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)), ] |