|
33 | 33 | from tempfile import mkdtemp, NamedTemporaryFile |
34 | 34 | from unittest import mock, TestCase |
35 | 35 |
|
| 36 | +from extract_msg import SignedAttachment |
36 | 37 | from faker import Faker |
37 | 38 | from faker_file.providers.docx_file import DocxFileProvider |
38 | 39 | from faker_file.providers.eml_file import EmlFileProvider |
@@ -735,3 +736,51 @@ def test_attachment_converted(self) -> None: |
735 | 736 | converted = convert_msg_to_text(dummy_filename, config=self.config) |
736 | 737 |
|
737 | 738 | self.assertEqual(converted.strip(), content) |
| 739 | + |
| 740 | + def test_attachment_with_null_extension_skipped(self) -> None: |
| 741 | + self.fake.add_provider(DocxFileProvider) |
| 742 | + |
| 743 | + dummy_filename = "dummy_filename.msg" |
| 744 | + |
| 745 | + content = self.fake.paragraph(nb_sentences=10) |
| 746 | + docx = self.fake.docx_file(content=content, raw=True) |
| 747 | + mock_attachment = mock.Mock( |
| 748 | + extension=None, |
| 749 | + data=BytesIO(docx).read(), |
| 750 | + ) |
| 751 | + mock_msgfile = mock.Mock( |
| 752 | + body=None, htmlBody=None, attachments=[mock_attachment] |
| 753 | + ) |
| 754 | + mock_openmsg = mock.Mock(return_value=mock_msgfile) |
| 755 | + with mock.patch.multiple( |
| 756 | + "cardinal_pythonlib.extract_text", |
| 757 | + openMsg=mock_openmsg, |
| 758 | + ): |
| 759 | + self.config.width = 0 |
| 760 | + converted = convert_msg_to_text(dummy_filename, config=self.config) |
| 761 | + |
| 762 | + self.assertEqual(converted.strip(), "") |
| 763 | + |
| 764 | + def test_signed_attachment_with_no_extension_skipped(self) -> None: |
| 765 | + self.fake.add_provider(DocxFileProvider) |
| 766 | + |
| 767 | + dummy_filename = "dummy_filename.msg" |
| 768 | + |
| 769 | + content = self.fake.paragraph(nb_sentences=10) |
| 770 | + docx = self.fake.docx_file(content=content, raw=True) |
| 771 | + mock_attachment = mock.Mock( |
| 772 | + spec=SignedAttachment, |
| 773 | + data=BytesIO(docx).read(), |
| 774 | + ) |
| 775 | + mock_msgfile = mock.Mock( |
| 776 | + body=None, htmlBody=None, attachments=[mock_attachment] |
| 777 | + ) |
| 778 | + mock_openmsg = mock.Mock(return_value=mock_msgfile) |
| 779 | + with mock.patch.multiple( |
| 780 | + "cardinal_pythonlib.extract_text", |
| 781 | + openMsg=mock_openmsg, |
| 782 | + ): |
| 783 | + self.config.width = 0 |
| 784 | + converted = convert_msg_to_text(dummy_filename, config=self.config) |
| 785 | + |
| 786 | + self.assertEqual(converted.strip(), "") |
0 commit comments