forked from adamchainz/django-jsonfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·54 lines (42 loc) · 1.58 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
#!/usr/bin/env python
import os
import sys
import warnings
import django
BASE_PATH = os.path.dirname(__file__)
def main():
"""
Standalone django model test with a 'memory-only-django-installation'.
You can play with a django model without a complete django app installation.
http://www.djangosnippets.org/snippets/1044/
"""
warnings.filterwarnings("always", category=DeprecationWarning)
warnings.filterwarnings("always", category=PendingDeprecationWarning)
os.environ["DJANGO_SETTINGS_MODULE"] = "django.conf.global_settings"
from django.conf import global_settings
global_settings.INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'jsonfield',
)
global_settings.DATABASES = {
'default': {
'ENGINE': 'django.db.backends.{DB_ENGINE}'.format(**os.environ),
'NAME': 'jsonfield-{DB_NAME}'.format(**os.environ),
'USER': os.environ.get('DB_USER', ''),
'PASSWORD': os.environ.get('DB_PASSWORD', ''),
}
}
global_settings.STATIC_URL = "/static/"
global_settings.MEDIA_ROOT = os.path.join(BASE_PATH, 'static')
global_settings.STATIC_ROOT = global_settings.MEDIA_ROOT
global_settings.SECRET_KEY = '334ebe58-a77d-4321-9d01-a7d2cb8d3eea'
from django.test.utils import get_runner
test_runner = get_runner(global_settings)
test_runner = test_runner()
if getattr(django, 'setup', None):
django.setup()
failures = test_runner.run_tests(['jsonfield'])
sys.exit(failures)
if __name__ == '__main__':
main()