|
| 1 | +# |
| 2 | +# Copyright (C) 2007 Stefan Seefeld |
| 3 | +# All rights reserved. |
| 4 | +# For license terms see the file COPYING.txt. |
| 5 | +# |
| 6 | + |
| 7 | +from __future__ import print_function |
| 8 | +import unittest, os, shutil, errno, sys, difflib, cgi, re |
| 9 | + |
| 10 | +from roundup.admin import AdminTool |
| 11 | + |
| 12 | +from . import db_test_base |
| 13 | +from .test_mysql import skip_mysql |
| 14 | +from .test_postgresql import skip_postgresql |
| 15 | + |
| 16 | + |
| 17 | +class AdminTest(object): |
| 18 | + |
| 19 | + backend = None |
| 20 | + |
| 21 | + def setUp(self): |
| 22 | + self.dirname = '_test_admin' |
| 23 | + |
| 24 | + def tearDown(self): |
| 25 | + try: |
| 26 | + shutil.rmtree(self.dirname) |
| 27 | + except OSError as error: |
| 28 | + if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 29 | + |
| 30 | + def testInit(self): |
| 31 | + import sys |
| 32 | + self.admin=AdminTool() |
| 33 | + sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend] |
| 34 | + ret = self.admin.main() |
| 35 | + print(ret) |
| 36 | + self.assertTrue(ret == 0) |
| 37 | + self.assertTrue(os.path.isfile(self.dirname + "/config.ini")) |
| 38 | + self.assertTrue(os.path.isfile(self.dirname + "/schema.py")) |
| 39 | + |
| 40 | + def testInitWithConfig_ini(self): |
| 41 | + import sys |
| 42 | + from roundup.configuration import CoreConfig |
| 43 | + self.admin=AdminTool() |
| 44 | + sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend] |
| 45 | + # create a config_ini.ini file in classic template |
| 46 | + templates=self.admin.listTemplates() |
| 47 | + config_ini_content = "[mail]\n# comment\ndebug = SendMail.LOG\n" |
| 48 | + config_ini_path = templates['classic']['path'] + '/config_ini.ini' |
| 49 | + config_ini_file = open(config_ini_path, "w") |
| 50 | + config_ini_file.write(config_ini_content) |
| 51 | + config_ini_file.close() |
| 52 | + |
| 53 | + try: |
| 54 | + ret = self.admin.main() |
| 55 | + finally: |
| 56 | + try: |
| 57 | + # ignore file not found |
| 58 | + os.remove(config_ini_path) |
| 59 | + except OSError as e: # FileNotFound exception under py3 |
| 60 | + if e.errno == 2: |
| 61 | + pass |
| 62 | + else: |
| 63 | + raise |
| 64 | + |
| 65 | + print(ret) |
| 66 | + self.assertTrue(ret == 0) |
| 67 | + self.assertTrue(os.path.isfile(self.dirname + "/config.ini")) |
| 68 | + self.assertTrue(os.path.isfile(self.dirname + "/schema.py")) |
| 69 | + config=CoreConfig(self.dirname) |
| 70 | + self.assertEqual(config['MAIL_DEBUG'], self.dirname + "/SendMail.LOG") |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +class anydbmAdminTest(AdminTest, unittest.TestCase): |
| 75 | + backend = 'anydbm' |
| 76 | + |
| 77 | + |
| 78 | +@skip_mysql |
| 79 | +class mysqlAdminTest(AdminTest, unittest.TestCase): |
| 80 | + backend = 'mysql' |
| 81 | + |
| 82 | + |
| 83 | +class sqliteAdminTest(AdminTest, unittest.TestCase): |
| 84 | + backend = 'sqlite' |
| 85 | + |
| 86 | + |
| 87 | +@skip_postgresql |
| 88 | +class postgresqlAdminTest(AdminTest, unittest.TestCase): |
| 89 | + backend = 'postgresql' |
0 commit comments