comparison pylons_app/lib/db_manage.py @ 535:fefffd6fd5f4 celery

Added some more tests, rewrite testing schema, to autogenerate fresh db, new index. cleaned up some codes that involves testing.
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 21 Sep 2010 01:08:01 +0200
parents ac559565c6b8
children 53aa1ee1af86
comparison
equal deleted inserted replaced
534:74b9bed279ae 535:fefffd6fd5f4
41 import logging 41 import logging
42 42
43 log = logging.getLogger(__name__) 43 log = logging.getLogger(__name__)
44 44
45 class DbManage(object): 45 class DbManage(object):
46 def __init__(self, log_sql, dbname,tests=False): 46 def __init__(self, log_sql, dbname, tests=False):
47 self.dbname = dbname 47 self.dbname = dbname
48 self.tests = tests 48 self.tests = tests
49 dburi = 'sqlite:////%s' % jn(ROOT, self.dbname) 49 dburi = 'sqlite:////%s' % jn(ROOT, self.dbname)
50 engine = create_engine(dburi, echo=log_sql) 50 engine = create_engine(dburi, echo=log_sql)
51 init_model(engine) 51 init_model(engine)
66 """ 66 """
67 self.check_for_db(override) 67 self.check_for_db(override)
68 if override: 68 if override:
69 log.info("database exisist and it's going to be destroyed") 69 log.info("database exisist and it's going to be destroyed")
70 if self.tests: 70 if self.tests:
71 destroy=True 71 destroy = True
72 else: 72 else:
73 destroy = ask_ok('Are you sure to destroy old database ? [y/n]') 73 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
74 if not destroy: 74 if not destroy:
75 sys.exit() 75 sys.exit()
76 if self.db_exists and destroy: 76 if self.db_exists and destroy:
82 def admin_prompt(self): 82 def admin_prompt(self):
83 if not self.tests: 83 if not self.tests:
84 import getpass 84 import getpass
85 username = raw_input('Specify admin username:') 85 username = raw_input('Specify admin username:')
86 password = getpass.getpass('Specify admin password:') 86 password = getpass.getpass('Specify admin password:')
87 self.create_user(username, password, True) 87 email = raw_input('Specify admin email:')
88 self.create_user(username, password, email, True)
88 else: 89 else:
89 log.info('creating admin and regular test users') 90 log.info('creating admin and regular test users')
90 self.create_user('test_admin', 'test', True) 91 self.create_user('test_admin', 'test', 'test_admin@mail.com', True)
91 self.create_user('test_regular', 'test', False) 92 self.create_user('test_regular', 'test', 'test_regular@mail.com', False)
93 self.create_user('test_regular2', 'test', 'test_regular2@mail.com', False)
92 94
93 95
94 96
95 def config_prompt(self,test_repo_path=''): 97 def config_prompt(self, test_repo_path=''):
96 log.info('Setting up repositories config') 98 log.info('Setting up repositories config')
97 99
98 if not self.tests and not test_repo_path: 100 if not self.tests and not test_repo_path:
99 path = raw_input('Specify valid full path to your repositories' 101 path = raw_input('Specify valid full path to your repositories'
100 ' you can change this later in application settings:') 102 ' you can change this later in application settings:')
101 else: 103 else:
102 path = test_repo_path 104 path = test_repo_path
103 105
104 if not os.path.isdir(path): 106 if not os.path.isdir(path):
105 log.error('You entered wrong path: %s',path) 107 log.error('You entered wrong path: %s', path)
106 sys.exit() 108 sys.exit()
107 109
108 hooks1 = HgAppUi() 110 hooks1 = HgAppUi()
109 hooks1.ui_section = 'hooks' 111 hooks1.ui_section = 'hooks'
110 hooks1.ui_key = 'changegroup.update' 112 hooks1.ui_key = 'changegroup.update'
164 except: 166 except:
165 self.sa.rollback() 167 self.sa.rollback()
166 raise 168 raise
167 log.info('created ui config') 169 log.info('created ui config')
168 170
169 def create_user(self, username, password, admin=False): 171 def create_user(self, username, password, email='', admin=False):
170 log.info('creating administrator user %s', username) 172 log.info('creating administrator user %s', username)
171 new_user = User() 173 new_user = User()
172 new_user.username = username 174 new_user.username = username
173 new_user.password = get_crypt_password(password) 175 new_user.password = get_crypt_password(password)
174 new_user.name = 'Hg' 176 new_user.name = 'Hg'
175 new_user.lastname = 'Admin' 177 new_user.lastname = 'Admin'
176 new_user.email = 'admin@localhost.com' 178 new_user.email = email
177 new_user.admin = admin 179 new_user.admin = admin
178 new_user.active = True 180 new_user.active = True
179 181
180 try: 182 try:
181 self.sa.add(new_user) 183 self.sa.add(new_user)