gh-98 Check that metadata is dictionary before accessing it
This commit is contained in:
parent
a0f744c082
commit
1a1a50e656
|
@ -23,6 +23,8 @@ class Base(object):
|
||||||
|
|
||||||
__name__ = 'Base'
|
__name__ = 'Base'
|
||||||
|
|
||||||
|
extensions = ()
|
||||||
|
|
||||||
def __init__(self, source=None):
|
def __init__(self, source=None):
|
||||||
self.source = source
|
self.source = source
|
||||||
self.reset_cache()
|
self.reset_cache()
|
||||||
|
@ -142,7 +144,7 @@ class Base(object):
|
||||||
metadata = self.get_metadata()
|
metadata = self.get_metadata()
|
||||||
|
|
||||||
# If this file has an album already set we do not overwrite EXIF
|
# 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
|
return False
|
||||||
|
|
||||||
folder = os.path.basename(metadata['directory_path'])
|
folder = os.path.basename(metadata['directory_path'])
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue