class AdminTest(object): backend = None def setUp(self): self.dirname = '_test_admin' def tearDown(self): try: shutil.rmtree(self.dirname) except OSError as error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise def testInit(self): import sys self.admin = AdminTool() sys.argv = [ 'main', '-i', '_test_admin', 'install', 'classic', self.backend ] ret = self.admin.main() print(ret) self.assertTrue(ret == 0) self.assertTrue(os.path.isfile(self.dirname + "/config.ini")) self.assertTrue(os.path.isfile(self.dirname + "/schema.py")) def testInitWithConfig_ini(self): import sys from roundup.configuration import CoreConfig self.admin = AdminTool() sys.argv = [ 'main', '-i', '_test_admin', 'install', 'classic', self.backend ] # create a config_ini.ini file in classic template templates = self.admin.listTemplates() config_ini_content = "[mail]\n# comment\ndebug = SendMail.LOG\n" config_ini_path = templates['classic']['path'] + '/config_ini.ini' config_ini_file = open(config_ini_path, "w") config_ini_file.write(config_ini_content) config_ini_file.close() try: ret = self.admin.main() finally: try: # ignore file not found os.remove(config_ini_path) except OSError as e: # FileNotFound exception under py3 if e.errno == 2: pass else: raise print(ret) self.assertTrue(ret == 0) self.assertTrue(os.path.isfile(self.dirname + "/config.ini")) self.assertTrue(os.path.isfile(self.dirname + "/schema.py")) config = CoreConfig(self.dirname) self.assertEqual(config['MAIL_DEBUG'], self.dirname + "/SendMail.LOG")
def run(): # time out after a minute if we can import socket if hasattr(socket, 'setdefaulttimeout'): socket.setdefaulttimeout(60) tool = AdminTool() sys.exit(tool.main())
def testConfigValueInterpolateError(self): ''' error is not raised using ConfigParser under Python 2. Unknown cause, so skip it if running python 2. ''' self.munge_configini(mods=[("admin_email = ", "a bare % is invalid")]) config = configuration.CoreConfig() # load config generates: ''' E roundup.configuration.ParsingOptionError: Error in _test_instance/config.ini with section [main] at option admin_email: '%' must be followed by '%' or '(', found: '% is invalid' ''' with self.assertRaises(configuration.ParsingOptionError) as cm: config.load(self.dirname) print(cm.exception) self.assertIn( "'%' must be followed by '%' or '(', found: '% is invalid'", cm.exception.args[0]) self.assertIn( "_test_instance/config.ini with section [main] at option admin_email", cm.exception.args[0]) from roundup.admin import AdminTool from .test_admin import captured_output admin = AdminTool() with captured_output() as (out, err): sys.argv = ['main', '-i', self.dirname, 'get', 'tile', 'issue1'] ret = admin.main() expected_err = "Error in _test_instance/config.ini with section [main] at option admin_email: '%' must be followed by '%' or '(', found: '% is invalid'" self.assertEqual(ret, 1) out = out.getvalue().strip() self.assertEqual(out, expected_err)
import sys # python version check from roundup import version_check # import the admin tool guts and make it go from roundup.admin import AdminTool from roundup.i18n import _ if __name__ == "__main__": tool = AdminTool() sys.exit(tool.main())