6
6
7
7
from beets .test ._common import touch
8
8
from beets .test .helper import AsIsImporterMixin , ImportTestCase , PluginMixin
9
- from beets .util import displayable_path
10
9
from beetsplug .permissions import (
11
10
check_permissions ,
12
11
convert_perm ,
@@ -23,57 +22,25 @@ def setUp(self):
23
22
self .config ["permissions" ] = {"file" : "777" , "dir" : "777" }
24
23
25
24
def test_permissions_on_album_imported (self ):
26
- self .do_thing ( True )
25
+ self .import_and_check_permissions ( )
27
26
28
27
def test_permissions_on_item_imported (self ):
29
28
self .config ["import" ]["singletons" ] = True
30
- self .do_thing ( True )
29
+ self .import_and_check_permissions ( )
31
30
32
- @patch ("os.chmod" , Mock ())
33
- def test_failing_to_set_permissions (self ):
34
- self .do_thing (False )
35
-
36
- def do_thing (self , expect_success ):
31
+ def import_and_check_permissions (self ):
37
32
if platform .system () == "Windows" :
38
33
self .skipTest ("permissions not available on Windows" )
39
34
40
- def get_stat (v ):
41
- return (
42
- os .stat (os .path .join (self .temp_dir , b"import" , * v )).st_mode
43
- & 0o777
44
- )
45
-
46
- typs = ["file" , "dir" ]
47
-
48
- track_file = (b"album" , b"track_1.mp3" )
49
- self .exp_perms = {
50
- True : {
51
- k : convert_perm (self .config ["permissions" ][k ].get ())
52
- for k in typs
53
- },
54
- False : {k : get_stat (v ) for (k , v ) in zip (typs , (track_file , ()))},
55
- }
35
+ track_file = os .path .join (self .import_dir , b"album" , b"track_1.mp3" )
36
+ assert os .stat (track_file ).st_mode & 0o777 != 511
56
37
57
38
self .run_asis_importer ()
58
39
item = self .lib .items ().get ()
59
40
60
- self .assertPerms (item .path , "file" , expect_success )
61
-
62
- for path in dirs_in_library (self .lib .directory , item .path ):
63
- self .assertPerms (path , "dir" , expect_success )
64
-
65
- def assertPerms (self , path , typ , expect_success ):
66
- for x in [
67
- (True , self .exp_perms [expect_success ][typ ], "!=" ),
68
- (False , self .exp_perms [not expect_success ][typ ], "==" ),
69
- ]:
70
- msg = "{} : {} {} {}" .format (
71
- displayable_path (path ),
72
- oct (os .stat (path ).st_mode ),
73
- x [2 ],
74
- oct (x [1 ]),
75
- )
76
- assert x [0 ] == check_permissions (path , x [1 ]), msg
41
+ paths = (item .path , * dirs_in_library (self .lib .directory , item .path ))
42
+ for path in paths :
43
+ assert os .stat (path ).st_mode & 0o777 == 511
77
44
78
45
def test_convert_perm_from_string (self ):
79
46
assert convert_perm ("10" ) == 8
0 commit comments