Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18035 -- Removed deprecated AdminMediaHandler, as per official…

… deprecation timeline. Thanks Jannis Leidel and Ramiro Morales for the review.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17879 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5c53e30607014163872e89c221b206992a9acfef 1 parent 4f62352
Claude Paroz authored April 08, 2012
8  django/contrib/admin/static/admin/js/SelectFilter2.js
@@ -13,7 +13,7 @@ function findForm(node) {
13 13
 }
14 14
 
15 15
 window.SelectFilter = {
16  
-    init: function(field_id, field_name, is_stacked, admin_media_prefix) {
  16
+    init: function(field_id, field_name, is_stacked, admin_static_prefix) {
17 17
         if (field_id.match(/__prefix__/)){
18 18
             // Don't intialize on empty forms.
19 19
             return;
@@ -43,14 +43,14 @@ window.SelectFilter = {
43 43
         var selector_available = quickElement('div', selector_div, '');
44 44
         selector_available.className = 'selector-available';
45 45
         var title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
46  
-        quickElement('img', title_available, '', 'src', admin_media_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of available %s. You may choose some by selecting them in the box below and then clicking the "Choose" arrow between the two boxes.'), [field_name]));
  46
+        quickElement('img', title_available, '', 'src', admin_static_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of available %s. You may choose some by selecting them in the box below and then clicking the "Choose" arrow between the two boxes.'), [field_name]));
47 47
 
48 48
         var filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
49 49
         filter_p.className = 'selector-filter';
50 50
 
51 51
         var search_filter_label = quickElement('label', filter_p, '', 'for', field_id + "_input");
52 52
 
53  
-        var search_selector_img = quickElement('img', search_filter_label, '', 'src', admin_media_prefix + 'img/selector-search.gif', 'class', 'help-tooltip', 'alt', '', 'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name]));
  53
+        var search_selector_img = quickElement('img', search_filter_label, '', 'src', admin_static_prefix + 'img/selector-search.gif', 'class', 'help-tooltip', 'alt', '', 'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name]));
54 54
 
55 55
         filter_p.appendChild(document.createTextNode(' '));
56 56
 
@@ -73,7 +73,7 @@ window.SelectFilter = {
73 73
         var selector_chosen = quickElement('div', selector_div, '');
74 74
         selector_chosen.className = 'selector-chosen';
75 75
         var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
76  
-        quickElement('img', title_chosen, '', 'src', admin_media_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of chosen %s. You may remove some by selecting them in the box below and then clicking the "Remove" arrow between the two boxes.'), [field_name]));
  76
+        quickElement('img', title_chosen, '', 'src', admin_static_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of chosen %s. You may remove some by selecting them in the box below and then clicking the "Remove" arrow between the two boxes.'), [field_name]));
77 77
 
78 78
         var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', from_box.getAttribute('name'));
79 79
         to_box.className = 'filtered';
3  django/contrib/gis/admin/widgets.py
@@ -8,8 +8,7 @@
8 8
 
9 9
 # Creating a template context that contains Django settings
10 10
 # values needed by admin map templates.
11  
-geo_context = Context({'ADMIN_MEDIA_PREFIX' : static('admin/'),
12  
-                       'LANGUAGE_BIDI' : translation.get_language_bidi()})
  11
+geo_context = Context({'LANGUAGE_BIDI' : translation.get_language_bidi()})
13 12
 
14 13
 class OpenLayersWidget(Textarea):
15 14
     """
6  django/contrib/staticfiles/management/commands/runserver.py
... ...
@@ -1,12 +1,12 @@
1 1
 from optparse import make_option
2 2
 
3 3
 from django.conf import settings
4  
-from django.core.management.commands.runserver import BaseRunserverCommand
  4
+from django.core.management.commands.runserver import Command as RunserverCommand
5 5
 
6 6
 from django.contrib.staticfiles.handlers import StaticFilesHandler
7 7
 
8  
-class Command(BaseRunserverCommand):
9  
-    option_list = BaseRunserverCommand.option_list + (
  8
+class Command(RunserverCommand):
  9
+    option_list = RunserverCommand.option_list + (
10 10
         make_option('--nostatic', action="store_false", dest='use_static_handler', default=True,
11 11
             help='Tells Django to NOT automatically serve static files at STATIC_URL.'),
12 12
         make_option('--insecure', action="store_true", dest='insecure_serving', default=False,
17  django/core/management/commands/runserver.py
@@ -5,7 +5,7 @@
5 5
 import socket
6 6
 
7 7
 from django.core.management.base import BaseCommand, CommandError
8  
-from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
  8
+from django.core.servers.basehttp import run, WSGIServerException, get_internal_wsgi_application
9 9
 from django.utils import autoreload
10 10
 
11 11
 naiveip_re = re.compile(r"""^(?:
@@ -17,7 +17,7 @@
17 17
 DEFAULT_PORT = "8000"
18 18
 
19 19
 
20  
-class BaseRunserverCommand(BaseCommand):
  20
+class Command(BaseCommand):
21 21
     option_list = BaseCommand.option_list + (
22 22
         make_option('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
23 23
             help='Tells Django to use a IPv6 address.'),
@@ -128,15 +128,6 @@ def inner_run(self, *args, **options):
128 128
                 self.stdout.write("%s\n" % shutdown_message)
129 129
             sys.exit(0)
130 130
 
131  
-class Command(BaseRunserverCommand):
132  
-    option_list = BaseRunserverCommand.option_list + (
133  
-        make_option('--adminmedia', dest='admin_media_path', default='',
134  
-            help='Specifies the directory from which to serve admin media.'),
135  
-    )
136 131
 
137  
-    def get_handler(self, *args, **options):
138  
-        """
139  
-        Serves admin media like old-school (deprecation pending).
140  
-        """
141  
-        handler = super(Command, self).get_handler(*args, **options)
142  
-        return AdminMediaHandler(handler, options.get('admin_media_path'))
  132
+# Kept for backward compatibility
  133
+BaseRunserverCommand = Command
50  django/core/servers/basehttp.py
@@ -22,10 +22,6 @@
22 22
 from django.core.management.color import color_style
23 23
 from django.core.wsgi import get_wsgi_application
24 24
 from django.utils.importlib import import_module
25  
-from django.utils._os import safe_join
26  
-from django.views import static
27  
-
28  
-from django.contrib.staticfiles import handlers
29 25
 
30 26
 __all__ = ['WSGIServer', 'WSGIRequestHandler']
31 27
 
@@ -131,7 +127,7 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
131 127
 
132 128
     def __init__(self, *args, **kwargs):
133 129
         from django.conf import settings
134  
-        self.admin_media_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
  130
+        self.admin_static_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
135 131
         # We set self.path to avoid crashes in log_message() on unsupported
136 132
         # requests (like "OPTIONS").
137 133
         self.path = ''
@@ -173,7 +169,7 @@ def get_environ(self):
173 169
 
174 170
     def log_message(self, format, *args):
175 171
         # Don't bother logging requests for admin images or the favicon.
176  
-        if (self.path.startswith(self.admin_media_prefix)
  172
+        if (self.path.startswith(self.admin_static_prefix)
177 173
                 or self.path == '/favicon.ico'):
178 174
             return
179 175
 
@@ -200,48 +196,6 @@ def log_message(self, format, *args):
200 196
         sys.stderr.write(msg)
201 197
 
202 198
 
203  
-class AdminMediaHandler(handlers.StaticFilesHandler):
204  
-    """
205  
-    WSGI middleware that intercepts calls to the admin media directory, as
206  
-    defined by the STATIC_URL setting, and serves those images.
207  
-    Use this ONLY LOCALLY, for development! This hasn't been tested for
208  
-    security and is not super efficient.
209  
-
210  
-    This is pending for deprecation since 1.3.
211  
-    """
212  
-    def get_base_dir(self):
213  
-        return os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
214  
-
215  
-    def get_base_url(self):
216  
-        from django.conf import settings
217  
-        return urlparse.urljoin(settings.STATIC_URL, 'admin/')
218  
-
219  
-    def file_path(self, url):
220  
-        """
221  
-        Returns the path to the media file on disk for the given URL.
222  
-
223  
-        The passed URL is assumed to begin with ``self.base_url``.  If the
224  
-        resulting file path is outside the media directory, then a ValueError
225  
-        is raised.
226  
-        """
227  
-        relative_url = url[len(self.base_url[2]):]
228  
-        relative_path = urllib.url2pathname(relative_url)
229  
-        return safe_join(self.base_dir, relative_path)
230  
-
231  
-    def serve(self, request):
232  
-        document_root, path = os.path.split(self.file_path(request.path))
233  
-        return static.serve(request, path, document_root=document_root)
234  
-
235  
-    def _should_handle(self, path):
236  
-        """
237  
-        Checks if the path should be handled. Ignores the path if:
238  
-
239  
-        * the host is provided as part of the base_url
240  
-        * the request's path isn't under the base path
241  
-        """
242  
-        return path.startswith(self.base_url[2]) and not self.base_url[1]
243  
-
244  
-
245 199
 def run(addr, port, wsgi_handler, ipv6=False, threading=False):
246 200
     server_address = (addr, port)
247 201
     if threading:
2  docs/howto/deployment/wsgi/gunicorn.txt
@@ -58,7 +58,7 @@ This provides a few Django-specific niceties:
58 58
 * validates installed models
59 59
 
60 60
 * allows an ``--adminmedia`` option for passing in the location of the
61  
-  admin media files, mimicing the behavior of runserver.
  61
+  admin media files.
62 62
 
63 63
 See Gunicorn's `deployment documentation`_ for additional tips on starting and
64 64
 maintaining the Gunicorn server.
5  docs/man/django-admin.1
@@ -70,7 +70,7 @@ Runs this project as a FastCGI application. Requires flup. Use
70 70
 .B runfcgi help
71 71
 for help on the KEY=val pairs.
72 72
 .TP
73  
-.BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
  73
+.BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "port|ipaddr:port" "]"
74 74
 Starts a lightweight Web server for development.
75 75
 .TP
76 76
 .BI "shell [" "\-\-plain" "]"
@@ -169,9 +169,6 @@ Enables IPv6 addresses.
169 169
 .I \-\-verbosity=VERBOSITY
170 170
 Verbosity level: 0=minimal output, 1=normal output, 2=all output.
171 171
 .TP
172  
-.I \-\-adminmedia=ADMIN_MEDIA_PATH
173  
-Specifies the directory from which to serve admin media when using the development server.
174  
-.TP
175 172
 .I \-\-traceback
176 173
 By default, django-admin.py will show a simple error message whenever an
177 174
 error occurs. If you specify this option, django-admin.py  will
14  docs/ref/django-admin.txt
@@ -655,23 +655,11 @@ You can provide an IPv6 address surrounded by brackets
655 655
 
656 656
 A hostname containing ASCII-only characters can also be used.
657 657
 
658  
-.. django-admin-option:: --adminmedia
659  
-
660  
-Use the ``--adminmedia`` option to tell Django where to find the various CSS
661  
-and JavaScript files for the Django admin interface. Normally, the development
662  
-server serves these files out of the Django source tree magically, but you'd
663  
-want to use this if you made any changes to those files for your own site.
664  
-
665  
-Example usage::
666  
-
667  
-    django-admin.py runserver --adminmedia=/tmp/new-admin-style/
668  
-
669 658
 .. versionchanged:: 1.3
670 659
 
671 660
 If the :doc:`staticfiles</ref/contrib/staticfiles>` contrib app is enabled
672 661
 (default in new projects) the :djadmin:`runserver` command will be overriden
673  
-with an own :djadmin:`runserver<staticfiles-runserver>` command which doesn't
674  
-have the :djadminopt:`--adminmedia` option due to deprecation.
  662
+with an own :djadmin:`runserver<staticfiles-runserver>` command.
675 663
 
676 664
 .. django-admin-option:: --noreload
677 665
 
4  tests/regressiontests/admin_scripts/tests.py
@@ -1095,12 +1095,12 @@ def test_liveserver(self):
1095 1095
 
1096 1096
 class ManageRunserver(AdminScriptTestCase):
1097 1097
     def setUp(self):
1098  
-        from django.core.management.commands.runserver import BaseRunserverCommand
  1098
+        from django.core.management.commands.runserver import Command
1099 1099
 
1100 1100
         def monkey_run(*args, **options):
1101 1101
             return
1102 1102
 
1103  
-        self.cmd = BaseRunserverCommand()
  1103
+        self.cmd = Command()
1104 1104
         self.cmd.run = monkey_run
1105 1105
 
1106 1106
     def assertServerSettings(self, addr, port, ipv6=None, raw_ipv6=False):
20  tests/regressiontests/admin_widgets/tests.py
@@ -20,8 +20,8 @@
20 20
 from .widgetadmin import site as widget_admin_site
21 21
 
22 22
 
23  
-admin_media_prefix = lambda: {
24  
-    'ADMIN_MEDIA_PREFIX': "%sadmin/" % settings.STATIC_URL,
  23
+admin_static_prefix = lambda: {
  24
+    'ADMIN_STATIC_PREFIX': "%sadmin/" % settings.STATIC_URL,
25 25
 }
26 26
 
27 27
 class AdminFormfieldForDBFieldTests(TestCase):
@@ -196,14 +196,14 @@ def test_render(self):
196 196
         w = widgets.FilteredSelectMultiple('test', False)
197 197
         self.assertHTMLEqual(
198 198
             conditional_escape(w.render('test', 'test')),
199  
-            '<select multiple="multiple" name="test" class="selectfilter">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 0, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % admin_media_prefix()
  199
+            '<select multiple="multiple" name="test" class="selectfilter">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 0, "%(ADMIN_STATIC_PREFIX)s"); });</script>\n' % admin_static_prefix()
200 200
         )
201 201
 
202 202
     def test_stacked_render(self):
203 203
         w = widgets.FilteredSelectMultiple('test', True)
204 204
         self.assertHTMLEqual(
205 205
             conditional_escape(w.render('test', 'test')),
206  
-            '<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % admin_media_prefix()
  206
+            '<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_STATIC_PREFIX)s"); });</script>\n' % admin_static_prefix()
207 207
         )
208 208
 
209 209
 class AdminDateWidgetTest(DjangoTestCase):
@@ -292,7 +292,7 @@ def test_render(self):
292 292
         w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
293 293
         self.assertHTMLEqual(
294 294
             conditional_escape(w.render('test', band.pk, attrs={})),
295  
-            '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>' % dict(admin_media_prefix(), bandpk=band.pk)
  295
+            '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>' % dict(admin_static_prefix(), bandpk=band.pk)
296 296
         )
297 297
 
298 298
     def test_relations_to_non_primary_key(self):
@@ -307,7 +307,7 @@ def test_relations_to_non_primary_key(self):
307 307
         w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
308 308
         self.assertHTMLEqual(
309 309
             w.render('test', core.parent_id, attrs={}),
310  
-            '<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>' % admin_media_prefix()
  310
+            '<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>' % admin_static_prefix()
311 311
         )
312 312
 
313 313
     def test_fk_related_model_not_in_admin(self):
@@ -349,7 +349,7 @@ def test_proper_manager_for_label_lookup(self):
349 349
         )
350 350
         self.assertHTMLEqual(
351 351
             w.render('test', child_of_hidden.parent_id, attrs={}),
352  
-            '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>' % admin_media_prefix()
  352
+            '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>' % admin_static_prefix()
353 353
         )
354 354
 
355 355
 
@@ -365,12 +365,12 @@ def test_render(self):
365 365
         w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site)
366 366
         self.assertHTMLEqual(
367 367
             conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={})),
368  
-            '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/static/admin/img/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_media_prefix(), m1pk=m1.pk, m2pk=m2.pk)
  368
+            '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/static/admin/img/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk, m2pk=m2.pk)
369 369
         )
370 370
 
371 371
         self.assertHTMLEqual(
372 372
             conditional_escape(w.render('test', [m1.pk])),
373  
-            '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_media_prefix(), m1pk=m1.pk)
  373
+            '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk)
374 374
         )
375 375
 
376 376
         self.assertEqual(w._has_changed(None, None), False)
@@ -691,4 +691,4 @@ class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleni
691 691
     webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
692 692
 
693 693
 class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFirefoxTests):
694  
-    webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
  694
+    webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
66  tests/regressiontests/servers/tests.py
@@ -2,77 +2,15 @@
2 2
 Tests for django.core.servers.
3 3
 """
4 4
 import os
5  
-from urlparse import urljoin
6 5
 import urllib2
7 6
 
8  
-import django
9  
-from django.conf import settings
10 7
 from django.core.exceptions import ImproperlyConfigured
11  
-from django.test import TestCase, LiveServerTestCase
12  
-from django.core.handlers.wsgi import WSGIHandler
13  
-from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
  8
+from django.test import LiveServerTestCase
  9
+from django.core.servers.basehttp import WSGIServerException
14 10
 from django.test.utils import override_settings
15 11
 
16 12
 from .models import Person
17 13
 
18  
-class AdminMediaHandlerTests(TestCase):
19  
-
20  
-    def setUp(self):
21  
-        self.admin_media_url = urljoin(settings.STATIC_URL, 'admin/')
22  
-        self.admin_media_file_path = os.path.abspath(
23  
-            os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
24  
-        )
25  
-        self.handler = AdminMediaHandler(WSGIHandler())
26  
-
27  
-    def test_media_urls(self):
28  
-        """
29  
-        Tests that URLs that look like absolute file paths after the
30  
-        settings.STATIC_URL don't turn into absolute file paths.
31  
-        """
32  
-        # Cases that should work on all platforms.
33  
-        data = (
34  
-            ('%scss/base.css' % self.admin_media_url, ('css', 'base.css')),
35  
-        )
36  
-        # Cases that should raise an exception.
37  
-        bad_data = ()
38  
-
39  
-        # Add platform-specific cases.
40  
-        if os.sep == '/':
41  
-            data += (
42  
-                # URL, tuple of relative path parts.
43  
-                ('%s\\css/base.css' % self.admin_media_url, ('\\css', 'base.css')),
44  
-            )
45  
-            bad_data += (
46  
-                '%s/css/base.css' % self.admin_media_url,
47  
-                '%s///css/base.css' % self.admin_media_url,
48  
-                '%s../css/base.css' % self.admin_media_url,
49  
-            )
50  
-        elif os.sep == '\\':
51  
-            bad_data += (
52  
-                '%sC:\css/base.css' % self.admin_media_url,
53  
-                '%s/\\css/base.css' % self.admin_media_url,
54  
-                '%s\\css/base.css' % self.admin_media_url,
55  
-                '%s\\\\css/base.css' % self.admin_media_url
56  
-            )
57  
-        for url, path_tuple in data:
58  
-            try:
59  
-                output = self.handler.file_path(url)
60  
-            except ValueError:
61  
-                self.fail("Got a ValueError exception, but wasn't expecting"
62  
-                          " one. URL was: %s" % url)
63  
-            rel_path = os.path.join(*path_tuple)
64  
-            desired = os.path.join(self.admin_media_file_path, rel_path)
65  
-            self.assertEqual(
66  
-                os.path.normcase(output), os.path.normcase(desired),
67  
-                "Got: %s, Expected: %s, URL was: %s" % (output, desired, url))
68  
-        for url in bad_data:
69  
-            try:
70  
-                output = self.handler.file_path(url)
71  
-            except ValueError:
72  
-                continue
73  
-            self.fail('URL: %s should have caused a ValueError exception.'
74  
-                      % url)
75  
-
76 14
 
77 15
 TEST_ROOT = os.path.dirname(__file__)
78 16
 TEST_SETTINGS = {

0 notes on commit 5c53e30

Please sign in to comment.
Something went wrong with that request. Please try again.