def test_get_hash_exists(): db = Manifest() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with explicit False value as 3rd param db.add_hash(random_key, random_value, False) assert db.get_hash(random_key) == random_value, 'Lookup for hash that exists did not return value'
def test_reset_hash_db(): db = Manifest() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with explicit False value as 3rd param db.add_hash(random_key, random_value, False) assert random_key in db.hash_db, random_key db.reset_hash_db() assert random_key not in db.hash_db, random_key
def test_add_hash_explicit_write(): db = Manifest() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with explicit True value as 3rd param db.add_hash(random_key, random_value, True) assert db.check_hash(random_key) == True, 'Lookup for hash did not return True' # Instnatiate new db class to confirm random_key exists db2 = Manifest() assert db2.check_hash(random_key) == True
def test_add_hash_default_do_not_write(): db = Manifest() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with default False value as 3rd param db.add_hash(random_key, random_value) assert db.check_hash(random_key) == True, 'Lookup for hash did not return True' # Instnatiate new db class to confirm random_key does not exist db2 = Manifest() assert db2.check_hash(random_key) == False
def test_get_all(): db = Manifest() db.reset_hash_db() random_keys = [] random_values = [] for _ in range(10): random_keys.append(helper.random_string(10)) random_values.append(helper.random_string(12)) db.add_hash(random_keys[-1:][0], random_values[-1:][0], False) counter = 0 for key, value in db.all(): assert key in random_keys, key assert value in random_values, value counter += 1 assert counter == 10, counter
def _generate_db(source, debug): """Regenerate the hash.json database which contains all of the sha256 signatures of media files. The hash.json file is located at ~/.elodie/. """ constants.debug = debug result = Result() source = os.path.abspath(os.path.expanduser(source)) if not os.path.isdir(source): log.error('Source is not a valid directory %s' % source) sys.exit(1) db = Manifest() db.backup_hash_db() db.reset_hash_db() for current_file in FILESYSTEM.get_all_files(source): result.append((current_file, True)) db.add_hash(db.checksum(current_file), current_file) log.progress() db.update_hash_db() log.progress('', True) result.write()