Fix bug in split_mimetype and add test

pull/16/head
Dan Puttick 2017-07-16 14:25:16 -04:00
parent 36c4493cd6
commit a47a00d7a9
2 changed files with 9 additions and 2 deletions

View File

@ -251,7 +251,7 @@ class FileBase(object):
return mimetype
def _split_mimetype(self, mimetype):
if '/' in mimetype:
if mimetype and '/' in mimetype:
main_type, sub_type = mimetype.split('/')
else:
main_type, sub_type = None, None

View File

@ -124,7 +124,7 @@ class TestFileBase:
with mock.patch('kittengroomer.helpers.magic.from_file',
return_value='text/plain'):
file = FileBase('', '')
file.mimetype = 'text/plain'
assert file.mimetype == 'text/plain'
def test_maintype_and_subtype_attributes(self):
"""If a file has a full mimetype, maintype and subtype should ==
@ -142,6 +142,13 @@ class TestFileBase:
file = FileBase('', '')
assert file.has_mimetype is False
def test_has_mimetype_mimetype_is_none(self):
"""If a file doesn't have a full mimetype has_mimetype should == False."""
with mock.patch('kittengroomer.helpers.FileBase._determine_mimetype',
return_value=None):
file = FileBase('', '')
assert file.has_mimetype is False
# File properties
def get_property_doesnt_exist(self, text_file):