Esempio n. 1
0
    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")
Esempio n. 5
0
    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)>")
Esempio n. 6
0
    def test_article_parse_attachment_from_dct_one_attachments_two(self):
        art_dct = {
            'Age': 82383,
            'AgeTimeUnix': 82383,
            'ArticleID': '30',
            'ArticleType': 'webrequest',
            'ArticleTypeID': '8',
            'Attachment': [
                {
                    'Content': 'mFyC',
                    'ContentAlternative': '',
                    'ContentID': '',
                    'ContentType': 'text/plain',
                    'Disposition': 'attachment',
                    'Filename': 'foo.txt',
                    'Filesize': '3 Bytes',
                    'FilesizeRaw': '3'
                }
            ],
            'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End',
            'Cc': '',
            'CustomerID': None,
            'CustomerUserID': None,
            'DynamicField': [
                {
                    'Name': 'ProcessManagementActivityID',
                    'Value': None
                },
                {
                    'Name': 'ProcessManagementProcessID',
                    'Value': None
                },
                {
                    'Name': 'firstname',
                    'Value': 'Jane'
                },
                {
                    'Name': 'lastname',
                    'Value': 'Doe'
                }
            ],
            'EscalationResponseTime': '0',
            'EscalationSolutionTime': '0',
        }

        art = Article(art_dct)
        att_l = art.attachments

        att_expected = Attachment({
            'Content': 'mFyC',
            'ContentAlternative': '',
            'ContentID': '',
            'ContentType': 'text/plain',
            'Disposition': 'attachment',
            'Filename': 'foo.txt',
            'Filesize': '3 Bytes',
            'FilesizeRaw': '3'
        })

        self.assertIsInstance(art, Article)
        self.assertDictEqual(att_l[0].to_dct(), att_expected.to_dct())
        self.assertIsInstance(art.attachment_get('foo.txt'), Attachment)
        self.assertIsNone(art.attachment_get('non-existent.txt'))
        self.assertIsNone(art.dynamic_field_get('non-existent'))
    def test_attachment_create_from_binary_file(self):
        """create_from_file with binary test file"""
        att = Attachment.create_from_file(os.path.join(current_path, "fixtures/logo_bg.png"))

        self.assertIsInstance(att, Attachment)
        self.assertEqual(att.ContentType, "image/png")
    def test_attachment_create_from_file_no_file_ext(self):
        """create_from_file test - no file ending -> mime needs to default"""
        att = Attachment.create_from_file(os.path.join(current_path, "fixtures/b_file"))

        self.assertIsInstance(att, Attachment)
        self.assertEqual(att.ContentType, "application/octet-stream")
    def test_attachment_create_from_file(self):
        """create_from_file test ending in .txt"""
        att = Attachment.create_from_file(os.path.join(current_path, "fixtures/a_file.txt"))

        self.assertIsInstance(att, Attachment)
        self.assertEqual(att.ContentType, "text/plain")
Esempio n. 10
0
 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'})
Esempio n. 11
0
 def test_attachment_dummy(self):
     att = Attachment._dummy()
     self.assertIsInstance(att, Attachment)
     self.assertEqual(att.__repr__(), '<Attachment: dümmy.txt>')
Esempio n. 12
0
 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>')
Esempio n. 13
0
 def test_attachment_file(self):
     att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt")
     self.assertIsInstance(att, Attachment)
Esempio n. 14
0
 def test_init_no_file(self):
     att = Attachment({'Content': 'YnFyCg==',
                       'ContentType': 'text/plain'})
     self.assertIsInstance(att, Attachment)
     self.assertEqual(att.__repr__(), '<Attachment>')
Esempio n. 15
0
 def test_init_static(self):
     att = Attachment({'Content': 'YmFyCg==',
                       'ContentType': 'text/plain',
                       'Filename': 'dümmy1.txt'})
     self.assertIsInstance(att, Attachment)