From a47a00d7a9dc83d6d199db2d1dbf075e1816c119 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Sun, 16 Jul 2017 14:25:16 -0400 Subject: [PATCH] Fix bug in split_mimetype and add test --- kittengroomer/helpers.py | 2 +- tests/test_kittengroomer.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/kittengroomer/helpers.py b/kittengroomer/helpers.py index da6f401..45ba4e9 100644 --- a/kittengroomer/helpers.py +++ b/kittengroomer/helpers.py @@ -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 diff --git a/tests/test_kittengroomer.py b/tests/test_kittengroomer.py index 37c8b9d..dc6c35d 100644 --- a/tests/test_kittengroomer.py +++ b/tests/test_kittengroomer.py @@ -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):