44import tempfile
55import unittest
66from io import StringIO
7+ from pathlib import Path
78from unittest import mock
89
910from django .conf import settings
@@ -457,25 +458,39 @@ def run_collectstatic(self, **kwargs):
457458 )
458459 def test_collect_static_files_permissions (self ):
459460 call_command ('collectstatic' , ** self .command_params )
460- test_file = os .path .join (settings .STATIC_ROOT , "test.txt" )
461- test_dir = os .path .join (settings .STATIC_ROOT , "subdir" )
462- file_mode = os .stat (test_file )[0 ] & 0o777
463- dir_mode = os .stat (test_dir )[0 ] & 0o777
461+ static_root = Path (settings .STATIC_ROOT )
462+ test_file = static_root / 'test.txt'
463+ file_mode = test_file .stat ().st_mode & 0o777
464464 self .assertEqual (file_mode , 0o655 )
465- self .assertEqual (dir_mode , 0o765 )
465+ tests = [
466+ static_root / 'subdir' ,
467+ static_root / 'nested' ,
468+ static_root / 'nested' / 'css' ,
469+ ]
470+ for directory in tests :
471+ with self .subTest (directory = directory ):
472+ dir_mode = directory .stat ().st_mode & 0o777
473+ self .assertEqual (dir_mode , 0o765 )
466474
467475 @override_settings (
468476 FILE_UPLOAD_PERMISSIONS = None ,
469477 FILE_UPLOAD_DIRECTORY_PERMISSIONS = None ,
470478 )
471479 def test_collect_static_files_default_permissions (self ):
472480 call_command ('collectstatic' , ** self .command_params )
473- test_file = os .path .join (settings .STATIC_ROOT , "test.txt" )
474- test_dir = os .path .join (settings .STATIC_ROOT , "subdir" )
475- file_mode = os .stat (test_file )[0 ] & 0o777
476- dir_mode = os .stat (test_dir )[0 ] & 0o777
481+ static_root = Path (settings .STATIC_ROOT )
482+ test_file = static_root / 'test.txt'
483+ file_mode = test_file .stat ().st_mode & 0o777
477484 self .assertEqual (file_mode , 0o666 & ~ self .umask )
478- self .assertEqual (dir_mode , 0o777 & ~ self .umask )
485+ tests = [
486+ static_root / 'subdir' ,
487+ static_root / 'nested' ,
488+ static_root / 'nested' / 'css' ,
489+ ]
490+ for directory in tests :
491+ with self .subTest (directory = directory ):
492+ dir_mode = directory .stat ().st_mode & 0o777
493+ self .assertEqual (dir_mode , 0o777 & ~ self .umask )
479494
480495 @override_settings (
481496 FILE_UPLOAD_PERMISSIONS = 0o655 ,
@@ -484,12 +499,19 @@ def test_collect_static_files_default_permissions(self):
484499 )
485500 def test_collect_static_files_subclass_of_static_storage (self ):
486501 call_command ('collectstatic' , ** self .command_params )
487- test_file = os .path .join (settings .STATIC_ROOT , "test.txt" )
488- test_dir = os .path .join (settings .STATIC_ROOT , "subdir" )
489- file_mode = os .stat (test_file )[0 ] & 0o777
490- dir_mode = os .stat (test_dir )[0 ] & 0o777
502+ static_root = Path (settings .STATIC_ROOT )
503+ test_file = static_root / 'test.txt'
504+ file_mode = test_file .stat ().st_mode & 0o777
491505 self .assertEqual (file_mode , 0o640 )
492- self .assertEqual (dir_mode , 0o740 )
506+ tests = [
507+ static_root / 'subdir' ,
508+ static_root / 'nested' ,
509+ static_root / 'nested' / 'css' ,
510+ ]
511+ for directory in tests :
512+ with self .subTest (directory = directory ):
513+ dir_mode = directory .stat ().st_mode & 0o777
514+ self .assertEqual (dir_mode , 0o740 )
493515
494516
495517@override_settings (
0 commit comments