-
Notifications
You must be signed in to change notification settings - Fork 34
/
runtests.py
93 lines (83 loc) · 2.61 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
#!/usr/bin/env python
import os
import sys
from django.conf import settings
from django.test.runner import DiscoverRunner
from django.utils.functional import empty
def setup_test_environment():
# reset settings
settings._wrapped = empty
apps = [
'django.contrib.sessions',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.messages',
'ratelimitbackend',
'tests',
]
settings_dict = {
"DATABASES": {
'default': {
'ENGINE': "django.db.backends.sqlite3",
'NAME': 'ratelimitbackend.sqlite',
},
},
"CACHES": {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
},
"ROOT_URLCONF": "tests.urls",
"MIDDLEWARE": [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'ratelimitbackend.middleware.RateLimitMiddleware',
],
"INSTALLED_APPS": apps,
"SITE_ID": 1,
"AUTHENTICATION_BACKENDS": (
'ratelimitbackend.backends.RateLimitModelBackend',
),
"LOGGING": {
'version': 1,
'handlers': {
'null': {
'class': 'logging.NullHandler',
}
},
'loggers': {
'ratelimitbackend': {
'handlers': ['null'],
},
},
},
"TEMPLATES": [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'loaders': (
'django.template.loaders.app_directories.Loader',
),
'context_processors': (
'django.contrib.auth.context_processors.auth',
),
},
}],
}
# set up settings for running tests for all apps
settings.configure(**settings_dict)
from django import setup
setup()
def runtests():
setup_test_environment()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
runner = DiscoverRunner(verbosity=1, interactive=True, failfast=False)
failures = runner.run_tests(())
sys.exit(failures)
if __name__ == '__main__':
runtests()