mirror of
https://github.com/beetbox/beets.git
synced 2026-01-17 05:34:23 +01:00
Bring test_permissions.py up to 100%
This commit is contained in:
parent
4d07e45732
commit
edefc1373e
1 changed files with 26 additions and 28 deletions
|
|
@ -5,6 +5,9 @@
|
|||
from __future__ import (division, absolute_import, print_function,
|
||||
unicode_literals)
|
||||
|
||||
import os
|
||||
from mock import patch, Mock
|
||||
|
||||
from test._common import unittest
|
||||
from test.helper import TestHelper
|
||||
from beetsplug.permissions import (check_permissions,
|
||||
|
|
@ -26,45 +29,40 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper):
|
|||
self.unload_plugins()
|
||||
|
||||
def test_permissions_on_album_imported(self):
|
||||
self.importer = self.create_importer()
|
||||
self.importer.run()
|
||||
item = self.lib.items().get()
|
||||
|
||||
file_perm = self.config['permissions']['file'].get()
|
||||
file_perm = convert_perm(file_perm)
|
||||
|
||||
dir_perm = self.config['permissions']['dir'].get()
|
||||
dir_perm = convert_perm(dir_perm)
|
||||
|
||||
music_dirs = dirs_in_library(self.lib.directory, item.path)
|
||||
|
||||
self.assertTrue(check_permissions(item.path, file_perm))
|
||||
self.assertFalse(check_permissions(item.path, convert_perm(644)))
|
||||
|
||||
for path in music_dirs:
|
||||
self.assertTrue(check_permissions(path, dir_perm))
|
||||
self.assertFalse(check_permissions(path, convert_perm(644)))
|
||||
self.do_test(True)
|
||||
|
||||
def test_permissions_on_item_imported(self):
|
||||
self.config['import']['singletons'] = True
|
||||
self.do_test(True)
|
||||
|
||||
@patch("os.chmod", Mock())
|
||||
def test_failing_to_set_permissions(self):
|
||||
self.do_test(False)
|
||||
|
||||
def do_test(self, expectSuccess):
|
||||
self.importer = self.create_importer()
|
||||
self.importer.run()
|
||||
item = self.lib.items().get()
|
||||
|
||||
file_perm = self.config['permissions']['file'].get()
|
||||
file_perm = convert_perm(file_perm)
|
||||
exp_perms = {k: convert_perm(self.config['permissions'][k].get())
|
||||
for k in ['file', 'dir']}
|
||||
|
||||
dir_perm = self.config['permissions']['dir'].get()
|
||||
dir_perm = convert_perm(dir_perm)
|
||||
self.assertPerms(item.path, convert_perm(644),
|
||||
exp_perms['file'], expectSuccess)
|
||||
|
||||
music_dirs = dirs_in_library(self.lib.directory, item.path)
|
||||
for path in dirs_in_library(self.lib.directory, item.path):
|
||||
self.assertPerms(path, convert_perm(755),
|
||||
exp_perms['dir'], expectSuccess)
|
||||
|
||||
self.assertTrue(check_permissions(item.path, file_perm))
|
||||
self.assertFalse(check_permissions(item.path, convert_perm(644)))
|
||||
def assertPerms(self, path, old_perms, new_perms, expectSuccess):
|
||||
for x in [(True, new_perms if expectSuccess else old_perms, '!='),
|
||||
(False, old_perms if expectSuccess else new_perms, '==')]:
|
||||
self.assertEqual(x[0], check_permissions(path, x[1]),
|
||||
msg='{} : {} {} {}'.format(
|
||||
path, oct(os.stat(path).st_mode), x[2], oct(x[1])))
|
||||
|
||||
for path in music_dirs:
|
||||
self.assertTrue(check_permissions(path, dir_perm))
|
||||
self.assertFalse(check_permissions(path, convert_perm(644)))
|
||||
def test_convert_perm_from_string(self):
|
||||
self.assertEqual(convert_perm('10'), 8)
|
||||
|
||||
|
||||
def suite():
|
||||
|
|
|
|||
Loading…
Reference in a new issue