-
Notifications
You must be signed in to change notification settings - Fork 8
/
app_test_runner.py
executable file
·77 lines (65 loc) · 2.6 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
#!/usr/bin/env python
import os
import sys
from optparse import OptionParser
from django.conf import settings
from django.core.management import call_command
def main():
"""
The entry point for the script. This script is fairly basic. Here is a
quick example of how to use it::
app_test_runner.py [path-to-app]
You must have Django on the PYTHONPATH prior to running this script. This
script basically will bootstrap a Django environment for you.
By default this script with use SQLite and an in-memory database. If you
are using Python 2.5 it will just work out of the box for you.
TODO: show more options here.
"""
parser = OptionParser()
parser.add_option("--DATABASE_ENGINE", dest="DATABASE_ENGINE", default="sqlite3")
parser.add_option("--DATABASE_NAME", dest="DATABASE_NAME", default="")
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)
options, args = parser.parse_args()
# check for app in args
try:
app_path = args[0]
except IndexError:
print "You did not provide an app path."
raise SystemExit
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(**{
"DATABASE_ENGINE": options.DATABASE_ENGINE,
"DATABASE_NAME": options.DATABASE_NAME,
"DATABASE_USER": options.DATABASE_USER,
"DATABASE_PASSWORD": options.DATABASE_PASSWORD,
"SITE_ID": options.SITE_ID,
"ROOT_URLCONF": "",
"TEMPLATE_LOADERS": (
"django.template.loaders.filesystem.load_template_source",
"django.template.loaders.app_directories.load_template_source",
),
"TEMPLATE_DIRS": (
os.path.join(os.path.dirname(__file__), "templates"),
),
"INSTALLED_APPS": (
# HACK: the admin app should *not* be required. Need to spend some
# time looking into this. Django #8523 has a patch for this issue,
# but was wrongly attached to that ticket. It should have its own
# ticket.
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
app_name,
),
})
call_command("test")
if __name__ == "__main__":
main()