summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests/test_management.py
diff options
context:
space:
mode:
authorFrançois Freitag <francois.freitag@polyconseil.fr>2016-08-26 17:46:46 -0700
committerTim Graham <timograham@gmail.com>2016-09-01 19:46:03 -0400
commit3f2c945257e3d9015252c801d124bd70768f2d0c (patch)
treebeea7f74d61a4527cf91278a7677552dc2aa612b /tests/staticfiles_tests/test_management.py
parentc93ac9cf42bff259ab71b70a89b693b9c38e4666 (diff)
Added tests for collectstatic interactivity.
Diffstat (limited to 'tests/staticfiles_tests/test_management.py')
-rw-r--r--tests/staticfiles_tests/test_management.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py
index d2ae7e2ed5..4cca344490 100644
--- a/tests/staticfiles_tests/test_management.py
+++ b/tests/staticfiles_tests/test_management.py
@@ -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