-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_test_runner.py
97 lines (84 loc) · 3.01 KB
/
app_test_runner.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import os
import sys
from optparse import OptionParser
from django.conf import settings
from django.core.management import call_command
import django
APP = 'django_js_utils'
TEST_APP = 'test_project'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(os.path.dirname(__file__), "templates"),
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]
},
},
]
def main():
parser = OptionParser()
parser.add_option("--DATABASE_ENGINE", dest="DATABASE_ENGINE", default="sqlite3")
parser.add_option("--DATABASE_NAME", dest="DATABASE_NAME", default="sqlite.db")
parser.add_option("--DATABASE_USER", dest="DATABASE_USER", default="")
parser.add_option("--DATABASE_PASSWORD", dest="DATABASE_PASSWORD", default="")
parser.add_option("--SITE_ID", dest="SITE_ID", type="int", default=1)
parser.add_option("--cmd", dest="cmd", default="test")
parser.add_option("--cmdargs", dest="cmdargs", default="")
options, args = parser.parse_args()
if options.cmdargs:
args += options.cmdargs.split(',')
try:
app_path = args[0]
except IndexError:
raise SystemExit("Usage: app_test_runner.py [path-to-app] [app-test-case]")
else:
if app_path.endswith("/"):
app_path = app_path[:-1]
parent_dir, app_name = os.path.split(app_path)
sys.path.insert(0, parent_dir)
settings.configure(**{
"DATABASES": {
'default': {
"ENGINE": 'django.db.backends.%s' % options.DATABASE_ENGINE,
"NAME": options.DATABASE_NAME,
"USER": options.DATABASE_USER,
"PASSWORD": options.DATABASE_PASSWORD,
}
},
"DEBUG": True,
"ALLOWED_HOSTS": ['*'],
"USE_TZ": True,
"SITE_ID": options.SITE_ID,
"ROOT_URLCONF": "{0}.urls".format(TEST_APP),
"TEMPLATES": TEMPLATES,
"INSTALLED_APPS": (
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
APP,
TEST_APP,
),
"MIDDLEWARE_CLASSES": (),
})
if django.get_version() >= '1.7':
django.setup()
call_command(options.cmd, *args[1:])
if __name__ == "__main__":
main()