def test_dummy_static_with_article_id_two_att_ignore_content(self): self.maxDiff = None att1 = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt") att2 = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt") art = Article({"Subject": "Dümmy Subject", "Body": "Hallo Bjørn,\n[kt]\n\n -- The End", "ArticleID": 4, "TimeUnit": 0, "MimeType": "text/plain", "Charset": "UTF8"}) art.attachments = [att1, att2] expected = {'Subject': 'Dümmy Subject', 'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End', 'ArticleID': 4, 'TimeUnit': 0, 'MimeType': 'text/plain', 'Charset': 'UTF8', 'Attachment': [{'ContentType': 'text/plain', 'Filename': 'foo.txt'}, {'ContentType': 'text/plain', 'Filename': 'dümmy.txt'}]} self.assertDictEqual(art.to_dct(attachment_cont=False), expected) self.assertEqual(art.__repr__(), "<ArticleID: 4 (2 Attachments)>")
def test_attachment_save_to_dir_two(self): """save_to_dir test - ok""" att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy5.txt") with mock.patch('pyotrs.lib.open', mock.mock_open()) as m: att.save_to_dir() self.assertEqual(m.call_count, 1) self.assertEqual(m.call_args_list, [mock.call("/tmp/dümmy5.txt", 'wb')])
def test_attachment_save_to_dir_invalid_no_content(self): """save_to_dir test - invalid Attachment""" att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt") att.__delattr__("Content") self.assertRaisesRegex(ValueError, "invalid Attachment", att.save_to_dir, "/tmp")
def test_attachment_save_to_dir_invalid_no_filename(self): """save_to_dir test - invalid Attachment""" att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy5.txt") att.__delattr__("Filename") self.assertRaisesRegex(ValueError, "invalid Attachment", att.save_to_dir, "/tmp")
def test_dummy_static_with_article_id_one_att(self): self.maxDiff = None att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt") art = Article({"Subject": "Dümmy Subject", "Body": "Hallo Bjørn,\n[kt]\n\n -- The End", "ArticleID": 3, "TimeUnit": 0, "MimeType": "text/plain", "Charset": "UTF8"}) art.attachments = [att] expected = {'Subject': 'Dümmy Subject', 'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End', 'ArticleID': 3, 'TimeUnit': 0, 'MimeType': 'text/plain', 'Charset': 'UTF8', 'Attachment': [{'Content': 'mFyCg==', 'ContentType': 'text/plain', 'Filename': 'foo.txt'}]} self.assertDictEqual(art.to_dct(), expected) self.assertEqual(art.__repr__(), "<ArticleID: 3 (1 Attachment)>")
def test_dummy_static_dct_unicode(self): att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy5.txt") self.assertDictEqual(att.to_dct(), {'Content': 'YmFyCg==', 'ContentType': 'text/plain', 'Filename': 'd\xfcmmy5.txt'})
def test_attachment_dummy_static(self): att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy2.txt") self.assertIsInstance(att, Attachment) self.assertEqual(att.__repr__(), '<Attachment: dümmy2.txt>')
def test_attachment_file(self): att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt") self.assertIsInstance(att, Attachment)