forked from mugwort-rc/django-pgpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
86 lines (74 loc) · 2.53 KB
/
run_tests.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
#!/usr/bin/env python
import sys
import os
BASE_DIR = os.path.dirname(__file__)
import django
from django.conf import settings
def main():
# Dynamically configure the Django settings with the minimum necessary to
# get Django running tests.
try:
settings.configure(
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
},
],
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.sessions',
'bootstrapform',
'pgpdb',
],
# Django replaces this, but it still wants it. *shrugs*
DATABASE_ENGINE='django.db.backends.sqlite3',
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
TIME_ZONE = 'UTC',
USE_I18N = True,
USE_L10N = True,
USE_TZ = True,
MEDIA_ROOT='/tmp/django_pgpdb_test_media/',
MEDIA_PATH='/media/',
ROOT_URLCONF='pgpdb.urls',
DEBUG=True,
TEMPLATE_DEBUG=True,
)
if django.VERSION[:2] >= (1, 7):
django.setup()
apps = ['pgpdb']
from django.core.management import call_command
from django.test.utils import get_runner
try:
from django.contrib.auth import get_user_model
except ImportError:
USERNAME_FIELD = "username"
else:
USERNAME_FIELD = get_user_model().USERNAME_FIELD
DjangoTestRunner = get_runner(settings)
class TestRunner(DjangoTestRunner):
def setup_databases(self, *args, **kwargs):
result = super(TestRunner, self).setup_databases(*args, **kwargs)
kwargs = {
"interactive": False,
"email": "admin@example.com",
USERNAME_FIELD: "admin",
}
call_command("createsuperuser", **kwargs)
return result
failures = TestRunner(verbosity=2, interactive=True).run_tests(apps)
sys.exit(failures)
finally:
pass
if __name__ == '__main__':
main()