def item_enclosure_mime_type(self, item): try: file_loc = os.path.join( settings.MEDIA_ROOT, get_item(item)['local_path'].encode('utf-8')) return lookup_mime_type(file_loc) except: return None
def test_unsupported_extension_returns_octetstream(self): """ For a bad extension, do we return the proper default? """ tests = [ '/var/junk/filename.something.xyz', '../var/junk/~filename_something', '../../junk.junk.xxx' ] for test in tests: self.assertEqual('application/octet-stream', lookup_mime_type(test))
def item_enclosure_mime_type(self, item): try: file_loc = os.path.join( settings.MEDIA_ROOT, get_item(item)['local_path'].encode('utf-8') ) return lookup_mime_type(file_loc) except: return None
def test_known_good_mimetypes(self): """ For known good mimetypes, make sure we return the right value """ tests = { 'mp3/2015/1/1/something_v._something_else.mp3': 'audio/mpeg', 'doc/2015/1/1/voutila_v._bonvini.doc': 'application/msword', 'pdf/2015/1/1/voutila_v._bonvini.pdf': 'application/pdf', 'txt/2015/1/1/voutila_v._bonvini.txt': 'text/plain', } for test_path in tests.keys(): self.assertEqual(tests.get(test_path), lookup_mime_type(test_path))
def test_known_good_mimetypes(self): """ For known good mimetypes, make sure we return the right value """ tests = { "mp3/2015/1/1/something_v._something_else.mp3": "audio/mpeg", "doc/2015/1/1/voutila_v._bonvini.doc": "application/msword", "pdf/2015/1/1/voutila_v._bonvini.pdf": "application/pdf", "txt/2015/1/1/voutila_v._bonvini.txt": "text/plain", } for test_path in tests.keys(): self.assertEqual(tests.get(test_path), lookup_mime_type(test_path))
def test_known_good_mimetypes(self): """ For known good mimetypes, make sure we return the right value """ tests = { 'mp3/2015/1/1/something_v._something_else.mp3':'audio/mpeg', 'doc/2015/1/1/voutila_v._bonvini.doc':'application/msword', 'pdf/2015/1/1/voutila_v._bonvini.pdf':'application/pdf', 'txt/2015/1/1/voutila_v._bonvini.txt':'text/plain', } for test_path in tests.keys(): self.assertEqual(tests.get(test_path), lookup_mime_type(test_path))
def item_enclosure_mime_type(self, item): try: path = get_item(item)["local_path"] return lookup_mime_type(path) except: return None