gh-93 Update media module to test for string before calling string functions

This commit is contained in:
Jaisen Mathai 2016-03-23 00:20:58 -07:00
parent ed127aa402
commit f234cb989d
3 changed files with 17 additions and 1 deletions

View File

@ -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:

BIN
elodie/tests/files/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -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()