forked from django-guardian/django-guardian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
56 lines (46 loc) · 1.48 KB
/
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
"""
Unit tests runner for ``django-guardian`` based on boundled example project.
Tests are independent from this example application but setuptools need
instructions how to interpret ``test`` command when we run::
python setup.py test
"""
import os
import sys
import django
os.environ["DJANGO_SETTINGS_MODULE"] = 'guardian.testsettings'
from guardian import testsettings as settings
settings.INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.sites',
'guardian',
'guardian.testapp',
)
settings.PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
)
def run_tests(settings):
from django.test.utils import get_runner
from utils import show_settings
show_settings(settings, 'tests')
import django
if hasattr(django, 'setup'):
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner(interactive=False)
# As we use different TestRunners for django < 1.8 and >= 1.8
# the arguments run_tests differs
if django.VERSION < (1, 8):
failures = test_runner.run_tests(['auth', 'guardian', 'testapp'])
else:
failures = test_runner.run_tests([
'django.contrib.auth', 'guardian', 'guardian.testapp'])
return failures
def main():
failures = run_tests(settings)
sys.exit(failures)
if __name__ == '__main__':
main()