Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made sure startproject can handle template URLs with trailing slashes.

Thanks Issac Kelly that reported this via IRC.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17320 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f250ef3573d44ebb2c17c401851768a235742062 1 parent 068dcbd
Ramiro Morales authored
13  django/core/management/templates.py
@@ -196,13 +196,22 @@ def download(self, url):
196 196
         """
197 197
         Downloads the given URL and returns the file name.
198 198
         """
  199
+        def cleanup_url(url):
  200
+            tmp = url.rstrip('/')
  201
+            filename = tmp.split('/')[-1]
  202
+            if url.endswith('/'):
  203
+                display_url  = tmp + '/'
  204
+            else:
  205
+                display_url = url
  206
+            return filename, display_url
  207
+
199 208
         prefix = 'django_%s_template_' % self.app_or_project
200 209
         tempdir = tempfile.mkdtemp(prefix=prefix, suffix='_download')
201 210
         self.paths_to_remove.append(tempdir)
202  
-        filename = url.split('/')[-1]
  211
+        filename, display_url = cleanup_url(url)
203 212
 
204 213
         if self.verbosity >= 2:
205  
-            self.stdout.write("Downloading %s\n" % url)
  214
+            self.stdout.write("Downloading %s\n" % display_url)
206 215
         try:
207 216
             the_path, info = urllib.urlretrieve(url,
208 217
                                                 path.join(tempdir, filename))
18  tests/regressiontests/admin_scripts/tests.py
@@ -11,7 +11,6 @@
11 11
 import socket
12 12
 import subprocess
13 13
 import sys
14  
-import urllib
15 14
 
16 15
 from django import conf, bin, get_version
17 16
 from django.conf import settings
@@ -1387,11 +1386,12 @@ def test_simple_project(self):
1387 1386
         self.assertOutput(err, "File exists")
1388 1387
 
1389 1388
     def test_invalid_project_name(self):
  1389
+        "Make sure the startproject management command validates a project name"
  1390
+
1390 1391
         def cleanup(p):
1391 1392
             if os.path.exists(p):
1392 1393
                 shutil.rmtree(p)
1393 1394
 
1394  
-        "Make sure the startproject management command validates a project name"
1395 1395
         args = ['startproject', '7testproject']
1396 1396
         testproject_dir = os.path.join(test_dir, '7testproject')
1397 1397
 
@@ -1454,7 +1454,6 @@ def test_custom_project_template_from_tarball_by_path(self):
1454 1454
 
1455 1455
     def test_custom_project_template_from_tarball_by_url(self):
1456 1456
         "Make sure the startproject management command is able to use a different project template from a tarball via a url"
1457  
-        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template.tgz')
1458 1457
         template_url = '%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url
1459 1458
 
1460 1459
         args = ['startproject', '--template', template_url, 'urltestproject']
@@ -1465,3 +1464,16 @@ def test_custom_project_template_from_tarball_by_url(self):
1465 1464
         self.assertNoOutput(err)
1466 1465
         self.assertTrue(os.path.isdir(testproject_dir))
1467 1466
         self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))
  1467
+
  1468
+    def test_project_template_tarball_url(self):
  1469
+        "Startproject management command handles project template tar/zip balls from non-canonical urls"
  1470
+        template_url = '%s/admin_scripts/custom_templates/project_template.tgz/' % self.live_server_url
  1471
+
  1472
+        args = ['startproject', '--template', template_url, 'urltestproject']
  1473
+        testproject_dir = os.path.join(test_dir, 'urltestproject')
  1474
+
  1475
+        out, err = self.run_django_admin(args)
  1476
+        self.addCleanup(shutil.rmtree, testproject_dir)
  1477
+        self.assertNoOutput(err)
  1478
+        self.assertTrue(os.path.isdir(testproject_dir))
  1479
+        self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))

0 notes on commit f250ef3

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