Source

filevault / test_filevault.py

Full commit
from filevault import Vault

# HASH from default salt
A_HASH = "fa1fcedb71e2aa8054bce52050500a1339df532f20b27e927020b0d3249c4c29"
A_HASH_PATH = "f/a/1/"

# HASH from custom salt
B_HASH = "629c5f83210b2635dd14e73b59950a3c41113599044254b4dc8648784d221041"
SALT = "if there's a booger in your sugar pass the salt"   

VAULT_PATH = "/tmp/test-vault-will-be-deleted/"

def test_a_with_default_salt():
    v = Vault( vaultpath = VAULT_PATH )
    assert A_HASH in v.create_filename('a')

def test_a_and_ext_with_default_salt():
    v = Vault( vaultpath = VAULT_PATH )
    a_filename = v.create_filename('a','png')
    assert A_HASH in a_filename and '.png' in a_filename

def test_default_depth():
    v = Vault( vaultpath = VAULT_PATH )
    a_filename = v.create_filename('a')
    assert A_HASH in a_filename
    assert len( a_filename.split('/') ) == 4

def test_custom_depth_one():
    v = Vault( vaultpath = VAULT_PATH, depth = 1 )
    a_filename = v.create_filename('a')
    assert A_HASH in a_filename
    assert len( a_filename.split('/') ) == 2

def test_custom_depth_four():
    v = Vault( vaultpath = VAULT_PATH, depth = 4 )
    a_filename = v.create_filename('a')
    assert A_HASH in a_filename
    assert len( a_filename.split('/') ) == 5

def test_valid_depth_path():
    v = Vault( vaultpath = VAULT_PATH ) 
    a_filename = v.create_filename('a')
    assert A_HASH_PATH in a_filename 

def test_custom_salt():
    v = Vault( vaultpath = VAULT_PATH, salt = SALT )
    assert B_HASH in v.create_filename('b')

def test_create_random_filename():
    v = Vault( vaultpath = VAULT_PATH ) 
    random_filename = v.create_random_filename()
    assert len( random_filename.split('/') ) == 4
    assert len( random_filename ) == 70

def test_ext_equals_dot_ext():
    v = Vault( vaultpath = VAULT_PATH )
    assert v.create_filename('a','png') == v.create_filename('a','.png') 

def test_tardown_filevault():
    from shutil import rmtree
    rmtree( VAULT_PATH )