def test_invalid_option_in_section(self): """invalid options in section should not alter the database""" panels = { 'priority': PriorityAdminPanel(self.env), 'severity': SeverityAdminPanel(self.env), 'resolution': ResolutionAdminPanel(self.env), 'ticket_type': TicketTypeAdminPanel(self.env), 'component': ComponentAdminPanel(self.env), } # create the section with invalid option and values in configuration self.env.config.set('ticket-field-config','nintendo','mario,pacman') # run our plugin admin_command = TicketFieldConfigCommand(self.env) admin_command.set_fields_from_config() # verify that invalid options in section does not alter db for name, panel in panels.items(): if name == 'component': self.assertItemsEqual( panel.get_component_list(), self.default[name] ) else: self.assertItemsEqual( panel.get_enum_list(), self.default[name] )
def test_no_options_in_section(self): """present section but missing options should not alter the database""" panels = { 'priority': PriorityAdminPanel(self.env), 'severity': SeverityAdminPanel(self.env), 'resolution': ResolutionAdminPanel(self.env), 'ticket_type': TicketTypeAdminPanel(self.env), 'component': ComponentAdminPanel(self.env), } # create the section, but no options or values in configuration self.env.config.set('ticket-field-config','','') # run our plugin admin_command = TicketFieldConfigCommand(self.env) admin_command.set_fields_from_config() # verify that present section but missing options does not alter db for name, panel in panels.items(): if name == 'component': self.assertItemsEqual( panel.get_component_list(), self.default[name] ) else: self.assertItemsEqual( panel.get_enum_list(), self.default[name] )
def test_component_set_successful(self): """ When we add custom component enum values to the config and call TicketFieldConfigCommand.set_fields_from_config() we expect the Trac environments component enums to be updated with our custom values and removal of the default values. """ # We create an instance of the panel so we can check existing values panel = ComponentAdminPanel(self.env) # Check the environment initially contains the default values. self.assertItemsEqual(panel.get_component_list(), self.default['component']) # create the section, option, and values in configuration self.env.config.set('ticket-field-config', 'component', ','.join(self.new['component'])) # create component_owner option self.env.config.set('ticket-field-config','component_owner','test') admin_command = TicketFieldConfigCommand(self.env) # run our plugin admin_command.set_fields_from_config() self.assertItemsEqual(panel.get_component_list(), self.new['component'])
def test_unconfigured_options_do_not_alter_database(self): """unconfigured options should not alter the database""" panels = { 'priority': PriorityAdminPanel(self.env), 'severity': SeverityAdminPanel(self.env), 'resolution': ResolutionAdminPanel(self.env), 'ticket_type': TicketTypeAdminPanel(self.env), 'component': ComponentAdminPanel(self.env), } # Check the environment initially contains the default values. for name, panel in panels.items(): if name == 'component': self.assertItemsEqual( panel.get_component_list(), self.default[name] ) else: self.assertItemsEqual( panel.get_enum_list(), self.default[name] ) # create the section, option, and values in configuration self.env.config.set('ticket-field-config', 'ticket_type', ','.join(self.new['ticket_type'])) # run our plugin admin_command = TicketFieldConfigCommand(self.env) admin_command.set_fields_from_config() # verify that specified configuration options altered database self.assertItemsEqual( panels['ticket_type'].get_enum_list(), self.new['ticket_type'] ) # verify that unspecified configuration options do not alter database for name, panel in panels.items(): if name == 'ticket_type': continue # skipping because we changed this on purpose if name == 'component': self.assertItemsEqual( panel.get_component_list(), self.default[name] ) else: self.assertItemsEqual( panel.get_enum_list(), self.default[name] )
def test_reorder_field_values(self): """ test that field values are reordered to match configuration """ # We create an instance of the panel so we can check existing values panel = ResolutionAdminPanel(self.env) # Check the environment initially contains the default values self.assertItemsEqual(panel.get_enum_list(), self.default['resolution']) # create the section, option, and values in configuration self.env.config.set('ticket-field-config', 'resolution', ','.join(self.new['resolution'])) admin_command = TicketFieldConfigCommand(self.env) # run our plugin admin_command.set_fields_from_config() # assert order was adjusted self.assertEqual(panel.get_enum_list(), self.new['resolution'])