diff --git a/elodie/media/media.py b/elodie/media/media.py index e65ac2a..704255c 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -295,6 +295,9 @@ class Media(object): @classmethod def get_class_by_file(cls, _file, classes): + if not isinstance(_file, basestring) or not os.path.isfile(_file): + return None + extension = os.path.splitext(_file)[1][1:].lower() for i in classes: diff --git a/elodie/tests/files/.DS_Store b/elodie/tests/files/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/elodie/tests/files/.DS_Store differ diff --git a/elodie/tests/media/media_test.py b/elodie/tests/media/media_test.py index 3658b7a..ef7abaf 100644 --- a/elodie/tests/media/media_test.py +++ b/elodie/tests/media/media_test.py @@ -43,11 +43,24 @@ def test_get_class_by_file_unsupported(): assert media is None -def test_get_class_by_file_empty(): +def test_get_class_by_file_ds_store(): media = Media.get_class_by_file(helper.get_file('.DS_Store'), [Photo, Video, Audio]) assert media is None +def test_get_class_by_file_invalid_type(): + media = Media.get_class_by_file(None, + [Photo, Video, Audio]) + assert media is None + + media = Media.get_class_by_file(False, + [Photo, Video, Audio]) + assert media is None + + media = Media.get_class_by_file(True, + [Photo, Video, Audio]) + assert media is None + def is_valid(): media = Media()