mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.8.x] Fixed #17716 -- Prevented include('...', app_name='...') without a namespace.
Backport of 27eeb64a96 from master
			
			
This commit is contained in:
		| @@ -17,6 +17,9 @@ handler500 = 'django.views.defaults.server_error' | ||||
|  | ||||
|  | ||||
| def include(arg, namespace=None, app_name=None): | ||||
|     if app_name and not namespace: | ||||
|         raise ValueError('Must specify a namespace if specifying app_name.') | ||||
|  | ||||
|     if isinstance(arg, tuple): | ||||
|         # callable returning a namespace hint | ||||
|         if namespace: | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import unittest | ||||
| from admin_scripts.tests import AdminScriptTestCase | ||||
|  | ||||
| from django.conf import settings | ||||
| from django.conf.urls import include | ||||
| from django.contrib.auth.models import User | ||||
| from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist | ||||
| from django.core.urlresolvers import ( | ||||
| @@ -20,7 +21,9 @@ from django.http import ( | ||||
|     HttpRequest, HttpResponsePermanentRedirect, HttpResponseRedirect, | ||||
| ) | ||||
| from django.shortcuts import redirect | ||||
| from django.test import TestCase, ignore_warnings, override_settings | ||||
| from django.test import ( | ||||
|     SimpleTestCase, TestCase, ignore_warnings, override_settings, | ||||
| ) | ||||
| from django.utils import six | ||||
| from django.utils.deprecation import RemovedInDjango20Warning | ||||
|  | ||||
| @@ -399,7 +402,7 @@ class ReverseShortcutTests(TestCase): | ||||
|     @ignore_warnings(category=RemovedInDjango20Warning) | ||||
|     def test_reverse_by_path_nested(self): | ||||
|         # Views that are added to urlpatterns using include() should be | ||||
|         # reversible by doted path. | ||||
|         # reversible by dotted path. | ||||
|         self.assertEqual(reverse('urlpatterns_reverse.views.nested_view'), '/includes/nested_path/') | ||||
|  | ||||
|     def test_redirect_view_object(self): | ||||
| @@ -749,3 +752,10 @@ class ViewLoadingTests(TestCase): | ||||
|         # swallow it. | ||||
|         self.assertRaises(AttributeError, get_callable, | ||||
|                           'urlpatterns_reverse.views_broken.i_am_broken') | ||||
|  | ||||
|  | ||||
| class IncludeTests(SimpleTestCase): | ||||
|     def test_include_app_name_but_no_namespace(self): | ||||
|         msg = "Must specify a namespace if specifying app_name." | ||||
|         with self.assertRaisesMessage(ValueError, msg): | ||||
|             include('urls', app_name='bar') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user