gh-98 Check that metadata is dictionary before accessing it

This commit is contained in:
Jaisen Mathai 2016-04-14 22:12:44 -07:00
parent a0f744c082
commit 1a1a50e656
2 changed files with 38 additions and 1 deletions

View File

@ -23,6 +23,8 @@ class Base(object):
__name__ = 'Base'
extensions = ()
def __init__(self, source=None):
self.source = source
self.reset_cache()
@ -142,7 +144,7 @@ class Base(object):
metadata = self.get_metadata()
# If this file has an album already set we do not overwrite EXIF
if(metadata['album'] is not None):
if(not isinstance(metadata, dict) or metadata['album'] is not None):
return False
folder = os.path.basename(metadata['directory_path'])

View File

@ -0,0 +1,35 @@
# Project imports
import os
import sys
import hashlib
import random
import re
import shutil
import string
import tempfile
import time
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))))
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
import helper
from elodie.media.base import Base
os.environ['TZ'] = 'GMT'
def test_set_album_from_folder_invalid_file():
temporary_folder, folder = helper.create_working_folder()
base_file = helper.get_file('invalid.jpg')
origin = '%s/invalid.jpg' % folder
shutil.copyfile(base_file, origin)
base = Base(origin)
status = base.set_album_from_folder()
assert status == False, status