Author: ramiro
Date: 2012-01-01 09:45:40 -0800 (Sun, 01 Jan 2012)
New Revision: 17320
Modified:
django/trunk/django/core/management/templates.py
django/trunk/tests/regressiontests/admin_scripts/tests.py
Log:
Made sure startproject can handle template URLs with trailing slashes.
Thanks Issac Kelly that reported this via IRC.
Modified: django/trunk/django/core/management/templates.py
===================================================================
--- django/trunk/django/core/management/templates.py 2011-12-31 15:35:04 UTC
(rev 17319)
+++ django/trunk/django/core/management/templates.py 2012-01-01 17:45:40 UTC
(rev 17320)
@@ -196,13 +196,22 @@
"""
Downloads the given URL and returns the file name.
"""
+ def cleanup_url(url):
+ tmp = url.rstrip('/')
+ filename = tmp.split('/')[-1]
+ if url.endswith('/'):
+ display_url = tmp + '/'
+ else:
+ display_url = url
+ return filename, display_url
+
prefix = 'django_%s_template_' % self.app_or_project
tempdir = tempfile.mkdtemp(prefix=prefix, suffix='_download')
self.paths_to_remove.append(tempdir)
- filename = url.split('/')[-1]
+ filename, display_url = cleanup_url(url)
if self.verbosity >= 2:
- self.stdout.write("Downloading %s\n" % url)
+ self.stdout.write("Downloading %s\n" % display_url)
try:
the_path, info = urllib.urlretrieve(url,
path.join(tempdir, filename))
Modified: django/trunk/tests/regressiontests/admin_scripts/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_scripts/tests.py 2011-12-31
15:35:04 UTC (rev 17319)
+++ django/trunk/tests/regressiontests/admin_scripts/tests.py 2012-01-01
17:45:40 UTC (rev 17320)
@@ -11,7 +11,6 @@
import socket
import subprocess
import sys
-import urllib
from django import conf, bin, get_version
from django.conf import settings
@@ -1387,11 +1386,12 @@
self.assertOutput(err, "File exists")
def test_invalid_project_name(self):
+ "Make sure the startproject management command validates a project
name"
+
def cleanup(p):
if os.path.exists(p):
shutil.rmtree(p)
- "Make sure the startproject management command validates a project
name"
args = ['startproject', '7testproject']
testproject_dir = os.path.join(test_dir, '7testproject')
@@ -1454,7 +1454,6 @@
def test_custom_project_template_from_tarball_by_url(self):
"Make sure the startproject management command is able to use a
different project template from a tarball via a url"
- template_path = os.path.join(test_dir, 'admin_scripts',
'custom_templates', 'project_template.tgz')
template_url =
'%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url
args = ['startproject', '--template', template_url, 'urltestproject']
@@ -1465,3 +1464,16 @@
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir,
'run.py')))
+
+ def test_project_template_tarball_url(self):
+ "Startproject management command handles project template tar/zip
balls from non-canonical urls"
+ template_url =
'%s/admin_scripts/custom_templates/project_template.tgz/' % self.live_server_url
+
+ args = ['startproject', '--template', template_url, 'urltestproject']
+ testproject_dir = os.path.join(test_dir, 'urltestproject')
+
+ out, err = self.run_django_admin(args)
+ self.addCleanup(shutil.rmtree, testproject_dir)
+ self.assertNoOutput(err)
+ self.assertTrue(os.path.isdir(testproject_dir))
+ self.assertTrue(os.path.exists(os.path.join(testproject_dir,
'run.py')))
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.