def test_add_attachment(self): ticket = DummyTicket(**self.init_data) self.assert_equal(len(ticket.comments), 0) att = self.__create_dummy_attachment() ticket.add_attachment(att, replace_existing=True) self.assert_equal(len(ticket.comments), 1) self.assert_equal(ticket.comments[0], att.description)
def test_get_attachment(self): ticket = DummyTicket(**self.init_data) att = self.__create_dummy_attachment() ticket.add_attachment(att, replace_existing=True) att_fn = att.file_name ticket_att = ticket.get_attachment(att_fn) self.assert_equal(ticket_att.file_name, att_fn) self.assert_equal(ticket_att.content, 'dummy_attachment_test') self.assert_is_none(ticket.get_attachment('other file'))
def test_get_trac_data_tuple(self): ticket = DummyTicket(**self.init_data) exp_attr = dict() for attr_name in ATTRIBUTE_NAMES.keys(): value = getattr(ticket, attr_name) if value is None: value = '' exp_attr[attr_name] = value exp_data = (123, ticket.time, ticket.changetime, exp_attr) self.assert_equal(ticket.get_trac_data_tuple(), exp_data)
def test_init(self): ticket = DummyTicket(**self.init_data) self.assert_is_not_none(ticket.time) self.assert_equal(ticket.changetime, ticket.time) self.assert_equal(len(ticket.comments), 0) for attr_name, exp_val in self.init_data.iteritems(): self.assert_equal(getattr(ticket, attr_name), exp_val)
def test_get_all_attachments(self): ticket = DummyTicket(**self.init_data) list1 = ticket.get_all_attachments() self.assert_equal(len(list1), 0) att1 = self.__create_dummy_attachment(file_name='file1.txt') ticket.add_attachment(att1, replace_existing=False) att2 = self.__create_dummy_attachment(file_name='file2.txt') ticket.add_attachment(att2, replace_existing=False) exp_list = [att1.get_trac_data_tuple(), att2.get_trac_data_tuple()] list2 = ticket.get_all_attachments() self.assert_equal(list2, exp_list)
def test_add_attachment_replacing(self): ticket = DummyTicket(**self.init_data) file_name = 'test_file.txt' att1 = self.__create_dummy_attachment(file_name=file_name) ticket.add_attachment(att1, replace_existing=True) list1 = ticket.get_all_attachments() self.assert_equal(len(list1), 1) att2 = self.__create_dummy_attachment(content='different content', file_name=file_name) ticket.add_attachment(att2, replace_existing=True) list2 = ticket.get_all_attachments() self.assert_equal(len(list2), 1) ticket_att1 = ticket.get_attachment(file_name) self.assert_not_equal(ticket_att1.content, att1.content) self.assert_equal(ticket_att1.content, att2.content) att3 = self.__create_dummy_attachment(content='content version 3', file_name=file_name) ticket.add_attachment(att3, replace_existing=False) list3 = ticket.get_all_attachments() self.assert_equal(len(list3), 2) ticket_att2 = ticket.get_attachment(file_name) self.assert_equal(ticket_att2.content, att2.content) self.assert_not_equal(ticket_att2.content, att3.content) new_name = '%s.2' % (file_name) self.assert_is_not_none(ticket.get_attachment(new_name))