From 1a1a50e65618a6c2d5a1de993b51c61d7ba1ad50 Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Thu, 14 Apr 2016 22:12:44 -0700 Subject: [PATCH] gh-98 Check that metadata is dictionary before accessing it --- elodie/media/base.py | 4 +++- elodie/tests/media/base_test.py | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 elodie/tests/media/base_test.py diff --git a/elodie/media/base.py b/elodie/media/base.py index b26d96b..702a289 100644 --- a/elodie/media/base.py +++ b/elodie/media/base.py @@ -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']) diff --git a/elodie/tests/media/base_test.py b/elodie/tests/media/base_test.py new file mode 100644 index 0000000..cbceb3c --- /dev/null +++ b/elodie/tests/media/base_test.py @@ -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 +