Skip to content
Snippets Groups Projects
Commit 61f5789c authored by Jiří Machálek's avatar Jiří Machálek
Browse files

Merge remote-tracking branch 'github/pr/5'

- merge Stewart Perrygrove contribution with list of attachments
parents 3f4b5140 e7f9fef7
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,7 @@ class Rt:
'update_pattern': re.compile('^# Ticket [0-9]+ updated.$'),
'content_pattern': re.compile('Content:'),
'attachments_pattern': re.compile('Attachments:'),
'attachments_list_pattern': re.compile(r'[^0-9]*(\d+): ([\w().]+) \((\w+/[\w.]+) / ([0-9a-z.]+)\),?$'),
'headers_pattern': re.compile('Headers:'),
'links_updated_pattern': re.compile('^# Links for ticket [0-9]+ updated.$'),
'created_link_pattern': re.compile('.* Created link '),
......@@ -725,22 +726,37 @@ Text: %s""" % (str(ticket_id), re.sub(r'\n', r'\n ', text))}
return self.__get_status_code(msg) == 200
def get_attachments_ids(self, ticket_id):
""" Get IDs of attachments for given ticket.
def get_attachments(self, ticket_id):
""" Get attachment list for a given ticket
:param ticket_id: ID of ticket
:returns: List of IDs (type int) of attachments belonging to given
ticket
:returns: List of tuples for attachments belonging to given ticket.
Tuple format: (id, name, content_type, size)
"""
at = self.__request('ticket/%s/attachments' % (str(ticket_id),))
if (len(at) != 0) and (self.__get_status_code(at) == 200):
atlines = at.split('\n')
attachment_infos = []
if len(atlines) >= 4:
return [int(re.sub(r'[^0-9]*([0-9]+):.*', r'\1', line)) for line in atlines[4:] if len(line) > 0]
for line in atlines[4:]:
if len(line) > 0:
info = self.RE_PATTERNS['attachments_list_pattern'].match(line).groups()
if info:
attachment_infos.append(info)
return attachment_infos
else:
return []
else:
return []
def get_attachments_ids(self, ticket_id):
""" Get IDs of attachments for given ticket.
:param ticket_id: ID of ticket
:returns: List of IDs (type int) of attachments belonging to given
ticket
"""
return [int(att[0]) for att in self.get_attachments(ticket_id)]
def get_attachment(self, ticket_id, attachment_id):
""" Get attachment.
......
......@@ -143,6 +143,10 @@ class RtTestCase(unittest.TestCase):
self.assertTrue(at_ids, 'Emply list with attachment ids, something went wrong.')
at_content = tracker.get_attachment_content(ticket_id, at_ids[-1])
self.assertEqual(at_content, attachment_content, 'Recorded attachment is not equal to the original file.')
# attachments list
at_list = tracker.get_attachments(ticket_id)
at_names = [at[1] for at in at_list]
self.assertTrue(attachment_name in at_names, 'Attachment name is not in the list of attachments.')
# merge tickets
self.assertTrue(tracker.merge_ticket(ticket2_id, ticket_id), 'Merging tickets failed.')
# delete ticket
......
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