Skip to content

Commit

Permalink
added some tests for permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ael-code committed Mar 23, 2015
1 parent aead0b7 commit e8e113a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 17 deletions.
37 changes: 20 additions & 17 deletions tests/fsdb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import filecmp
import string
import stat
import tempfile
from fsdb import Fsdb

Expand Down Expand Up @@ -140,23 +141,25 @@ def test_get_item_key_error(self):
with self.assertRaises(KeyError):
self.fsdb[digest]


class FsdbTestConfig(unittest.TestCase):

def setUp(self):
self.fsdb_tmp_path = tempfile.mkdtemp(prefix="fsdb_test")

def tearDown(self):
shutil.rmtree(self.fsdb_tmp_path)

def test_creation_without_params(self):
fsdb = Fsdb(self.fsdb_tmp_path)

def test_creation_with_params(self):
fsdb = Fsdb(self.fsdb_tmp_path,
mode="0770",
deep=5,
hash_alg="sha1")
def test_right_permission(self):
self.fsdb = Fsdb(os.path.join(self.fsdb_tmp_path, "fsdbRoot_"),
fmode="0600",
dmode="0700",
deep=1)
digest = self.fsdb.add(self.createTestFile())
path = self.fsdb.get_file_path(digest)
self.assertEqual(stat.S_IMODE(os.stat(path).st_mode), self.fsdb._conf['fmode'])
self.assertEqual(stat.S_IMODE(os.stat(os.path.dirname(path)).st_mode), self.fsdb._conf['dmode'])

def test_not_enough_permission_on_directory(self):
with self.assertRaisesRegexp(OSError,"Permission denied"):
self.fsdb = Fsdb(os.path.join(self.fsdb_tmp_path, "fsdbRoot_"),
dmode="0600")

def test_not_enough_permission_on_file(self):
with self.assertRaisesRegexp(OSError,"Permission denied"):
self.fsdb = Fsdb(os.path.join(self.fsdb_tmp_path, "fsdbRoot_"),
fmode="0400")


def randomID(length):
Expand Down
48 changes: 48 additions & 0 deletions tests/fsdb_test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest
import tempfile
import shutil
from fsdb import Fsdb

class FsdbTestConfig(unittest.TestCase):

def setUp(self):
self.fsdb_tmp_path = tempfile.mkdtemp(prefix="fsdb_test")

def tearDown(self):
shutil.rmtree(self.fsdb_tmp_path)

def test_creation_without_params(self):
fsdb = Fsdb(self.fsdb_tmp_path)

def test_creation_with_params(self):
fsdb = Fsdb(self.fsdb_tmp_path,
fmode="0600",
dmode="0700",
deep=10,
hash_alg="sha2")
self.assertEqual(fsdb._conf['fmode'], int("0600",8))
self.assertEqual(fsdb._conf['dmode'], int("0700",8))
self.assertEqual(fsdb._conf['deep'], 10)
self.assertEqual(fsdb._conf['hash_alg'], "sha2")

def test_negative_depth(self):
fsdb = Fsdb(self.fsdb_tmp_path,
deep=5,
hash_alg="sha1")
def test_fmode_passing(self):
fmode = "0600"
fsdb = Fsdb(self.fsdb_tmp_path,
fmode=fmode)
self.assertEqual(fsdb._conf['fmode'], int(fmode,8))

def test_dmode_passing(self):
dmode = "0700"
fsdb = Fsdb(self.fsdb_tmp_path,
fmode=dmode)
self.assertEqual(fsdb._conf['dmode'], int(dmode,8))

def test_fmode_other_session(self):
fmode = "0600"
Fsdb(self.fsdb_tmp_path, fmode=fmode)
fsdb = Fsdb(self.fsdb_tmp_path,fmode="0000")
self.assertEqual(fsdb._conf['fmode'], int(fmode,8))

0 comments on commit e8e113a

Please sign in to comment.