Exemplo 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)>")
Exemplo n.º 2
0
    def test_validation(self):
        """Article validation; blacklisted fields should be removed, others should be added"""
        expected = {'Subject': 'This Article only has Subject',
                    'Body': 'and Body and needs to be completed.'}

        expected_validated = {'Subject': 'This Article only has Subject',
                              'Body': 'and Body and needs to be completed.',
                              'TimeUnit': 0,
                              'MimeType': 'text/plain',
                              'Charset': 'UTF8'}

        art = Article({'Subject': 'This Article only has Subject',
                       'Body': 'and Body and needs to be completed.'})

        self.assertIsInstance(art, Article)
        self.assertDictEqual(art.to_dct(), expected)

        art.validate()
        self.assertDictEqual(art.to_dct(), expected_validated)
Exemplo n.º 3
0
    def test_dummy_static_with_no_article_id(self):
        self.maxDiff = None
        art = Article({"Subject": "Dümmy Subject",
                       "Body": "Hallo Bjørn,\n[kt]\n\n -- The End",
                       "TimeUnit": 0,
                       "MimeType": "text/plain",
                       "Charset": "UTF8"})

        expected = {'Subject': 'Dümmy Subject',
                    'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End',
                    'TimeUnit': 0,
                    'MimeType': 'text/plain',
                    'Charset': 'UTF8'}

        self.assertDictEqual(art.to_dct(), expected)
        self.assertEqual(art.__repr__(), "<Article>")
        self.assertEqual(art.aid, 0)
Exemplo n.º 4
0
    def test_validation_custom(self):
        """Article validation; blacklisted fields should be removed, others should be added"""

        custom_validation = {"Body": "API created Article Body",
                             "Charset": "UTF8",
                             "SpecialField": "SpecialValue",
                             "MimeType": "text/plain",
                             "Subject": "API created Article",
                             "TimeUnit": 0}

        expected_validated = {'Subject': 'This Article only has Subject',
                              'Body': 'and Body and needs to be completed.',
                              'TimeUnit': 0,
                              'MimeType': 'text/plain',
                              'Charset': 'UTF8',
                              'SpecialField': 'SpecialValue'}

        art = Article({'Subject': 'This Article only has Subject',
                       'Body': 'and Body and needs to be completed.'})

        art.validate(validation_map=custom_validation)
        self.assertDictEqual(art.to_dct(), expected_validated)
Exemplo 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)>")
Exemplo n.º 6
0
    def test_article_parse_attachment_from_dct_one_attachments(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'))
        self.assertIsInstance(art.dynamic_field_get('firstname'), DynamicField)
        self.assertIsInstance(art.to_dct(), dict)