-
Notifications
You must be signed in to change notification settings - Fork 8
/
runtests.py
executable file
·105 lines (90 loc) · 2.82 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
#!/usr/bin/env python
import subprocess
import sys
from django.conf import settings
from django.core.management import call_command
from django.test.utils import get_runner
import django
import tempfile
DEBUG = True
tmp_media = tempfile.TemporaryDirectory()
settings.configure(
DEBUG=True,
ALLOWED_HOSTS=('testserver',),
INSTALLED_APPS=( # Including django.contrib apps prevents warnings during
# tests.
'djautotask',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
),
SECRET_KEY='correct horse battery staple',
AUTOTASK_SERVER_URL='https://localhost',
AUTOTASK_CREDENTIALS={
'username': '',
'password': '',
'integration_code': '',
'rest_api_version': '',
'server_url': '',
},
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'djautotask-test.sqlite',
},
},
# Member avatar tests like to save files to disk,
# so here's a temporary place for them.
MEDIA_ROOT=tmp_media.name,
USE_TZ=True, # Prevent 'ValueError: SQLite backend does not support
# timezone-aware datetimes when USE_TZ is False.'
ROOT_URLCONF='djautotask.tests.urls',
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
},
LOGGING={
'version': 1,
'loggers': {
'djautotask': {
'level': 'ERROR'
}
}
}
)
def _setup():
"""Configure Django stuff for tests."""
django.setup()
# Set up the test DB, if necessary.
# Note that the test DB is not deleted before or after a test,
# which speeds up subsequent tests because migrations
# don't need to be run. But if you run into any funny errors,
# you may want to remove the DB file and start fresh.
# The DB file is stored in settings.DATABASES['default']['NAME'].
call_command('migrate')
# Clear out the test DB
call_command('flush', '--noinput')
def exit_on_failure(command, message=None):
if command:
sys.exit(command)
def flake8_main():
print('Running: flake8')
_call = ['flake8'] + ['.']
command = subprocess.call(_call)
print("Failed: flake8 failed." if command else "Success. flake8 passed.")
return command
def suite():
"""
Set up and return a test suite. This is used in `python setup.py test`.
"""
_setup()
runner_cls = get_runner(settings)
return runner_cls().build_suite(test_labels=None)
if __name__ == '__main__':
_setup()
call_command('test')
# To run specific tests, try something such as:
# call_command('test', 'djautotask.tests.test_commands.TestSyncAllCommand') # noqa: E501
exit_on_failure(flake8_main())