Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14544 -- Squashed bug in the findstatic command when used with…

… the --first option.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14324 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 85ef6c09386ec55193dc4ca40251c7c4ca559516 1 parent c1b3dee
Jannis Leidel authored October 23, 2010
2  django/contrib/staticfiles/management/commands/findstatic.py
@@ -17,6 +17,8 @@ def handle_label(self, path, **options):
17 17
         verbosity = int(options.get('verbosity', 1))
18 18
         result = finders.find(path, all=options['all'])
19 19
         if result:
  20
+            if not isinstance(result, (list, tuple)):
  21
+                result = [result]
20 22
             output = '\n  '.join((os.path.realpath(path) for path in result))
21 23
             self.stdout.write("Found %r here:\n  %s\n" % (path, output))
22 24
         else:
34  tests/regressiontests/staticfiles_tests/tests.py
@@ -3,6 +3,7 @@
3 3
 import os
4 4
 import sys
5 5
 import posixpath
  6
+from StringIO import StringIO
6 7
 
7 8
 from django.test import TestCase
8 9
 from django.conf import settings
@@ -134,6 +135,39 @@ def test_app_files(self):
134 135
         self.assertFileContains('test/file1.txt', 'file1 in the app dir')
135 136
 
136 137
 
  138
+class TestFindStatic(BuildStaticTestCase, TestDefaults):
  139
+    """
  140
+    Test ``findstatic`` management command.
  141
+    """
  142
+    def _get_file(self, filepath):
  143
+        _stdout = sys.stdout
  144
+        sys.stdout = StringIO()
  145
+        try:
  146
+            call_command('findstatic', filepath, all=False, verbosity='0')
  147
+            sys.stdout.seek(0)
  148
+            lines = [l.strip() for l in sys.stdout.readlines()]
  149
+            contents = open(lines[1].strip()).read()
  150
+        finally:
  151
+            sys.stdout = _stdout
  152
+        return contents
  153
+
  154
+    def test_all_files(self):
  155
+        """
  156
+        Test that findstatic returns all candidate files if run without --first.
  157
+        """
  158
+        _stdout = sys.stdout
  159
+        sys.stdout = StringIO()
  160
+        try:
  161
+            call_command('findstatic', 'test/file.txt', verbosity='0')
  162
+            sys.stdout.seek(0)
  163
+            lines = [l.strip() for l in sys.stdout.readlines()]
  164
+        finally:
  165
+            sys.stdout = _stdout
  166
+        self.assertEquals(len(lines), 3) # three because there is also the "Found <file> here" line
  167
+        self.failUnless('project' in lines[1])
  168
+        self.failUnless('apps' in lines[2])
  169
+
  170
+
137 171
 class TestBuildStatic(BuildStaticTestCase, TestDefaults):
138 172
     """
139 173
     Test ``collectstatic`` management command.

0 notes on commit 85ef6c0

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