mirror of https://github.com/CIRCL/PyCIRCLean
Fix bug in split_mimetype and add test
parent
36c4493cd6
commit
a47a00d7a9
|
@ -251,7 +251,7 @@ class FileBase(object):
|
||||||
return mimetype
|
return mimetype
|
||||||
|
|
||||||
def _split_mimetype(self, mimetype):
|
def _split_mimetype(self, mimetype):
|
||||||
if '/' in mimetype:
|
if mimetype and '/' in mimetype:
|
||||||
main_type, sub_type = mimetype.split('/')
|
main_type, sub_type = mimetype.split('/')
|
||||||
else:
|
else:
|
||||||
main_type, sub_type = None, None
|
main_type, sub_type = None, None
|
||||||
|
|
|
@ -124,7 +124,7 @@ class TestFileBase:
|
||||||
with mock.patch('kittengroomer.helpers.magic.from_file',
|
with mock.patch('kittengroomer.helpers.magic.from_file',
|
||||||
return_value='text/plain'):
|
return_value='text/plain'):
|
||||||
file = FileBase('', '')
|
file = FileBase('', '')
|
||||||
file.mimetype = 'text/plain'
|
assert file.mimetype == 'text/plain'
|
||||||
|
|
||||||
def test_maintype_and_subtype_attributes(self):
|
def test_maintype_and_subtype_attributes(self):
|
||||||
"""If a file has a full mimetype, maintype and subtype should ==
|
"""If a file has a full mimetype, maintype and subtype should ==
|
||||||
|
@ -142,6 +142,13 @@ class TestFileBase:
|
||||||
file = FileBase('', '')
|
file = FileBase('', '')
|
||||||
assert file.has_mimetype is False
|
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
|
# File properties
|
||||||
|
|
||||||
def get_property_doesnt_exist(self, text_file):
|
def get_property_doesnt_exist(self, text_file):
|
||||||
|
|
Loading…
Reference in New Issue