-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathruntests.py
More file actions
76 lines (56 loc) · 2.5 KB
/
runtests.py
File metadata and controls
76 lines (56 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
from collections import namedtuple
import sys, os
from optparse import OptionParser, make_option
from django.conf import settings
# the table need to have the unaccent sql function available
# The user must have the right to create a table
DbConnectionInfo = namedtuple('DbConnectionInfo', ['name', 'user', 'password', 'host'])
default_db_connection_info = DbConnectionInfo(
name='django_unaccent_db',
user='django_unaccent_user',
password='',
host='',
)
def get_minimal_django_settings(db_info=default_db_connection_info):
return dict(
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.contenttypes',
],
DATABASES={
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': db_info.name,
'USER': db_info.user,
'PASSWORD': db_info.password,
'HOST': db_info.host,
}
},
)
def set_settings_and_runtests(db_connection_info, verbosity=1, interactive=False, failfast=False):
if not settings.configured:
settings.configure(**get_minimal_django_settings(db_connection_info))
### Importing DjangoTestSuiteRunner makes Django fails with an import error on 'signals' ###
### The real reason is that the settings, found or not, are not initialized ###
from runtests_with_settings import runtests
return_code = runtests()
sys.exit(return_code)
if __name__ == '__main__':
opt_db_info = default_db_connection_info
opt_list = [
# Database settings
make_option('-d', '--database', default=opt_db_info.name,
help='The database to use for testing django-unaccent. Must have the unaccent SQL function available'),
make_option('-u', '--user', default=opt_db_info.user,
help='Django test user to connect to the database, must have creation of database right.'),
make_option('-p', '--password', default=opt_db_info.password,
help='password, if any, to connect to the database'),
make_option('-H', '--host', default=opt_db_info.host, help=''),
# Add test settings ?
# parser.add_option('--failfast', action='store_true', default=False, dest='failfast')
]
parser = OptionParser(option_list=opt_list)
options, _ = parser.parse_args()
db_info = DbConnectionInfo(options.database, options.user, options.password, options.host)
set_settings_and_runtests(db_info)