forked from rafalp/Misago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·133 lines (101 loc) · 3.2 KB
/
runtests.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import pwd
import shutil
import sys
from django import setup
from django.test.utils import setup_test_environment
def runtests():
args, kwargs = parse_args()
setup_testproject()
run_django(*args, **kwargs)
def parse_args():
args = []
kwargs = {
'verbosity': 1,
'noinput': True,
}
sys_argv = sys.argv[1:]
if sys_argv and sys_argv[0] == 'test':
sys_argv = sys_argv[1:]
for arg in sys_argv:
if arg == '--verbose':
kwargs['verbosity'] = 2
else:
args.append(arg)
return args, kwargs
def setup_testproject():
test_runner_path = os.path.dirname(os.path.abspath(__file__))
project_template_path = os.path.join(test_runner_path, 'misago/project_template')
project_package_path = os.path.join(test_runner_path, 'misago/project_template/project_name')
test_project_path = os.path.join(test_runner_path, "testproject")
if os.path.exists(test_project_path):
shutil.rmtree(test_project_path)
shutil.copytree(project_template_path, test_project_path)
module_init_path = os.path.join(test_project_path, '__init__.py')
with open(module_init_path, "w") as py_file:
py_file.write('')
settings_path = os.path.join(
test_project_path, 'project_name', 'settings.py')
with open(settings_path, "r") as py_file:
settings_file = py_file.read()
# Do some configuration magic
settings_file = settings_file.replace('{{ project_name }}', 'testproject.project_name')
settings_file = settings_file.replace('{{ secret_key }}', 't3stpr0j3ct')
settings_file += """
# disable account validation via Stop Forum Spam
MISAGO_NEW_REGISTRATIONS_VALIDATORS = (
'misago.users.validators.validate_gmail_email',
)
# store mails in memory
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
# use in-memory cache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'uniqu3-sn0wf14k3'
}
}
# Use MD5 password hashing to speed up test suite
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
)
# Use english search config
MISAGO_SEARCH_CONFIG = 'english'
"""
if os.environ.get('TRAVIS'):
settings_file += """
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'travis_ci_test',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '',
}
}
TEST_NAME = 'travis_ci_test'
"""
else:
settings_file += """
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'misago_test',
'USER': '%s',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
""" % pwd.getpwuid(os.getuid())[0]
with open(settings_path, "w") as py_file:
py_file.write(settings_file)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.project_name.settings")
def run_django(*args, **kwargs):
setup()
setup_test_environment()
from django.core.management import call_command
sys.exit(call_command('test', *args, **kwargs))
if __name__ == '__main__':
runtests()