def test_update(self): ori_ticket = self.__create_ticket_wrapper() trac = self.__alter_to_trac_with_all_permissions() create_attrs = ori_ticket.get_value_map_for_ticket_creation() ticket_data = (ori_ticket.summary, ori_ticket.description, create_attrs, True) ticket_id = trac.create(*ticket_data) self.assert_equal(trac.ticket_counter, 1) upd_ticket = TicketWrapper(description='changes in description', owner='owner2') comment = 'A normal ticket update.' update_attrs = upd_ticket.get_value_map_for_update() update_data = (ticket_id, comment, update_attrs, True) # invalid connection trac = self.__alter_to_trac_with_invalid_connection(trac) self.assert_raises(ProtocolError, trac.update, *update_data) # invalid permission trac = self.__alter_to_trac_with_get_only_permission(trac) self.assert_raises(ProtocolError, trac.update, *update_data) # success trac.get_only = False return_value = trac.update(*update_data) self.assert_equal(trac.ticket_counter, 1) self.assert_equal(len(return_value), 4) self.assert_equal(return_value[0], ticket_id) self.assert_is_not_none(return_value[1]) # created time self.assert_is_not_none(return_value[2]) # changetime self.assert_not_equal(return_value[1], return_value[2]) attrs = return_value[3] for attr_name, value in attrs.iteritems(): if update_attrs.has_key(attr_name): value_map = update_attrs elif create_attrs.has_key(attr_name): value_map = create_attrs else: value = getattr(ori_ticket, attr_name) if value == '': value = None self.assert_equal(getattr(ori_ticket, attr_name), value) continue self.assert_equal(value_map[attr_name], value) get_ticket = trac.get(ticket_id) self.assert_equal(get_ticket, return_value) # invalid arguments update_data = ('123', comment, update_attrs, True) self.assert_raises(Fault, trac.update, *update_data) update_data = (None, comment, update_attrs, True) self.assert_raises(TypeError, trac.update, *update_data) update_data = (1, None, update_attrs, True) self.assert_raises(TypeError, trac.update, *update_data) update_data = (1, comment, None, True) self.assert_raises(TypeError, trac.update, *update_data) update_data = (1, comment, update_attrs.values(), True) self.assert_raises(Fault, trac.update, *update_data) update_data = (1, comment, update_attrs, None) self.assert_raises(TypeError, trac.update, *update_data)
def test_init(self): # empty ticket ticket1 = TicketWrapper() self.assert_is_none(ticket1.ticket_id) for attr_name in ATTRIBUTE_NAMES: self.assert_is_none(getattr(ticket1, attr_name)) # value setting ticket2 = TicketWrapper(**self.init_data) for attr_name, exp_value in self.init_data.iteritems(): self.assert_equal(getattr(ticket2, attr_name), exp_value)
def get_value_map_for_update(self): # Empty ticket return empty maps. ticket = TicketWrapper(ticket_id=123) value_map1 = ticket.get_value_map_for_update() self.assert_equal(len(value_map1), 0) # Otherwise the map should contain all not None value. ticket.summary = 'Test TicketWrapper' ticket.priority = PRIORITY_ATTRIBUTE_VALUES.LOW value_map2 = ticket.get_value_map_for_update() self.assert_equal(len(value_map2), 2) self.assert_equal(value_map2[SummaryAttribute.NAME], 'Test TicketWrapper') self.assert_equal(value_map2[PriorityAttribute.NAME], PRIORITY_ATTRIBUTE_VALUES.LOW)
def test_get_value_map_for_ticket_creation(self): # Priority should be replaced by a default value. self.init_data[PriorityAttribute.NAME] = None ticket = TicketWrapper(**self.init_data) value_map = ticket.get_value_map_for_ticket_creation() self.assert_false(value_map.has_key(SummaryAttribute.NAME)) self.assert_false(value_map.has_key(DescriptionAttribute.NAME)) for attr_name in ATTRIBUTE_NAMES.keys(): if attr_name == SummaryAttribute.NAME or \ attr_name == DescriptionAttribute.NAME: continue if not value_map.has_key(attr_name): self.assert_is_none(getattr(ticket, attr_name)) continue ticket.check_attribute_validity(attr_name, value_map[attr_name]) if attr_name == PriorityAttribute.NAME: self.assert_equal(value_map[attr_name], PriorityAttribute.DEFAULT_VALUE) else: self.assert_equal(getattr(ticket, attr_name), self.init_data[attr_name])
def test_create_from_trac_data(self): ticket_id = 123 time_created = datetime.now() time_changed = None del self.init_data['ticket_id'] trac_data = (ticket_id, time_created, time_changed, self.init_data) ticket = TicketWrapper.create_from_trac_data(trac_data) self.assert_equal(ticket.ticket_id, ticket_id) self.assert_equal(ticket.time, time_created) self.assert_equal(ticket.changetime, time_changed) for attr_name, exp_value in self.init_data.iteritems(): self.assert_equal(getattr(ticket, attr_name), exp_value)
def __create_ticket_wrapper(self, **kw): ticket_init_data = dict(summary='dummy test ticket', description='This is a dummy test ticket.', reporter='user1', owner='user2', cc='user3, user4', type=TYPE_ATTRIBUTE_VALUES.ENHANCEMENT, status=STATUS_ATTRIBUTE_VALUES.NEW, priority=PRIORITY_ATTRIBUTE_VALUES.LOWEST, severity=SEVERITY_ATTRIBUTE_VALUES.TRIVIAL, milestone='1024 km', component='None', keywords='dummy, ticket, tractor') for attr_name, value in kw.iteritems(): ticket_init_data[attr_name] = value return TicketWrapper(**ticket_init_data)
def test_attribute_validity(self): ticket = TicketWrapper(**self.init_data) # None for non-optional value ticket.check_attribute_validity(SummaryAttribute.NAME) ticket.summary = None self.assert_raises(ValueError, ticket.check_attribute_validity, SummaryAttribute.NAME) ticket.check_attribute_validity(SummaryAttribute.NAME, 'ticket title') # Invalid option ticket.check_attribute_validity(PriorityAttribute.NAME) ticket.priority = TestAlternativePriorityOptions.UNREGISTERED self.assert_raises(ValueError, ticket.check_attribute_validity, PriorityAttribute.NAME) ticket.check_attribute_validity(PriorityAttribute.NAME, PRIORITY_ATTRIBUTE_VALUES.LOW) # test lookup usage alt_lookup = ATTRIBUTE_OPTIONS alt_lookup[PriorityAttribute.NAME] = TestAlternativePriorityOptions alt_ticket = TicketWrapper(priority=\ TestAlternativePriorityOptions.UNREGISTERED, attribute_options_lookup=alt_lookup) alt_ticket.check_attribute_validity(PriorityAttribute.NAME)