2015-07-01 19:43:25 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import codecs
|
|
|
|
import os
|
|
|
|
import shutil
|
2015-06-05 06:02:32 +08:00
|
|
|
import tempfile
|
2015-07-01 19:43:25 +08:00
|
|
|
import unittest
|
|
|
|
|
2015-11-21 04:59:34 +08:00
|
|
|
from admin_scripts.tests import AdminScriptTestCase
|
|
|
|
|
2015-07-01 19:43:25 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.staticfiles import storage
|
|
|
|
from django.contrib.staticfiles.management.commands import collectstatic
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
from django.core.management import call_command
|
2016-08-27 08:46:46 +08:00
|
|
|
from django.test import mock, override_settings
|
2015-06-05 06:02:32 +08:00
|
|
|
from django.test.utils import extend_sys_path
|
2015-07-01 19:43:25 +08:00
|
|
|
from django.utils import six
|
|
|
|
from django.utils._os import symlinks_supported
|
|
|
|
from django.utils.encoding import force_text
|
|
|
|
from django.utils.functional import empty
|
|
|
|
|
|
|
|
from .cases import CollectionTestCase, StaticFilesTestCase, TestDefaults
|
|
|
|
from .settings import TEST_ROOT, TEST_SETTINGS
|
|
|
|
from .storage import DummyStorage
|
|
|
|
|
|
|
|
|
|
|
|
class TestNoFilesCreated(object):
|
|
|
|
|
|
|
|
def test_no_files_created(self):
|
|
|
|
"""
|
|
|
|
Make sure no files were create in the destination directory.
|
|
|
|
"""
|
|
|
|
self.assertEqual(os.listdir(settings.STATIC_ROOT), [])
|
|
|
|
|
|
|
|
|
2016-03-26 23:17:06 +08:00
|
|
|
class TestFindStatic(TestDefaults, CollectionTestCase):
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
Test ``findstatic`` management command.
|
|
|
|
"""
|
|
|
|
def _get_file(self, filepath):
|
2016-02-14 01:20:29 +08:00
|
|
|
path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=six.StringIO())
|
|
|
|
with codecs.open(force_text(path), "r", "utf-8") as f:
|
2015-07-01 19:43:25 +08:00
|
|
|
return f.read()
|
|
|
|
|
|
|
|
def test_all_files(self):
|
|
|
|
"""
|
2016-10-27 15:53:39 +08:00
|
|
|
findstatic returns all candidate files if run without --first and -v1.
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
2016-02-14 01:20:29 +08:00
|
|
|
result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=six.StringIO())
|
|
|
|
lines = [l.strip() for l in result.split('\n')]
|
2015-07-01 19:43:25 +08:00
|
|
|
self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
|
|
|
|
self.assertIn('project', force_text(lines[1]))
|
|
|
|
self.assertIn('apps', force_text(lines[2]))
|
|
|
|
|
|
|
|
def test_all_files_less_verbose(self):
|
|
|
|
"""
|
2016-10-27 15:53:39 +08:00
|
|
|
findstatic returns all candidate files if run without --first and -v0.
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
2016-02-14 01:20:29 +08:00
|
|
|
result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=six.StringIO())
|
|
|
|
lines = [l.strip() for l in result.split('\n')]
|
2015-07-01 19:43:25 +08:00
|
|
|
self.assertEqual(len(lines), 2)
|
|
|
|
self.assertIn('project', force_text(lines[0]))
|
|
|
|
self.assertIn('apps', force_text(lines[1]))
|
|
|
|
|
|
|
|
def test_all_files_more_verbose(self):
|
|
|
|
"""
|
2016-10-27 15:53:39 +08:00
|
|
|
findstatic returns all candidate files if run without --first and -v2.
|
2015-07-01 19:43:25 +08:00
|
|
|
Also, test that findstatic returns the searched locations with -v2.
|
|
|
|
"""
|
2016-02-14 01:20:29 +08:00
|
|
|
result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=six.StringIO())
|
|
|
|
lines = [l.strip() for l in result.split('\n')]
|
2015-07-01 19:43:25 +08:00
|
|
|
self.assertIn('project', force_text(lines[1]))
|
|
|
|
self.assertIn('apps', force_text(lines[2]))
|
|
|
|
self.assertIn("Looking in the following locations:", force_text(lines[3]))
|
|
|
|
searched_locations = ', '.join(force_text(x) for x in lines[4:])
|
|
|
|
# AppDirectoriesFinder searched locations
|
|
|
|
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'), searched_locations)
|
|
|
|
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'no_label', 'static'), searched_locations)
|
|
|
|
# FileSystemFinder searched locations
|
|
|
|
self.assertIn(TEST_SETTINGS['STATICFILES_DIRS'][1][1], searched_locations)
|
|
|
|
self.assertIn(TEST_SETTINGS['STATICFILES_DIRS'][0], searched_locations)
|
|
|
|
# DefaultStorageFinder searched locations
|
|
|
|
self.assertIn(
|
|
|
|
os.path.join('staticfiles_tests', 'project', 'site_media', 'media'),
|
|
|
|
searched_locations
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestConfiguration(StaticFilesTestCase):
|
|
|
|
def test_location_empty(self):
|
2016-01-18 16:45:45 +08:00
|
|
|
msg = 'without having set the STATIC_ROOT setting to a filesystem path'
|
2015-07-01 19:43:25 +08:00
|
|
|
err = six.StringIO()
|
|
|
|
for root in ['', None]:
|
|
|
|
with override_settings(STATIC_ROOT=root):
|
2016-01-18 16:45:45 +08:00
|
|
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
2015-07-01 19:43:25 +08:00
|
|
|
call_command('collectstatic', interactive=False, verbosity=0, stderr=err)
|
|
|
|
|
|
|
|
def test_local_storage_detection_helper(self):
|
|
|
|
staticfiles_storage = storage.staticfiles_storage
|
|
|
|
try:
|
|
|
|
storage.staticfiles_storage._wrapped = empty
|
|
|
|
with self.settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage'):
|
|
|
|
command = collectstatic.Command()
|
|
|
|
self.assertTrue(command.is_local_storage())
|
|
|
|
|
|
|
|
storage.staticfiles_storage._wrapped = empty
|
|
|
|
with self.settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage'):
|
|
|
|
command = collectstatic.Command()
|
|
|
|
self.assertFalse(command.is_local_storage())
|
|
|
|
|
|
|
|
collectstatic.staticfiles_storage = storage.FileSystemStorage()
|
|
|
|
command = collectstatic.Command()
|
|
|
|
self.assertTrue(command.is_local_storage())
|
|
|
|
|
|
|
|
collectstatic.staticfiles_storage = DummyStorage()
|
|
|
|
command = collectstatic.Command()
|
|
|
|
self.assertFalse(command.is_local_storage())
|
|
|
|
finally:
|
|
|
|
staticfiles_storage._wrapped = empty
|
|
|
|
collectstatic.staticfiles_storage = staticfiles_storage
|
|
|
|
storage.staticfiles_storage = staticfiles_storage
|
|
|
|
|
|
|
|
|
2015-11-21 04:59:34 +08:00
|
|
|
class TestCollectionHelpSubcommand(AdminScriptTestCase):
|
|
|
|
@override_settings(STATIC_ROOT=None)
|
|
|
|
def test_missing_settings_dont_prevent_help(self):
|
|
|
|
"""
|
|
|
|
Even if the STATIC_ROOT setting is not set, one can still call the
|
|
|
|
`manage.py help collectstatic` command.
|
|
|
|
"""
|
|
|
|
self.write_settings('settings.py', apps=['django.contrib.staticfiles'])
|
|
|
|
out, err = self.run_manage(['help', 'collectstatic'])
|
|
|
|
self.assertNoOutput(err)
|
|
|
|
|
|
|
|
|
2016-03-26 23:17:06 +08:00
|
|
|
class TestCollection(TestDefaults, CollectionTestCase):
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
Test ``collectstatic`` management command.
|
|
|
|
"""
|
|
|
|
def test_ignore(self):
|
|
|
|
"""
|
2016-10-27 15:53:39 +08:00
|
|
|
-i patterns are ignored.
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
self.assertFileNotFound('test/test.ignoreme')
|
|
|
|
|
|
|
|
def test_common_ignore_patterns(self):
|
|
|
|
"""
|
|
|
|
Common ignore patterns (*~, .*, CVS) are ignored.
|
|
|
|
"""
|
|
|
|
self.assertFileNotFound('test/.hidden')
|
|
|
|
self.assertFileNotFound('test/backup~')
|
|
|
|
self.assertFileNotFound('test/CVS')
|
|
|
|
|
|
|
|
|
|
|
|
class TestCollectionClear(CollectionTestCase):
|
|
|
|
"""
|
|
|
|
Test the ``--clear`` option of the ``collectstatic`` management command.
|
|
|
|
"""
|
|
|
|
def run_collectstatic(self, **kwargs):
|
|
|
|
clear_filepath = os.path.join(settings.STATIC_ROOT, 'cleared.txt')
|
|
|
|
with open(clear_filepath, 'w') as f:
|
|
|
|
f.write('should be cleared')
|
|
|
|
super(TestCollectionClear, self).run_collectstatic(clear=True)
|
|
|
|
|
|
|
|
def test_cleared_not_found(self):
|
|
|
|
self.assertFileNotFound('cleared.txt')
|
|
|
|
|
|
|
|
def test_dir_not_exists(self, **kwargs):
|
|
|
|
shutil.rmtree(six.text_type(settings.STATIC_ROOT))
|
|
|
|
super(TestCollectionClear, self).run_collectstatic(clear=True)
|
|
|
|
|
2016-03-14 11:17:05 +08:00
|
|
|
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.PathNotImplementedStorage')
|
|
|
|
def test_handle_path_notimplemented(self):
|
|
|
|
self.run_collectstatic()
|
|
|
|
self.assertFileNotFound('cleared.txt')
|
|
|
|
|
2015-07-01 19:43:25 +08:00
|
|
|
|
2016-08-27 08:46:46 +08:00
|
|
|
class TestInteractiveMessages(CollectionTestCase):
|
|
|
|
overwrite_warning_msg = "This will overwrite existing files!"
|
|
|
|
delete_warning_msg = "This will DELETE ALL FILES in this location!"
|
2016-08-27 08:54:06 +08:00
|
|
|
files_copied_msg = "static files copied"
|
2016-08-27 08:46:46 +08:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def mock_input(stdout):
|
|
|
|
def _input(msg):
|
|
|
|
# Python 2 reads bytes from the console output, use bytes for the StringIO
|
|
|
|
stdout.write(msg.encode('utf-8') if six.PY2 else msg)
|
|
|
|
return 'yes'
|
|
|
|
return _input
|
|
|
|
|
|
|
|
def test_warning_when_clearing_staticdir(self):
|
|
|
|
stdout = six.StringIO()
|
|
|
|
self.run_collectstatic()
|
|
|
|
with mock.patch('django.contrib.staticfiles.management.commands.collectstatic.input',
|
|
|
|
side_effect=self.mock_input(stdout)):
|
|
|
|
call_command('collectstatic', interactive=True, clear=True, stdout=stdout)
|
|
|
|
|
|
|
|
output = force_text(stdout.getvalue())
|
|
|
|
self.assertNotIn(self.overwrite_warning_msg, output)
|
|
|
|
self.assertIn(self.delete_warning_msg, output)
|
|
|
|
|
|
|
|
def test_warning_when_overwriting_files_in_staticdir(self):
|
|
|
|
stdout = six.StringIO()
|
|
|
|
self.run_collectstatic()
|
|
|
|
with mock.patch('django.contrib.staticfiles.management.commands.collectstatic.input',
|
|
|
|
side_effect=self.mock_input(stdout)):
|
|
|
|
call_command('collectstatic', interactive=True, stdout=stdout)
|
|
|
|
output = force_text(stdout.getvalue())
|
|
|
|
self.assertIn(self.overwrite_warning_msg, output)
|
|
|
|
self.assertNotIn(self.delete_warning_msg, output)
|
|
|
|
|
2016-08-27 08:54:06 +08:00
|
|
|
def test_no_warning_when_staticdir_does_not_exist(self):
|
|
|
|
stdout = six.StringIO()
|
|
|
|
shutil.rmtree(six.text_type(settings.STATIC_ROOT))
|
|
|
|
call_command('collectstatic', interactive=True, stdout=stdout)
|
|
|
|
output = force_text(stdout.getvalue())
|
|
|
|
self.assertNotIn(self.overwrite_warning_msg, output)
|
|
|
|
self.assertNotIn(self.delete_warning_msg, output)
|
|
|
|
self.assertIn(self.files_copied_msg, output)
|
|
|
|
|
|
|
|
def test_no_warning_for_empty_staticdir(self):
|
|
|
|
stdout = six.StringIO()
|
|
|
|
static_dir = tempfile.mkdtemp(prefix='collectstatic_empty_staticdir_test')
|
|
|
|
with override_settings(STATIC_ROOT=static_dir):
|
|
|
|
call_command('collectstatic', interactive=True, stdout=stdout)
|
|
|
|
shutil.rmtree(six.text_type(static_dir))
|
|
|
|
output = force_text(stdout.getvalue())
|
|
|
|
self.assertNotIn(self.overwrite_warning_msg, output)
|
|
|
|
self.assertNotIn(self.delete_warning_msg, output)
|
|
|
|
self.assertIn(self.files_copied_msg, output)
|
|
|
|
|
2016-08-27 08:46:46 +08:00
|
|
|
|
2016-03-26 23:17:06 +08:00
|
|
|
class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
|
|
|
|
``collectstatic`` management command.
|
|
|
|
"""
|
|
|
|
def run_collectstatic(self):
|
|
|
|
super(TestCollectionExcludeNoDefaultIgnore, self).run_collectstatic(
|
|
|
|
use_default_ignore_patterns=False)
|
|
|
|
|
|
|
|
def test_no_common_ignore_patterns(self):
|
|
|
|
"""
|
|
|
|
With --no-default-ignore, common ignore patterns (*~, .*, CVS)
|
|
|
|
are not ignored.
|
|
|
|
"""
|
|
|
|
self.assertFileContains('test/.hidden', 'should be ignored')
|
|
|
|
self.assertFileContains('test/backup~', 'should be ignored')
|
|
|
|
self.assertFileContains('test/CVS', 'should be ignored')
|
|
|
|
|
|
|
|
|
2016-04-16 03:05:06 +08:00
|
|
|
@override_settings(INSTALLED_APPS=[
|
|
|
|
'staticfiles_tests.apps.staticfiles_config.IgnorePatternsAppConfig',
|
|
|
|
'staticfiles_tests.apps.test',
|
|
|
|
])
|
|
|
|
class TestCollectionCustomIgnorePatterns(CollectionTestCase):
|
|
|
|
def test_custom_ignore_patterns(self):
|
|
|
|
"""
|
|
|
|
A custom ignore_patterns list, ['*.css'] in this case, can be specified
|
|
|
|
in an AppConfig definition.
|
|
|
|
"""
|
|
|
|
self.assertFileNotFound('test/nonascii.css')
|
|
|
|
self.assertFileContains('test/.hidden', 'should be ignored')
|
|
|
|
|
|
|
|
|
2016-03-26 23:17:06 +08:00
|
|
|
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
Test ``--dry-run`` option for ``collectstatic`` management command.
|
|
|
|
"""
|
|
|
|
def run_collectstatic(self):
|
|
|
|
super(TestCollectionDryRun, self).run_collectstatic(dry_run=True)
|
|
|
|
|
|
|
|
|
|
|
|
class TestCollectionFilesOverride(CollectionTestCase):
|
|
|
|
"""
|
|
|
|
Test overriding duplicated files by ``collectstatic`` management command.
|
|
|
|
Check for proper handling of apps order in installed apps even if file modification
|
|
|
|
dates are in different order:
|
2015-06-05 06:02:32 +08:00
|
|
|
'staticfiles_test_app',
|
2015-07-01 19:43:25 +08:00
|
|
|
'staticfiles_tests.apps.no_label',
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
2015-06-05 06:02:32 +08:00
|
|
|
self.temp_dir = tempfile.mkdtemp()
|
|
|
|
self.addCleanup(shutil.rmtree, self.temp_dir)
|
|
|
|
|
2015-07-01 19:43:25 +08:00
|
|
|
# get modification and access times for no_label/static/file2.txt
|
2015-06-05 06:02:32 +08:00
|
|
|
self.orig_path = os.path.join(TEST_ROOT, 'apps', 'no_label', 'static', 'file2.txt')
|
2015-07-01 19:43:25 +08:00
|
|
|
self.orig_mtime = os.path.getmtime(self.orig_path)
|
|
|
|
self.orig_atime = os.path.getatime(self.orig_path)
|
|
|
|
|
2015-06-05 06:02:32 +08:00
|
|
|
# prepare duplicate of file2.txt from a temporary app
|
2015-07-01 19:43:25 +08:00
|
|
|
# this file will have modification time older than no_label/static/file2.txt
|
2015-06-05 06:02:32 +08:00
|
|
|
# anyway it should be taken to STATIC_ROOT because the temporary app is before
|
2015-07-01 19:43:25 +08:00
|
|
|
# 'no_label' app in installed apps
|
2015-06-05 06:02:32 +08:00
|
|
|
self.temp_app_path = os.path.join(self.temp_dir, 'staticfiles_test_app')
|
|
|
|
self.testfile_path = os.path.join(self.temp_app_path, 'static', 'file2.txt')
|
|
|
|
|
|
|
|
os.makedirs(self.temp_app_path)
|
|
|
|
with open(os.path.join(self.temp_app_path, '__init__.py'), 'w+'):
|
|
|
|
pass
|
|
|
|
|
|
|
|
os.makedirs(os.path.dirname(self.testfile_path))
|
2015-07-01 19:43:25 +08:00
|
|
|
with open(self.testfile_path, 'w+') as f:
|
|
|
|
f.write('duplicate of file2.txt')
|
2015-06-05 06:02:32 +08:00
|
|
|
|
2015-07-01 19:43:25 +08:00
|
|
|
os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
|
2015-06-05 06:02:32 +08:00
|
|
|
|
|
|
|
self.settings_with_test_app = self.modify_settings(
|
|
|
|
INSTALLED_APPS={'prepend': 'staticfiles_test_app'})
|
|
|
|
with extend_sys_path(self.temp_dir):
|
|
|
|
self.settings_with_test_app.enable()
|
|
|
|
|
2015-07-01 19:43:25 +08:00
|
|
|
super(TestCollectionFilesOverride, self).setUp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestCollectionFilesOverride, self).tearDown()
|
2015-06-05 06:02:32 +08:00
|
|
|
self.settings_with_test_app.disable()
|
2015-07-01 19:43:25 +08:00
|
|
|
|
|
|
|
def test_ordering_override(self):
|
|
|
|
"""
|
|
|
|
Test if collectstatic takes files in proper order
|
|
|
|
"""
|
|
|
|
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
|
|
|
|
|
|
|
|
# run collectstatic again
|
|
|
|
self.run_collectstatic()
|
|
|
|
|
|
|
|
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
|
|
|
|
|
|
|
|
|
|
|
|
# The collectstatic test suite already has conflicting files since both
|
|
|
|
# project/test/file.txt and apps/test/static/test/file.txt are collected. To
|
|
|
|
# properly test for the warning not happening unless we tell it to explicitly,
|
2015-06-05 06:02:32 +08:00
|
|
|
# we remove the project directory and will add back a conflicting file later.
|
2015-07-01 19:43:25 +08:00
|
|
|
@override_settings(STATICFILES_DIRS=[])
|
|
|
|
class TestCollectionOverwriteWarning(CollectionTestCase):
|
|
|
|
"""
|
|
|
|
Test warning in ``collectstatic`` output when a file is skipped because a
|
|
|
|
previous file was already written to the same path.
|
|
|
|
"""
|
|
|
|
# If this string is in the collectstatic output, it means the warning we're
|
|
|
|
# looking for was emitted.
|
|
|
|
warning_string = 'Found another file'
|
|
|
|
|
|
|
|
def _collectstatic_output(self, **kwargs):
|
|
|
|
"""
|
|
|
|
Run collectstatic, and capture and return the output. We want to run
|
|
|
|
the command at highest verbosity, which is why we can't
|
|
|
|
just call e.g. BaseCollectionTestCase.run_collectstatic()
|
|
|
|
"""
|
|
|
|
out = six.StringIO()
|
|
|
|
call_command('collectstatic', interactive=False, verbosity=3, stdout=out, **kwargs)
|
2015-06-05 06:02:32 +08:00
|
|
|
return force_text(out.getvalue())
|
2015-07-01 19:43:25 +08:00
|
|
|
|
|
|
|
def test_no_warning(self):
|
|
|
|
"""
|
|
|
|
There isn't a warning if there isn't a duplicate destination.
|
|
|
|
"""
|
|
|
|
output = self._collectstatic_output(clear=True)
|
2015-06-05 06:02:32 +08:00
|
|
|
self.assertNotIn(self.warning_string, output)
|
2015-07-01 19:43:25 +08:00
|
|
|
|
|
|
|
def test_warning(self):
|
|
|
|
"""
|
|
|
|
There is a warning when there are duplicate destinations.
|
|
|
|
"""
|
2015-06-05 06:02:32 +08:00
|
|
|
static_dir = tempfile.mkdtemp()
|
|
|
|
self.addCleanup(shutil.rmtree, static_dir)
|
2015-07-01 19:43:25 +08:00
|
|
|
|
2015-06-05 06:02:32 +08:00
|
|
|
duplicate = os.path.join(static_dir, 'test', 'file.txt')
|
|
|
|
os.mkdir(os.path.dirname(duplicate))
|
|
|
|
with open(duplicate, 'w+') as f:
|
|
|
|
f.write('duplicate of file.txt')
|
|
|
|
|
|
|
|
with self.settings(STATICFILES_DIRS=[static_dir]):
|
2015-07-01 19:43:25 +08:00
|
|
|
output = self._collectstatic_output(clear=True)
|
2015-06-05 06:02:32 +08:00
|
|
|
self.assertIn(self.warning_string, output)
|
2015-07-01 19:43:25 +08:00
|
|
|
|
2015-06-05 06:02:32 +08:00
|
|
|
os.remove(duplicate)
|
2015-07-01 19:43:25 +08:00
|
|
|
|
|
|
|
# Make sure the warning went away again.
|
2015-06-05 06:02:32 +08:00
|
|
|
with self.settings(STATICFILES_DIRS=[static_dir]):
|
|
|
|
output = self._collectstatic_output(clear=True)
|
|
|
|
self.assertNotIn(self.warning_string, output)
|
2015-07-01 19:43:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage')
|
2016-03-26 23:17:06 +08:00
|
|
|
class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase):
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
Tests for #15035
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(symlinks_supported(), "Must be able to symlink to run this test.")
|
2016-03-26 23:17:06 +08:00
|
|
|
class TestCollectionLinks(TestDefaults, CollectionTestCase):
|
2015-07-01 19:43:25 +08:00
|
|
|
"""
|
|
|
|
Test ``--link`` option for ``collectstatic`` management command.
|
|
|
|
|
|
|
|
Note that by inheriting ``TestDefaults`` we repeat all
|
|
|
|
the standard file resolving tests here, to make sure using
|
|
|
|
``--link`` does not change the file-selection semantics.
|
|
|
|
"""
|
2015-10-12 14:34:16 +08:00
|
|
|
def run_collectstatic(self, clear=False):
|
|
|
|
super(TestCollectionLinks, self).run_collectstatic(link=True, clear=clear)
|
2015-07-01 19:43:25 +08:00
|
|
|
|
|
|
|
def test_links_created(self):
|
|
|
|
"""
|
|
|
|
With ``--link``, symbolic links are created.
|
|
|
|
"""
|
|
|
|
self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt')))
|
|
|
|
|
|
|
|
def test_broken_symlink(self):
|
|
|
|
"""
|
|
|
|
Test broken symlink gets deleted.
|
|
|
|
"""
|
|
|
|
path = os.path.join(settings.STATIC_ROOT, 'test.txt')
|
|
|
|
os.unlink(path)
|
|
|
|
self.run_collectstatic()
|
|
|
|
self.assertTrue(os.path.islink(path))
|
2015-10-12 14:34:16 +08:00
|
|
|
|
|
|
|
def test_clear_broken_symlink(self):
|
|
|
|
"""
|
|
|
|
With ``--clear``, broken symbolic links are deleted.
|
|
|
|
"""
|
|
|
|
nonexistent_file_path = os.path.join(settings.STATIC_ROOT, 'nonexistent.txt')
|
|
|
|
broken_symlink_path = os.path.join(settings.STATIC_ROOT, 'symlink.txt')
|
|
|
|
os.symlink(nonexistent_file_path, broken_symlink_path)
|
|
|
|
self.run_collectstatic(clear=True)
|
|
|
|
self.assertFalse(os.path.lexists(broken_symlink_path))
|