def test_save_version(self): ap = VersionAdminPanel(self.env) old_name = '2.0' new_name = '4.0 dev' version = Version(self.env, old_name) self.assertEqual(old_name, version.name) req = MockRequest(self.env, method='POST', args={ 'name': ' 1.0 ', 'save': True }) with self.assertRaises(ResourceExistsError) as cm: ap.render_admin_panel(req, 'ticket', 'version', old_name) self.assertIn('Version "1.0" already exists', unicode(cm.exception)) req = MockRequest(self.env, method='POST', args={ 'name': ' 4.0 \t dev ', 'save': True }) self.assertRaises(RequestDone, ap.render_admin_panel, req, 'ticket', 'version', old_name) self.assertIn('Your changes have been saved.', req.chrome['notices']) version = Version(self.env, new_name) self.assertEqual(new_name, version.name) self.assertRaises(ResourceNotFound, ap.render_admin_panel, req, 'ticket', 'version', old_name) self.assertRaises(ResourceNotFound, Version, self.env, old_name)
def test_add_version_with_spaces(self): name = '4.0 dev' ap = VersionAdminPanel(self.env) req = MockRequest(self.env, method='POST', args={'name': ' 4.0 \t dev ', 'add': True}) self.assertRaises(ResourceNotFound, Version, self.env, name) self.assertRaises(RequestDone, ap.render_admin_panel, req, 'ticket', 'version', None) self.assertIn('The version "4.0 dev" has been added.', req.chrome['notices']) version = Version(self.env, name) self.assertEqual(name, version.name) with self.assertRaises(ResourceExistsError) as cm: ap.render_admin_panel(req, 'ticket', 'version', None) self.assertIn('Version "4.0 dev" already exists', str(cm.exception))
def test_set_default_version(self): name = '1.0' ap = VersionAdminPanel(self.env) config_key = 'default_version' req = MockRequest(self.env, method='POST', args={'default': name, 'apply': True}) self.assertRaises(RequestDone, ap.render_admin_panel, req, 'ticket', 'version', None) self.assertEqual(name, self.env.config.get('ticket', config_key))
def test_add_version(self): name = '3.0' ap = VersionAdminPanel(self.env) req = MockRequest(self.env, method='POST', args={'name': name, 'add': True}) self.assertRaises(ResourceNotFound, Version, self.env, name) self.assertRaises(RequestDone, ap.render_admin_panel, req, 'ticket', 'version', None) version = Version(self.env, name) self.assertEqual(name, version.name)
def test_set_default_version(self): name = '1.0' ap = VersionAdminPanel(self.env) config_key = 'default_version' req = MockRequest(self.env, method='POST', args={'default': name, 'apply': True}) self.assertRaises(RequestDone, ap.render_admin_panel, req, 'ticket', 'version', 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_default_version(self): name = '1.0' ap = VersionAdminPanel(self.env) config_key = 'default_version' self.env.config.set('ticket', config_key, name) req = self._create_request(method='POST', args={ 'sel': name, 'remove': True }) self.assertRaises(RequestDone, ap.render_admin_panel, req, 'ticket', 'version', None) self.assertEqual(self.env.config.get('ticket', config_key), '')