def test_add_component(self): cap = ComponentAdminPanel(self.env) name, owner = 'component3', 'user3' req = MockRequest(self.env, method='POST', args={ 'name': name, 'owner': owner, 'add': True }) self.assertRaises(ResourceNotFound, Component, self.env, name) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) component = Component(self.env, name) self.assertEqual(name, component.name) self.assertEqual(owner, component.owner) req = MockRequest(self.env, method='POST', args={ 'name': ' component3 ', 'owner': owner, 'add': True }) with self.assertRaises(ResourceExistsError) as cm: cap.render_admin_panel(req, 'ticket', 'component', None) self.assertIn('Component "component3" already exists', unicode(cm.exception))
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_save_component(self): cap = ComponentAdminPanel(self.env) old_name = 'component2' old_owner = 'somebody' new_name = 'comp on ent 2' new_owner = 'user2' component = Component(self.env, old_name) self.assertEqual(old_name, component.name) self.assertEqual(old_owner, component.owner) req = MockRequest(self.env, method='POST', args={'name': ' component1 ', 'owner': 'somebody', 'save': True}) with self.assertRaises(ResourceExistsError) as cm: cap.render_admin_panel(req, 'ticket', 'component', old_name) self.assertIn('Component "component1" already exists', unicode(cm.exception)) req = MockRequest(self.env, method='POST', args={'name': ' comp \t on \t ent \t 2 ', 'owner': new_owner, 'save': True}) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', old_name) self.assertIn('Your changes have been saved.', req.chrome['notices']) component = Component(self.env, new_name) self.assertEqual(new_name, component.name) self.assertEqual(new_owner, component.owner) self.assertRaises(ResourceNotFound, cap.render_admin_panel, req, 'ticket', 'component', old_name) self.assertRaises(ResourceNotFound, Component, self.env, old_name)
def test_component_without_owner_is_trac_error(self): """component_owner must be specified""" # 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'])) # we purposely forget to add component_owner to config # and run the plugin expecting a TracError admin_command = TicketFieldConfigCommand(self.env) self.assertRaises(TracError,admin_command.set_fields_from_config)
def test_add_component_with_spaces(self): cap = ComponentAdminPanel(self.env) name = 'comp on ent 4' self.assertRaises(ResourceNotFound, Component, self.env, name) req = MockRequest(self.env, method='POST', args={'name': ' comp \t on \t ent \t 4 ', 'owner': 'user4', 'add': True}) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) self.assertIn('The component "comp on ent 4" has been added.', req.chrome['notices']) component = Component(self.env, name) self.assertEqual(name, component.name) with self.assertRaises(ResourceExistsError) as cm: cap.render_admin_panel(req, 'ticket', 'component', None) self.assertIn('Component "comp on ent 4" already exists', unicode(cm.exception))
def test_set_default_component(self): name = 'component2' config_key = 'default_component' cap = ComponentAdminPanel(self.env) req = MockRequest(self.env, method='POST', args={'default': name, 'apply': True}) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) self.assertEqual(name, self.env.config.get('ticket', config_key))
def test_set_default_component(self): name = 'component2' config_key = 'default_component' cap = ComponentAdminPanel(self.env) req = MockRequest(self.env, method='POST', args={'default': name, 'apply': True}) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) self.assertIn('Your changes have been saved.', req.chrome['notices']) self.assertEqual([], req.chrome['warnings']) self.assertEqual(name, self.env.config.get('ticket', config_key))
def test_remove_component(self): cap = ComponentAdminPanel(self.env) name = 'component2' req = MockRequest(self.env, method='POST', args={'sel': name, 'remove': True}) component = Component(self.env, name) self.assertEqual(name, component.name) self.assertEqual('somebody', component.owner) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) self.assertRaises(ResourceNotFound, Component, self.env, name)
def test_add_component(self): cap = ComponentAdminPanel(self.env) name, owner = 'component3', 'user3' req = MockRequest(self.env, method='POST', args={'name': name, 'owner': owner, 'add': True}) self.assertRaises(ResourceNotFound, Component, self.env, name) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) component = Component(self.env, name) self.assertEqual(name, component.name) self.assertEqual(owner, component.owner)
def test_remove_default_component(self): name = 'component2' cap = ComponentAdminPanel(self.env) config_key = 'default_component' self.env.config.set('ticket', config_key, name) req = self._create_request(method='POST', args={ 'sel': name, 'remove': True }) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) self.assertEqual('', self.env.config.get('ticket', config_key))
def test_remove_multiple_components(self): cap = ComponentAdminPanel(self.env) names = ['component1', 'component2'] req = self._create_request(method='POST', args={ 'sel': names, 'remove': True }) for name in names: component = Component(self.env, name) self.assertEqual(name, component.name) self.assertEqual('somebody', component.owner) self.assertRaises(RequestDone, cap.render_admin_panel, req, 'ticket', 'component', None) for name in names: self.assertRaises(ResourceNotFound, Component, self.env, name)
def __init__(self, env): TracAdmin.__init__(self, env) self.env = open_environment(env) # new style, as of trac:changeset:7677 # see trac:#7770 # for now, support both use-cases if not hasattr(self, 'get_component_list'): # TODO: create these functions from trac.ticket.admin import ComponentAdminPanel from trac.ticket.admin import MilestoneAdminPanel from trac.wiki.admin import WikiAdmin self.ComponentAdminPanel = ComponentAdminPanel(self.env) self.get_component_list = self.ComponentAdminPanel.get_component_list self._do_component_remove = self.ComponentAdminPanel._do_remove self.MilestoneAdminPanel = MilestoneAdminPanel(self.env) self.get_milestone_list = self.MilestoneAdminPanel.get_milestone_list self._do_milestone_remove = self.MilestoneAdminPanel._do_remove self.WikiAdmin = WikiAdmin(self.env) self._do_wiki_load = self.WikiAdmin.load_pages