Skip to content
Snippets Groups Projects
Commit a9cfafe1 authored by Robert Habermann's avatar Robert Habermann
Browse files

fix Article implementation and tests for TicketUpdate

parent 40ddff9f
No related branches found
No related tags found
No related merge requests found
......@@ -185,6 +185,11 @@ class Article(object):
if not self.__dict__.get(key, None):
dct.update({key: value})
# TODO 2016-04-24 (RH): Check this
# Article does not contain DynamicField or Attachment on TicketCreate and TicketUpdate!
del dct['list_dynamic_fields']
del dct['list_attachments']
self.__dict__ = dct
......@@ -1068,8 +1073,9 @@ class Client(object):
Args:
ticket_id (int):
article (Article):
attachment_list (list): *Attachment* objects
article (Article): **optional** one *Article* that will be add to the ticket
attachment_list (list): list of one or more *Attachment* objects that will
be added to ticket. Also requires an *Article*!
dynamic_field_list (list): *DynamicField* objects
**kwargs: any regular OTRS Fields (not for Dynamic Fields!)
......
......@@ -32,7 +32,9 @@ class ArticleTests(unittest.TestCase):
'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End',
'TimeUnit': 0,
'MimeType': 'text/plain',
'Charset': 'UTF8'}}
'Charset': 'UTF8',
'list_attachments': [],
'list_dynamic_fields': []}}
art = Article._dummy()
self.assertDictEqual(art.to_dct(), expected)
......@@ -43,14 +45,19 @@ class ArticleTests(unittest.TestCase):
'TimeUnit': 0,
'MimeType': 'text/plain',
'Charset': 'UTF8',
"ForceNotificationToUserID": [1, 2]}}
"ForceNotificationToUserID": [1, 2],
'list_attachments': [],
'list_dynamic_fields': []}}
art = Article._dummy_force_notify()
self.assertDictEqual(art.to_dct(), expected)
def test_validation(self):
"""Article validation; blacklisted fields should be removed, others should be added"""
expected = {'Article': {'Subject': 'This Article only has Subject',
'Body': 'and Body and needs to be completed.'}}
'Body': 'and Body and needs to be completed.',
'list_attachments': [],
'list_dynamic_fields': []}}
expected_validated = {'Article': {'Subject': 'This Article only has Subject',
'Body': 'and Body and needs to be completed.',
......
......@@ -19,15 +19,17 @@ from pyotrs import Attachment # noqa
class AttachmentTests(unittest.TestCase):
def test_init(self):
att = Attachment()
att = Attachment({'Content': 'YmFyCg==',
'ContentType': 'text/plain',
'Filename': 'dümmy.txt'})
self.assertIsInstance(att, Attachment)
def test_attachment_file(self):
att = Attachment("mFyCg==", "text/plain", "foo.txt")
att = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt")
self.assertIsInstance(att, Attachment)
def test_attachment_dummy_static(self):
att = Attachment("YmFyCg==", "text/plain", "dümmy.txt")
att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
self.assertIsInstance(att, Attachment)
self.assertEqual(att.__repr__(), '<Attachment: dümmy.txt>')
......@@ -37,14 +39,14 @@ class AttachmentTests(unittest.TestCase):
self.assertEqual(att.__repr__(), '<Attachment: dümmy.txt>')
def test_dummy_static_dct(self):
att = Attachment("YmFyCg==", "text/plain", "dümmy.txt")
att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
self.assertDictEqual(att.to_dct(),
{'Content': 'YmFyCg==',
'ContentType': 'text/plain',
'Filename': 'dümmy.txt'})
def test_dummy_static_dct_unicode(self):
att = Attachment("YmFyCg==", "text/plain", "dümmy.txt")
att = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
self.assertDictEqual(att.to_dct(),
{'Content': 'YmFyCg==',
'ContentType': 'text/plain',
......
......@@ -439,8 +439,8 @@ class ClientTests(unittest.TestCase):
"""Test ticket_create - mocked attachment result """
obj = Client(baseurl="http://fqdn",
webservicename="GenericTicketConnectorREST")
att1 = Attachment("mFyCg==", "text/plain", "foo.txt")
att2 = Attachment("YmFyCg==", "text/plain", "dümmy.txt")
att1 = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt")
att2 = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
obj.session_id_store.value = "some_session_id"
tic = Ticket(dct={'Title': 'foo'})
art = Article({'Subject': 'mySubject',
......@@ -568,8 +568,9 @@ class ClientTests(unittest.TestCase):
obj = Client(baseurl="http://fqdn", webservicename="GenericTicketConnectorREST")
mock_ticket_update_json.return_value = False
att1 = Attachment("mFyCg==", "text/plain", "foo.txt")
att2 = Attachment("YmFyCg==", "text/plain", "dümmy.txt")
att1 = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt")
att2 = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
att2 = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
self.assertRaisesRegex(TicketError,
'To create an attachment an article is needed!',
......@@ -602,8 +603,8 @@ class ClientTests(unittest.TestCase):
'MimeType': 'text/plain',
'Charset': 'UTF8'})
att1 = Attachment("mFyCg==", "text/plain", "foo.txt")
att2 = Attachment("YmFyCg==", "text/plain", "dümmy.txt")
att1 = Attachment.create_basic("mFyCg==", "text/plain", "foo.txt")
att2 = Attachment.create_basic("YmFyCg==", "text/plain", "dümmy.txt")
mock_ticket_update_json.return_value = False
result = obj.ticket_update(8, article=art, attachment_list=[att1, att2])
......
......@@ -147,7 +147,9 @@ class TicketTests(unittest.TestCase):
'QueueID': '1',
'State': 'open',
'PriorityID': '5',
'CustomerUser': 'root@localhost'}})
'CustomerUser': 'root@localhost',
'list_articles': [],
'list_dynamic_field': []}})
def test_pending_text(self):
tic = Ticket.create_basic(Title='foobar',
......@@ -170,7 +172,9 @@ class TicketTests(unittest.TestCase):
'State': u'open',
'Priority': u'3 normal',
'CustomerUser': 'root@localhost',
'Title': 'Bäsic Ticket'}})
'Title': 'Bäsic Ticket',
'list_articles': [],
'list_dynamic_field': []}})
def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment