|
6 | 6 | import pickle |
7 | 7 | import re |
8 | 8 | import shutil |
| 9 | +import sys |
9 | 10 | import tempfile |
10 | 11 | import threading |
11 | 12 | import time |
12 | 13 | import unittest |
13 | 14 | from pathlib import Path |
14 | | -from unittest import mock |
| 15 | +from unittest import mock, skipIf |
15 | 16 |
|
16 | 17 | from django.conf import settings |
17 | 18 | from django.core import management, signals |
@@ -1466,6 +1467,28 @@ def test_get_ignores_enoent(self): |
1466 | 1467 | # Returns the default instead of erroring. |
1467 | 1468 | self.assertEqual(cache.get('foo', 'baz'), 'baz') |
1468 | 1469 |
|
| 1470 | + @skipIf( |
| 1471 | + sys.platform == 'win32', |
| 1472 | + 'Windows only partially supports umasks and chmod.', |
| 1473 | + ) |
| 1474 | + def test_cache_dir_permissions(self): |
| 1475 | + os.rmdir(self.dirname) |
| 1476 | + dir_path = Path(self.dirname) / 'nested' / 'filebasedcache' |
| 1477 | + for cache_params in settings.CACHES.values(): |
| 1478 | + cache_params['LOCATION'] = dir_path |
| 1479 | + setting_changed.send(self.__class__, setting='CACHES', enter=False) |
| 1480 | + cache.set('foo', 'bar') |
| 1481 | + self.assertIs(dir_path.exists(), True) |
| 1482 | + tests = [ |
| 1483 | + dir_path, |
| 1484 | + dir_path.parent, |
| 1485 | + dir_path.parent.parent, |
| 1486 | + ] |
| 1487 | + for directory in tests: |
| 1488 | + with self.subTest(directory=directory): |
| 1489 | + dir_mode = directory.stat().st_mode & 0o777 |
| 1490 | + self.assertEqual(dir_mode, 0o700) |
| 1491 | + |
1469 | 1492 | def test_get_does_not_ignore_non_filenotfound_exceptions(self): |
1470 | 1493 | with mock.patch('builtins.open', side_effect=OSError): |
1471 | 1494 | with self.assertRaises(OSError): |
|
0 commit comments