44import tempfile
55import unittest
66from io import StringIO
7+ from pathlib import Path
78from unittest import mock
89
910from django .conf import settings
@@ -530,25 +531,39 @@ def run_collectstatic(self, **kwargs):
530531 )
531532 def test_collect_static_files_permissions (self ):
532533 call_command ('collectstatic' , ** self .command_params )
533- test_file = os .path .join (settings .STATIC_ROOT , "test.txt" )
534- test_dir = os .path .join (settings .STATIC_ROOT , "subdir" )
535- file_mode = os .stat (test_file )[0 ] & 0o777
536- dir_mode = os .stat (test_dir )[0 ] & 0o777
534+ static_root = Path (settings .STATIC_ROOT )
535+ test_file = static_root / 'test.txt'
536+ file_mode = test_file .stat ().st_mode & 0o777
537537 self .assertEqual (file_mode , 0o655 )
538- self .assertEqual (dir_mode , 0o765 )
538+ tests = [
539+ static_root / 'subdir' ,
540+ static_root / 'nested' ,
541+ static_root / 'nested' / 'css' ,
542+ ]
543+ for directory in tests :
544+ with self .subTest (directory = directory ):
545+ dir_mode = directory .stat ().st_mode & 0o777
546+ self .assertEqual (dir_mode , 0o765 )
539547
540548 @override_settings (
541549 FILE_UPLOAD_PERMISSIONS = None ,
542550 FILE_UPLOAD_DIRECTORY_PERMISSIONS = None ,
543551 )
544552 def test_collect_static_files_default_permissions (self ):
545553 call_command ('collectstatic' , ** self .command_params )
546- test_file = os .path .join (settings .STATIC_ROOT , "test.txt" )
547- test_dir = os .path .join (settings .STATIC_ROOT , "subdir" )
548- file_mode = os .stat (test_file )[0 ] & 0o777
549- dir_mode = os .stat (test_dir )[0 ] & 0o777
554+ static_root = Path (settings .STATIC_ROOT )
555+ test_file = static_root / 'test.txt'
556+ file_mode = test_file .stat ().st_mode & 0o777
550557 self .assertEqual (file_mode , 0o666 & ~ self .umask )
551- self .assertEqual (dir_mode , 0o777 & ~ self .umask )
558+ tests = [
559+ static_root / 'subdir' ,
560+ static_root / 'nested' ,
561+ static_root / 'nested' / 'css' ,
562+ ]
563+ for directory in tests :
564+ with self .subTest (directory = directory ):
565+ dir_mode = directory .stat ().st_mode & 0o777
566+ self .assertEqual (dir_mode , 0o777 & ~ self .umask )
552567
553568 @override_settings (
554569 FILE_UPLOAD_PERMISSIONS = 0o655 ,
@@ -557,12 +572,19 @@ def test_collect_static_files_default_permissions(self):
557572 )
558573 def test_collect_static_files_subclass_of_static_storage (self ):
559574 call_command ('collectstatic' , ** self .command_params )
560- test_file = os .path .join (settings .STATIC_ROOT , "test.txt" )
561- test_dir = os .path .join (settings .STATIC_ROOT , "subdir" )
562- file_mode = os .stat (test_file )[0 ] & 0o777
563- dir_mode = os .stat (test_dir )[0 ] & 0o777
575+ static_root = Path (settings .STATIC_ROOT )
576+ test_file = static_root / 'test.txt'
577+ file_mode = test_file .stat ().st_mode & 0o777
564578 self .assertEqual (file_mode , 0o640 )
565- self .assertEqual (dir_mode , 0o740 )
579+ tests = [
580+ static_root / 'subdir' ,
581+ static_root / 'nested' ,
582+ static_root / 'nested' / 'css' ,
583+ ]
584+ for directory in tests :
585+ with self .subTest (directory = directory ):
586+ dir_mode = directory .stat ().st_mode & 0o777
587+ self .assertEqual (dir_mode , 0o740 )
566588
567589
568590@override_settings (
0 commit comments