summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-07-04 21:34:29 +0000
committerJannis Leidel <jannis@leidel.info>2011-07-04 21:34:29 +0000
commit94a38dfd0ea33c243c56eb91cfcb2618882edad0 (patch)
tree616e84ed3ac501f523fddb395853e99b1678eff8 /tests/regressiontests
parentc2a48110d47a281b4757401e6aeffd4f41c08825 (diff)
Fixed #16161 -- Added `--clear` option to `collectstatic` management command to be able to explicitly clear the files stored in the destination storage before collecting.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16509 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/staticfiles_tests/tests.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index 4c0c53b2d2..8a6012653a 100644
--- a/tests/regressiontests/staticfiles_tests/tests.py
+++ b/tests/regressiontests/staticfiles_tests/tests.py
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+from __future__ import with_statement
import codecs
import os
import posixpath
@@ -36,11 +37,8 @@ class StaticFilesTestCase(TestCase):
# during checkout, we actually create one file dynamically.
_nonascii_filepath = os.path.join(
TEST_ROOT, 'apps', 'test', 'static', 'test', u'fi\u015fier.txt')
- f = codecs.open(_nonascii_filepath, 'w', 'utf-8')
- try:
+ with codecs.open(_nonascii_filepath, 'w', 'utf-8') as f:
f.write(u"fi\u015fier in the app dir")
- finally:
- f.close()
self.addCleanup(os.unlink, _nonascii_filepath)
def assertFileContains(self, filepath, text):
@@ -94,12 +92,8 @@ class BuildStaticTestCase(StaticFilesTestCase):
def _get_file(self, filepath):
assert filepath, 'filepath is empty.'
filepath = os.path.join(settings.STATIC_ROOT, filepath)
- f = codecs.open(filepath, "r", "utf-8")
- try:
+ with codecs.open(filepath, "r", "utf-8") as f:
return f.read()
- finally:
- f.close()
-
class TestDefaults(object):
@@ -197,9 +191,23 @@ class TestBuildStatic(BuildStaticTestCase, TestDefaults):
self.assertFileNotFound('test/CVS')
+class TestBuildStaticClear(BuildStaticTestCase):
+ """
+ Test the ``--clear`` option of the ``collectstatic`` managemenet 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(TestBuildStaticClear, self).run_collectstatic(clear=True)
+
+ def test_cleared_not_found(self):
+ self.assertFileNotFound('cleared.txt')
+
+
class TestBuildStaticExcludeNoDefaultIgnore(BuildStaticTestCase, TestDefaults):
"""
- Test ``--exclude-dirs`` and ``--no-default-ignore`` options for
+ Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
``collectstatic`` management command.
"""
def run_collectstatic(self):