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_create_factory_method(self): summary = 'Test Ticket' description = 'Creation Factory Test.' ticket = create_wrapper_for_ticket_creation(summary, description) self.assert_is_none(ticket.ticket_id) for attr_name in ATTRIBUTE_NAMES.keys(): if attr_name == SummaryAttribute.NAME: self.assert_equal(getattr(ticket, attr_name), summary) elif attr_name == DescriptionAttribute.NAME: self.assert_equal(getattr(ticket, attr_name), description) else: self.assert_is_none(getattr(ticket, attr_name))
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_get_ticket(self): api = self.__create_api() t_wrapper = self.__create_ticket_wrapper() ticket_id = api.create_ticket(t_wrapper) get_ticket = api.get_ticket(ticket_id) self.assert_equal(get_ticket.ticket_id, ticket_id) self.assert_is_not_none(get_ticket.time) self.assert_equal(get_ticket.changetime, get_ticket.time) for attr_name, attr_cls in ATTRIBUTE_NAMES.iteritems(): ori_value = getattr(t_wrapper, attr_name) get_value = getattr(get_ticket, attr_name) if attr_name == ReporterAttribute.NAME \ or attr_name == OwnerAttribute.NAME: # are set by the trac automatically self.assert_is_not_none(get_value) elif not ori_value is None: self.assert_equal(ori_value, get_value) elif attr_cls.IS_OPTIONAL or attr_cls.DEFAULT_VALUE is None: self.assert_is_none(get_value) else: self.assert_equal(get_value, attr_cls.DEFAULT_VALUE)
def test_update_factory_method(self): ticket_id = 1 ticket = create_wrapper_for_ticket_update(ticket_id=ticket_id) self.assert_equal(ticket.ticket_id, ticket_id) for attr_name in ATTRIBUTE_NAMES.keys(): self.assert_is_none(getattr(ticket, attr_name))