From a3db514d4556eedfdb6b1ef371719a29380f9462 Mon Sep 17 00:00:00 2001 From: Robert Habermann <mail@rhab.de> Date: Sun, 24 Apr 2016 22:51:04 +0200 Subject: [PATCH] extend tests --- README.md | 5 ++-- pyotrs/lib.py | 4 --- tests/test_article.py | 11 +++++--- tests/test_attachment.py | 22 ++++++++++------ tests/test_ticket.py | 54 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5547f53..e47b6ee 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,13 @@ u'Welcome to OTRS!' >>> my_article = Article({"Subject": "Subj", "Body": "New Body"}) >>> client.ticket_update(1, article=my_article) True + >>> client.ticket_get_by_id(1, articles=1, attachments=1) # include Articles and Attachments >>> my_ticket = client.list_ticket_get_results[0] ->>> my_ticket -<Ticket: 1> + >>> my_ticket.list_articles [<ArticleID: 3>, <ArticleID: 3> + >>> my_ticket.list_dynamic_field [<DynamicField: ProcessManagementActivityID: None>, <DynamicField: ProcessManagementProcessID: None>] ``` diff --git a/pyotrs/lib.py b/pyotrs/lib.py index 5bb6bf5..fa79864 100644 --- a/pyotrs/lib.py +++ b/pyotrs/lib.py @@ -217,10 +217,6 @@ class Attachment(object): @classmethod def create_basic(cls, Content=None, ContentType=None, Filename=None): - cls.Content = Content # base64 encoded - cls.ContentType = ContentType - cls.Filename = Filename - return Attachment({'Content': Content, 'ContentType': ContentType, 'Filename': Filename}) diff --git a/tests/test_article.py b/tests/test_article.py index 7553ab2..dcb1286 100644 --- a/tests/test_article.py +++ b/tests/test_article.py @@ -54,14 +54,14 @@ class ArticleTests(unittest.TestCase): def test_dummy_static_with_article_id(self): art = Article({"Subject": "Dümmy Subject", "Body": "Hallo Bjørn,\n[kt]\n\n -- The End", - "ArticleID": 3, + "ArticleID": 5, "TimeUnit": 0, "MimeType": "text/plain", "Charset": "UTF8"}) expected = {'Article': {'Subject': 'Dümmy Subject', 'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End', - 'ArticleID': 3, + 'ArticleID': 5, 'TimeUnit': 0, 'MimeType': 'text/plain', 'Charset': 'UTF8', @@ -69,6 +69,7 @@ class ArticleTests(unittest.TestCase): 'list_dynamic_fields': []}} self.assertDictEqual(art.to_dct(), expected) + self.assertEqual(art.__repr__(), "<ArticleID: 5>") def test_dummy_static_with_article_id_one_att(self): att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt") @@ -91,13 +92,14 @@ class ArticleTests(unittest.TestCase): 'list_dynamic_fields': []}} self.assertDictEqual(art.to_dct(), expected) + self.assertEqual(art.__repr__(), "<ArticleID: 3 (1 Attachment)>") def test_dummy_static_with_article_id_two_att(self): 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": 3, + "ArticleID": 4, "TimeUnit": 0, "MimeType": "text/plain", "Charset": "UTF8"}) @@ -106,7 +108,7 @@ class ArticleTests(unittest.TestCase): expected = {'Article': {'Subject': 'Dümmy Subject', 'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End', - 'ArticleID': 3, + 'ArticleID': 4, 'TimeUnit': 0, 'MimeType': 'text/plain', 'Charset': 'UTF8', @@ -114,6 +116,7 @@ class ArticleTests(unittest.TestCase): 'list_dynamic_fields': []}} self.assertDictEqual(art.to_dct(), expected) + self.assertEqual(art.__repr__(), "<ArticleID: 4 (2 Attachments)>") def test_article_parse_attachement_from_dct_one_attachments(self): art_dct = { diff --git a/tests/test_attachment.py b/tests/test_attachment.py index 27219c3..ad4c4c4 100644 --- a/tests/test_attachment.py +++ b/tests/test_attachment.py @@ -18,20 +18,26 @@ from pyotrs import Attachment # noqa class AttachmentTests(unittest.TestCase): - def test_init(self): + def test_init_static(self): att = Attachment({'Content': 'YmFyCg==', 'ContentType': 'text/plain', - 'Filename': 'dümmy.txt'}) + 'Filename': 'dümmy1.txt'}) self.assertIsInstance(att, Attachment) + def test_init_no_file(self): + att = Attachment({'Content': 'YnFyCg==', + 'ContentType': 'text/plain'}) + self.assertIsInstance(att, Attachment) + self.assertEqual(att.__repr__(), '<Attachment>') + def test_attachment_file(self): att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt") self.assertIsInstance(att, Attachment) def test_attachment_dummy_static(self): - att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt") + att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy2.txt") self.assertIsInstance(att, Attachment) - self.assertEqual(att.__repr__(), '<Attachment: dümmy.txt>') + self.assertEqual(att.__repr__(), '<Attachment: dümmy2.txt>') def test_attachment_dummy(self): att = Attachment._dummy() @@ -39,18 +45,18 @@ class AttachmentTests(unittest.TestCase): self.assertEqual(att.__repr__(), '<Attachment: dümmy.txt>') def test_dummy_static_dct(self): - att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt") + att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy4.txt") self.assertDictEqual(att.to_dct(), {'Content': 'YmFyCg==', 'ContentType': 'text/plain', - 'Filename': 'dümmy.txt'}) + 'Filename': 'dümmy4.txt'}) def test_dummy_static_dct_unicode(self): - att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt") + att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy5.txt") self.assertDictEqual(att.to_dct(), {'Content': 'YmFyCg==', 'ContentType': 'text/plain', - 'Filename': 'd\xfcmmy.txt'}) + 'Filename': 'd\xfcmmy5.txt'}) def main(): diff --git a/tests/test_ticket.py b/tests/test_ticket.py index 4536ce0..48c2613 100644 --- a/tests/test_ticket.py +++ b/tests/test_ticket.py @@ -32,6 +32,60 @@ class TicketTests(unittest.TestCase): self.assertIsInstance(tic, Ticket) self.assertEqual(tic.__repr__(), '<Ticket>') + def test_init_parse_from_dct(self): + tic_dct = { + 'TypeID': '1', + 'Title': 'Baesic Ticket', + 'Article': [{ + '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' + }] + } + + tic = Ticket(tic_dct) + self.assertIsInstance(tic, Ticket) + self.assertEqual(tic.__repr__(), '<Ticket>') + self.assertEqual(tic.list_articles[0].__repr__(), "<ArticleID: 30 (1 Attachment)>") + def test_create_basic_no_title(self): self.assertRaisesRegex(ValueError, 'Title is required', Ticket.create_basic) -- GitLab