コード例 #1
0
 def test_extension_is_empty_str(self):
     """
     Tests the get_extension function when the file name is an empty string
     but the extension is guessable from the Content-Type.
     """
     self.part1['Content-Disposition'] = 'attachment; filename=""'
     self.msg.attach(self.image)
     attachment = get_first_attachment(self.msg)
     actual = attachments.get_extension(attachment)
     expected = '.jpeg'
     self.assertEqual(actual, expected)
コード例 #2
0
 def test_no_filename_guessable(self):
     """
     Tests the get_extension function when no file name is present
     but the extension is guessable from the Content-Type.
     """
     self.image['Content-Disposition'] = 'attachment;'
     self.msg.attach(self.image)
     attachment = get_first_attachment(self.msg)
     actual = attachments.get_extension(attachment)
     expected = '.jpeg'
     self.assertEqual(actual, expected)
コード例 #3
0
 def test_extension_is_none(self):
     """
     Tests the get_extension function when the file name has no extension
     but the extension is guessable from the Content-Type.
     """
     self.image['Content-Disposition'] = 'attachment; filename="profile_pic"'
     self.msg.attach(self.image)
     attachment = get_first_attachment(self.msg)
     actual = attachments.get_extension(attachment)
     expected = '.jpeg'
     self.assertEqual(actual, expected)
コード例 #4
0
 def test_extension_not_guessable(self):
     """
     Tests the get_extension function when no file name is present
     and the extension is not guessable.
     """
     self.image['Content-Disposition'] = 'attachment; filename=""'
     self.msg.attach(self.image)
     attachment = get_first_attachment(self.msg)
     attachment.get_filename = Mock(return_value=None)
     with patch('sifter.mailsifter.attachments.mimetypes') as mock_mimetypes:
         mock_mimetypes.guess_extension = Mock(return_value=None)
         actual = attachments.get_extension(attachment)
         expected = '.bin'
         self.assertEqual(actual, expected)