test_management.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. import datetime
  2. import os
  3. import shutil
  4. import tempfile
  5. import unittest
  6. from io import StringIO
  7. from pathlib import Path
  8. from unittest import mock
  9. from admin_scripts.tests import AdminScriptTestCase
  10. from django.conf import settings
  11. from django.contrib.staticfiles import storage
  12. from django.contrib.staticfiles.management.commands import collectstatic, runserver
  13. from django.core.exceptions import ImproperlyConfigured
  14. from django.core.management import CommandError, call_command
  15. from django.core.management.base import SystemCheckError
  16. from django.test import RequestFactory, override_settings
  17. from django.test.utils import extend_sys_path
  18. from django.utils._os import symlinks_supported
  19. from django.utils.functional import empty
  20. from .cases import CollectionTestCase, StaticFilesTestCase, TestDefaults
  21. from .settings import TEST_ROOT, TEST_SETTINGS
  22. from .storage import DummyStorage
  23. class TestNoFilesCreated:
  24. def test_no_files_created(self):
  25. """
  26. Make sure no files were create in the destination directory.
  27. """
  28. self.assertEqual(os.listdir(settings.STATIC_ROOT), [])
  29. class TestRunserver(StaticFilesTestCase):
  30. @override_settings(MIDDLEWARE=["django.middleware.common.CommonMiddleware"])
  31. def test_middleware_loaded_only_once(self):
  32. command = runserver.Command()
  33. with mock.patch("django.middleware.common.CommonMiddleware") as mocked:
  34. command.get_handler(use_static_handler=True, insecure_serving=True)
  35. self.assertEqual(mocked.call_count, 1)
  36. def test_404_response(self):
  37. command = runserver.Command()
  38. handler = command.get_handler(use_static_handler=True, insecure_serving=True)
  39. missing_static_file = os.path.join(settings.STATIC_URL, "unknown.css")
  40. req = RequestFactory().get(missing_static_file)
  41. with override_settings(DEBUG=False):
  42. response = handler.get_response(req)
  43. self.assertEqual(response.status_code, 404)
  44. with override_settings(DEBUG=True):
  45. response = handler.get_response(req)
  46. self.assertEqual(response.status_code, 404)
  47. class TestFindStatic(TestDefaults, CollectionTestCase):
  48. """
  49. Test ``findstatic`` management command.
  50. """
  51. def _get_file(self, filepath):
  52. path = call_command(
  53. "findstatic", filepath, all=False, verbosity=0, stdout=StringIO()
  54. )
  55. with open(path, encoding="utf-8") as f:
  56. return f.read()
  57. def test_all_files(self):
  58. """
  59. findstatic returns all candidate files if run without --first and -v1.
  60. """
  61. result = call_command(
  62. "findstatic", "test/file.txt", verbosity=1, stdout=StringIO()
  63. )
  64. lines = [line.strip() for line in result.split("\n")]
  65. self.assertEqual(
  66. len(lines), 3
  67. ) # three because there is also the "Found <file> here" line
  68. self.assertIn("project", lines[1])
  69. self.assertIn("apps", lines[2])
  70. def test_all_files_less_verbose(self):
  71. """
  72. findstatic returns all candidate files if run without --first and -v0.
  73. """
  74. result = call_command(
  75. "findstatic", "test/file.txt", verbosity=0, stdout=StringIO()
  76. )
  77. lines = [line.strip() for line in result.split("\n")]
  78. self.assertEqual(len(lines), 2)
  79. self.assertIn("project", lines[0])
  80. self.assertIn("apps", lines[1])
  81. def test_all_files_more_verbose(self):
  82. """
  83. findstatic returns all candidate files if run without --first and -v2.
  84. Also, test that findstatic returns the searched locations with -v2.
  85. """
  86. result = call_command(
  87. "findstatic", "test/file.txt", verbosity=2, stdout=StringIO()
  88. )
  89. lines = [line.strip() for line in result.split("\n")]
  90. self.assertIn("project", lines[1])
  91. self.assertIn("apps", lines[2])
  92. self.assertIn("Looking in the following locations:", lines[3])
  93. searched_locations = ", ".join(lines[4:])
  94. # AppDirectoriesFinder searched locations
  95. self.assertIn(
  96. os.path.join("staticfiles_tests", "apps", "test", "static"),
  97. searched_locations,
  98. )
  99. self.assertIn(
  100. os.path.join("staticfiles_tests", "apps", "no_label", "static"),
  101. searched_locations,
  102. )
  103. # FileSystemFinder searched locations
  104. self.assertIn(TEST_SETTINGS["STATICFILES_DIRS"][1][1], searched_locations)
  105. self.assertIn(TEST_SETTINGS["STATICFILES_DIRS"][0], searched_locations)
  106. self.assertIn(str(TEST_SETTINGS["STATICFILES_DIRS"][2]), searched_locations)
  107. # DefaultStorageFinder searched locations
  108. self.assertIn(
  109. os.path.join("staticfiles_tests", "project", "site_media", "media"),
  110. searched_locations,
  111. )
  112. class TestConfiguration(StaticFilesTestCase):
  113. def test_location_empty(self):
  114. msg = "without having set the STATIC_ROOT setting to a filesystem path"
  115. err = StringIO()
  116. for root in ["", None]:
  117. with override_settings(STATIC_ROOT=root):
  118. with self.assertRaisesMessage(ImproperlyConfigured, msg):
  119. call_command(
  120. "collectstatic", interactive=False, verbosity=0, stderr=err
  121. )
  122. def test_local_storage_detection_helper(self):
  123. staticfiles_storage = storage.staticfiles_storage
  124. try:
  125. storage.staticfiles_storage._wrapped = empty
  126. with self.settings(
  127. STATICFILES_STORAGE=(
  128. "django.contrib.staticfiles.storage.StaticFilesStorage"
  129. )
  130. ):
  131. command = collectstatic.Command()
  132. self.assertTrue(command.is_local_storage())
  133. storage.staticfiles_storage._wrapped = empty
  134. with self.settings(
  135. STATICFILES_STORAGE="staticfiles_tests.storage.DummyStorage"
  136. ):
  137. command = collectstatic.Command()
  138. self.assertFalse(command.is_local_storage())
  139. collectstatic.staticfiles_storage = storage.FileSystemStorage()
  140. command = collectstatic.Command()
  141. self.assertTrue(command.is_local_storage())
  142. collectstatic.staticfiles_storage = DummyStorage()
  143. command = collectstatic.Command()
  144. self.assertFalse(command.is_local_storage())
  145. finally:
  146. staticfiles_storage._wrapped = empty
  147. collectstatic.staticfiles_storage = staticfiles_storage
  148. storage.staticfiles_storage = staticfiles_storage
  149. @override_settings(STATICFILES_DIRS=("test"))
  150. def test_collectstatis_check(self):
  151. msg = "The STATICFILES_DIRS setting is not a tuple or list."
  152. with self.assertRaisesMessage(SystemCheckError, msg):
  153. call_command("collectstatic", skip_checks=False)
  154. class TestCollectionHelpSubcommand(AdminScriptTestCase):
  155. @override_settings(STATIC_ROOT=None)
  156. def test_missing_settings_dont_prevent_help(self):
  157. """
  158. Even if the STATIC_ROOT setting is not set, one can still call the
  159. `manage.py help collectstatic` command.
  160. """
  161. self.write_settings("settings.py", apps=["django.contrib.staticfiles"])
  162. out, err = self.run_manage(["help", "collectstatic"])
  163. self.assertNoOutput(err)
  164. class TestCollection(TestDefaults, CollectionTestCase):
  165. """
  166. Test ``collectstatic`` management command.
  167. """
  168. def test_ignore(self):
  169. """
  170. -i patterns are ignored.
  171. """
  172. self.assertFileNotFound("test/test.ignoreme")
  173. def test_common_ignore_patterns(self):
  174. """
  175. Common ignore patterns (*~, .*, CVS) are ignored.
  176. """
  177. self.assertFileNotFound("test/.hidden")
  178. self.assertFileNotFound("test/backup~")
  179. self.assertFileNotFound("test/CVS")
  180. def test_pathlib(self):
  181. self.assertFileContains("pathlib.txt", "pathlib")
  182. class TestCollectionPathLib(TestCollection):
  183. def mkdtemp(self):
  184. tmp_dir = super().mkdtemp()
  185. return Path(tmp_dir)
  186. class TestCollectionVerbosity(CollectionTestCase):
  187. copying_msg = "Copying "
  188. run_collectstatic_in_setUp = False
  189. post_process_msg = "Post-processed"
  190. staticfiles_copied_msg = "static files copied to"
  191. def test_verbosity_0(self):
  192. stdout = StringIO()
  193. self.run_collectstatic(verbosity=0, stdout=stdout)
  194. self.assertEqual(stdout.getvalue(), "")
  195. def test_verbosity_1(self):
  196. stdout = StringIO()
  197. self.run_collectstatic(verbosity=1, stdout=stdout)
  198. output = stdout.getvalue()
  199. self.assertIn(self.staticfiles_copied_msg, output)
  200. self.assertNotIn(self.copying_msg, output)
  201. def test_verbosity_2(self):
  202. stdout = StringIO()
  203. self.run_collectstatic(verbosity=2, stdout=stdout)
  204. output = stdout.getvalue()
  205. self.assertIn(self.staticfiles_copied_msg, output)
  206. self.assertIn(self.copying_msg, output)
  207. @override_settings(
  208. STATICFILES_STORAGE=(
  209. "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
  210. )
  211. )
  212. def test_verbosity_1_with_post_process(self):
  213. stdout = StringIO()
  214. self.run_collectstatic(verbosity=1, stdout=stdout, post_process=True)
  215. self.assertNotIn(self.post_process_msg, stdout.getvalue())
  216. @override_settings(
  217. STATICFILES_STORAGE=(
  218. "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
  219. )
  220. )
  221. def test_verbosity_2_with_post_process(self):
  222. stdout = StringIO()
  223. self.run_collectstatic(verbosity=2, stdout=stdout, post_process=True)
  224. self.assertIn(self.post_process_msg, stdout.getvalue())
  225. class TestCollectionClear(CollectionTestCase):
  226. """
  227. Test the ``--clear`` option of the ``collectstatic`` management command.
  228. """
  229. def run_collectstatic(self, **kwargs):
  230. clear_filepath = os.path.join(settings.STATIC_ROOT, "cleared.txt")
  231. with open(clear_filepath, "w") as f:
  232. f.write("should be cleared")
  233. super().run_collectstatic(clear=True)
  234. def test_cleared_not_found(self):
  235. self.assertFileNotFound("cleared.txt")
  236. def test_dir_not_exists(self, **kwargs):
  237. shutil.rmtree(settings.STATIC_ROOT)
  238. super().run_collectstatic(clear=True)
  239. @override_settings(
  240. STATICFILES_STORAGE="staticfiles_tests.storage.PathNotImplementedStorage"
  241. )
  242. def test_handle_path_notimplemented(self):
  243. self.run_collectstatic()
  244. self.assertFileNotFound("cleared.txt")
  245. class TestInteractiveMessages(CollectionTestCase):
  246. overwrite_warning_msg = "This will overwrite existing files!"
  247. delete_warning_msg = "This will DELETE ALL FILES in this location!"
  248. files_copied_msg = "static files copied"
  249. @staticmethod
  250. def mock_input(stdout):
  251. def _input(msg):
  252. stdout.write(msg)
  253. return "yes"
  254. return _input
  255. def test_warning_when_clearing_staticdir(self):
  256. stdout = StringIO()
  257. self.run_collectstatic()
  258. with mock.patch("builtins.input", side_effect=self.mock_input(stdout)):
  259. call_command("collectstatic", interactive=True, clear=True, stdout=stdout)
  260. output = stdout.getvalue()
  261. self.assertNotIn(self.overwrite_warning_msg, output)
  262. self.assertIn(self.delete_warning_msg, output)
  263. def test_warning_when_overwriting_files_in_staticdir(self):
  264. stdout = StringIO()
  265. self.run_collectstatic()
  266. with mock.patch("builtins.input", side_effect=self.mock_input(stdout)):
  267. call_command("collectstatic", interactive=True, stdout=stdout)
  268. output = stdout.getvalue()
  269. self.assertIn(self.overwrite_warning_msg, output)
  270. self.assertNotIn(self.delete_warning_msg, output)
  271. def test_no_warning_when_staticdir_does_not_exist(self):
  272. stdout = StringIO()
  273. shutil.rmtree(settings.STATIC_ROOT)
  274. call_command("collectstatic", interactive=True, stdout=stdout)
  275. output = stdout.getvalue()
  276. self.assertNotIn(self.overwrite_warning_msg, output)
  277. self.assertNotIn(self.delete_warning_msg, output)
  278. self.assertIn(self.files_copied_msg, output)
  279. def test_no_warning_for_empty_staticdir(self):
  280. stdout = StringIO()
  281. with tempfile.TemporaryDirectory(
  282. prefix="collectstatic_empty_staticdir_test"
  283. ) as static_dir:
  284. with override_settings(STATIC_ROOT=static_dir):
  285. call_command("collectstatic", interactive=True, stdout=stdout)
  286. output = stdout.getvalue()
  287. self.assertNotIn(self.overwrite_warning_msg, output)
  288. self.assertNotIn(self.delete_warning_msg, output)
  289. self.assertIn(self.files_copied_msg, output)
  290. def test_cancelled(self):
  291. self.run_collectstatic()
  292. with mock.patch("builtins.input", side_effect=lambda _: "no"):
  293. with self.assertRaisesMessage(
  294. CommandError, "Collecting static files cancelled"
  295. ):
  296. call_command("collectstatic", interactive=True)
  297. class TestCollectionNoDefaultIgnore(TestDefaults, CollectionTestCase):
  298. """
  299. The ``--no-default-ignore`` option of the ``collectstatic`` management
  300. command.
  301. """
  302. def run_collectstatic(self):
  303. super().run_collectstatic(use_default_ignore_patterns=False)
  304. def test_no_common_ignore_patterns(self):
  305. """
  306. With --no-default-ignore, common ignore patterns (*~, .*, CVS)
  307. are not ignored.
  308. """
  309. self.assertFileContains("test/.hidden", "should be ignored")
  310. self.assertFileContains("test/backup~", "should be ignored")
  311. self.assertFileContains("test/CVS", "should be ignored")
  312. @override_settings(
  313. INSTALLED_APPS=[
  314. "staticfiles_tests.apps.staticfiles_config.IgnorePatternsAppConfig",
  315. "staticfiles_tests.apps.test",
  316. ]
  317. )
  318. class TestCollectionCustomIgnorePatterns(CollectionTestCase):
  319. def test_custom_ignore_patterns(self):
  320. """
  321. A custom ignore_patterns list, ['*.css', '*/vendor/*.js'] in this case,
  322. can be specified in an AppConfig definition.
  323. """
  324. self.assertFileNotFound("test/nonascii.css")
  325. self.assertFileContains("test/.hidden", "should be ignored")
  326. self.assertFileNotFound(os.path.join("test", "vendor", "module.js"))
  327. class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
  328. """
  329. Test ``--dry-run`` option for ``collectstatic`` management command.
  330. """
  331. def run_collectstatic(self):
  332. super().run_collectstatic(dry_run=True)
  333. @override_settings(
  334. STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
  335. )
  336. class TestCollectionDryRunManifestStaticFilesStorage(TestCollectionDryRun):
  337. pass
  338. class TestCollectionFilesOverride(CollectionTestCase):
  339. """
  340. Test overriding duplicated files by ``collectstatic`` management command.
  341. Check for proper handling of apps order in installed apps even if file modification
  342. dates are in different order:
  343. 'staticfiles_test_app',
  344. 'staticfiles_tests.apps.no_label',
  345. """
  346. def setUp(self):
  347. self.temp_dir = tempfile.mkdtemp()
  348. self.addCleanup(shutil.rmtree, self.temp_dir)
  349. # get modification and access times for no_label/static/file2.txt
  350. self.orig_path = os.path.join(
  351. TEST_ROOT, "apps", "no_label", "static", "file2.txt"
  352. )
  353. self.orig_mtime = os.path.getmtime(self.orig_path)
  354. self.orig_atime = os.path.getatime(self.orig_path)
  355. # prepare duplicate of file2.txt from a temporary app
  356. # this file will have modification time older than no_label/static/file2.txt
  357. # anyway it should be taken to STATIC_ROOT because the temporary app is before
  358. # 'no_label' app in installed apps
  359. self.temp_app_path = os.path.join(self.temp_dir, "staticfiles_test_app")
  360. self.testfile_path = os.path.join(self.temp_app_path, "static", "file2.txt")
  361. os.makedirs(self.temp_app_path)
  362. with open(os.path.join(self.temp_app_path, "__init__.py"), "w+"):
  363. pass
  364. os.makedirs(os.path.dirname(self.testfile_path))
  365. with open(self.testfile_path, "w+") as f:
  366. f.write("duplicate of file2.txt")
  367. os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
  368. self.settings_with_test_app = self.modify_settings(
  369. INSTALLED_APPS={"prepend": "staticfiles_test_app"},
  370. )
  371. with extend_sys_path(self.temp_dir):
  372. self.settings_with_test_app.enable()
  373. super().setUp()
  374. def tearDown(self):
  375. super().tearDown()
  376. self.settings_with_test_app.disable()
  377. def test_ordering_override(self):
  378. """
  379. Test if collectstatic takes files in proper order
  380. """
  381. self.assertFileContains("file2.txt", "duplicate of file2.txt")
  382. # run collectstatic again
  383. self.run_collectstatic()
  384. self.assertFileContains("file2.txt", "duplicate of file2.txt")
  385. # The collectstatic test suite already has conflicting files since both
  386. # project/test/file.txt and apps/test/static/test/file.txt are collected. To
  387. # properly test for the warning not happening unless we tell it to explicitly,
  388. # we remove the project directory and will add back a conflicting file later.
  389. @override_settings(STATICFILES_DIRS=[])
  390. class TestCollectionOverwriteWarning(CollectionTestCase):
  391. """
  392. Test warning in ``collectstatic`` output when a file is skipped because a
  393. previous file was already written to the same path.
  394. """
  395. # If this string is in the collectstatic output, it means the warning we're
  396. # looking for was emitted.
  397. warning_string = "Found another file"
  398. def _collectstatic_output(self, **kwargs):
  399. """
  400. Run collectstatic, and capture and return the output. We want to run
  401. the command at highest verbosity, which is why we can't
  402. just call e.g. BaseCollectionTestCase.run_collectstatic()
  403. """
  404. out = StringIO()
  405. call_command(
  406. "collectstatic", interactive=False, verbosity=3, stdout=out, **kwargs
  407. )
  408. return out.getvalue()
  409. def test_no_warning(self):
  410. """
  411. There isn't a warning if there isn't a duplicate destination.
  412. """
  413. output = self._collectstatic_output(clear=True)
  414. self.assertNotIn(self.warning_string, output)
  415. def test_warning(self):
  416. """
  417. There is a warning when there are duplicate destinations.
  418. """
  419. with tempfile.TemporaryDirectory() as static_dir:
  420. duplicate = os.path.join(static_dir, "test", "file.txt")
  421. os.mkdir(os.path.dirname(duplicate))
  422. with open(duplicate, "w+") as f:
  423. f.write("duplicate of file.txt")
  424. with self.settings(STATICFILES_DIRS=[static_dir]):
  425. output = self._collectstatic_output(clear=True)
  426. self.assertIn(self.warning_string, output)
  427. os.remove(duplicate)
  428. # Make sure the warning went away again.
  429. with self.settings(STATICFILES_DIRS=[static_dir]):
  430. output = self._collectstatic_output(clear=True)
  431. self.assertNotIn(self.warning_string, output)
  432. @override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.DummyStorage")
  433. class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase):
  434. """
  435. Tests for a Storage that implements get_modified_time() but not path()
  436. (#15035).
  437. """
  438. def test_storage_properties(self):
  439. # Properties of the Storage as described in the ticket.
  440. storage = DummyStorage()
  441. self.assertEqual(
  442. storage.get_modified_time("name"),
  443. datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc),
  444. )
  445. with self.assertRaisesMessage(
  446. NotImplementedError, "This backend doesn't support absolute paths."
  447. ):
  448. storage.path("name")
  449. class TestCollectionNeverCopyStorage(CollectionTestCase):
  450. @override_settings(
  451. STATICFILES_STORAGE="staticfiles_tests.storage.NeverCopyRemoteStorage"
  452. )
  453. def test_skips_newer_files_in_remote_storage(self):
  454. """
  455. collectstatic skips newer files in a remote storage.
  456. run_collectstatic() in setUp() copies the static files, then files are
  457. always skipped after NeverCopyRemoteStorage is activated since
  458. NeverCopyRemoteStorage.get_modified_time() returns a datetime in the
  459. future to simulate an unmodified file.
  460. """
  461. stdout = StringIO()
  462. self.run_collectstatic(stdout=stdout, verbosity=2)
  463. output = stdout.getvalue()
  464. self.assertIn("Skipping 'test.txt' (not modified)", output)
  465. @unittest.skipUnless(symlinks_supported(), "Must be able to symlink to run this test.")
  466. class TestCollectionLinks(TestDefaults, CollectionTestCase):
  467. """
  468. Test ``--link`` option for ``collectstatic`` management command.
  469. Note that by inheriting ``TestDefaults`` we repeat all
  470. the standard file resolving tests here, to make sure using
  471. ``--link`` does not change the file-selection semantics.
  472. """
  473. def run_collectstatic(self, clear=False, link=True, **kwargs):
  474. super().run_collectstatic(link=link, clear=clear, **kwargs)
  475. def test_links_created(self):
  476. """
  477. With ``--link``, symbolic links are created.
  478. """
  479. self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, "test.txt")))
  480. def test_broken_symlink(self):
  481. """
  482. Test broken symlink gets deleted.
  483. """
  484. path = os.path.join(settings.STATIC_ROOT, "test.txt")
  485. os.unlink(path)
  486. self.run_collectstatic()
  487. self.assertTrue(os.path.islink(path))
  488. def test_symlinks_and_files_replaced(self):
  489. """
  490. Running collectstatic in non-symlink mode replaces symlinks with files,
  491. while symlink mode replaces files with symlinks.
  492. """
  493. path = os.path.join(settings.STATIC_ROOT, "test.txt")
  494. self.assertTrue(os.path.islink(path))
  495. self.run_collectstatic(link=False)
  496. self.assertFalse(os.path.islink(path))
  497. self.run_collectstatic(link=True)
  498. self.assertTrue(os.path.islink(path))
  499. def test_clear_broken_symlink(self):
  500. """
  501. With ``--clear``, broken symbolic links are deleted.
  502. """
  503. nonexistent_file_path = os.path.join(settings.STATIC_ROOT, "nonexistent.txt")
  504. broken_symlink_path = os.path.join(settings.STATIC_ROOT, "symlink.txt")
  505. os.symlink(nonexistent_file_path, broken_symlink_path)
  506. self.run_collectstatic(clear=True)
  507. self.assertFalse(os.path.lexists(broken_symlink_path))
  508. @override_settings(
  509. STATICFILES_STORAGE="staticfiles_tests.storage.PathNotImplementedStorage"
  510. )
  511. def test_no_remote_link(self):
  512. with self.assertRaisesMessage(
  513. CommandError, "Can't symlink to a remote destination."
  514. ):
  515. self.run_collectstatic()