mirror of
https://github.com/django/django.git
synced 2025-01-23 08:39:17 +00:00
Added tests for collectstatic interactivity.
This commit is contained in:
parent
c93ac9cf42
commit
3f2c945257
@ -13,7 +13,7 @@ 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
|
||||
from django.test import override_settings
|
||||
from django.test import mock, override_settings
|
||||
from django.test.utils import extend_sys_path
|
||||
from django.utils import six
|
||||
from django.utils._os import symlinks_supported
|
||||
@ -176,6 +176,40 @@ class TestCollectionClear(CollectionTestCase):
|
||||
self.assertFileNotFound('cleared.txt')
|
||||
|
||||
|
||||
class TestInteractiveMessages(CollectionTestCase):
|
||||
overwrite_warning_msg = "This will overwrite existing files!"
|
||||
delete_warning_msg = "This will DELETE ALL FILES in this location!"
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
|
||||
"""
|
||||
Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
|
||||
|
Loading…
x
Reference in New Issue
Block a user