forked from dimagi/commcare-hq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsettings.py
157 lines (135 loc) · 4.98 KB
/
testsettings.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from __future__ import absolute_import
from __future__ import unicode_literals
import settingshelper as helper
from settings import *
USING_CITUS = any(db.get('ROLE') == 'citus_master' for db in DATABASES.values())
# note: the only reason these are prepended to INSTALLED_APPS is because of
# a weird travis issue with kafka. if for any reason this order causes problems
# it can be reverted whenever that's figured out.
# https://github.com/dimagi/commcare-hq/pull/10034#issuecomment-174868270
INSTALLED_APPS = (
'django_nose',
'testapps.test_elasticsearch',
'testapps.test_pillowtop',
) + tuple(INSTALLED_APPS)
if USING_CITUS:
if 'testapps.citus_master' not in INSTALLED_APPS:
INSTALLED_APPS = (
'testapps.citus_master',
'testapps.citus_worker',
) + tuple(INSTALLED_APPS)
if 'testapps.citus_master.citus_router.CitusDBRouter' not in DATABASE_ROUTERS:
# this router must go first
DATABASE_ROUTERS = ['testapps.citus_master.citus_router.CitusDBRouter'] + DATABASE_ROUTERS
TEST_RUNNER = 'django_nose.BasicNoseRunner'
NOSE_ARGS = [
#'--no-migrations' # trim ~120s from test run with db tests
#'--with-fixture-bundling',
]
NOSE_PLUGINS = [
'corehq.tests.nose.HqTestFinderPlugin',
'corehq.tests.noseplugins.dividedwerun.DividedWeRunPlugin',
'corehq.tests.noseplugins.djangomigrations.DjangoMigrationsPlugin',
'corehq.tests.noseplugins.cmdline_params.CmdLineParametersPlugin',
'corehq.tests.noseplugins.uniformresult.UniformTestResultPlugin',
# The following are not enabled by default
'corehq.tests.noseplugins.logfile.LogFilePlugin',
'corehq.tests.noseplugins.timing.TimingPlugin',
'corehq.tests.noseplugins.output.OutputPlugin',
# Uncomment to debug tests. Plugins have nice hooks for inspecting state
# before/after each test or context setup/teardown, etc.
#'corehq.tests.noseplugins.debug.DebugPlugin',
]
# these settings can be overridden with environment variables
for key, value in {
'NOSE_DB_TEST_CONTEXT': 'corehq.tests.nose.HqdbContext',
'NOSE_NON_DB_TEST_CONTEXT': 'corehq.tests.nose.ErrorOnDbAccessContext',
'NOSE_IGNORE_FILES': '^localsettings',
'NOSE_EXCLUDE_DIRS': ';'.join([
'scripts',
]),
}.items():
os.environ.setdefault(key, value)
del key, value
if "SKIP_TESTS_REQUIRING_EXTRA_SETUP" not in globals():
SKIP_TESTS_REQUIRING_EXTRA_SETUP = False
CELERY_TASK_ALWAYS_EAGER = True
# keep a copy of the original PILLOWTOPS setting around in case other tests want it.
_PILLOWTOPS = PILLOWTOPS
PILLOWTOPS = {}
# required by auditcare tests
AUDIT_MODEL_SAVE = ['django.contrib.auth.models.User']
AUDIT_ADMIN_VIEWS = False
PHONE_TIMEZONES_HAVE_BEEN_PROCESSED = True
PHONE_TIMEZONES_SHOULD_BE_PROCESSED = True
ENABLE_PRELOGIN_SITE = True
# override dev_settings
CACHE_REPORTS = True
def _set_logging_levels(levels):
import logging
for path, level in levels.items():
logging.getLogger(path).setLevel(level)
_set_logging_levels({
# Quiet down noisy loggers. Selective removal can be handy for debugging.
'auditcare': 'INFO',
'boto3': 'WARNING',
'botocore': 'INFO',
'couchdbkit.request': 'INFO',
'datadog': 'WARNING',
'elasticsearch': 'ERROR',
'quickcache': 'INFO',
'requests.packages.urllib3': 'WARNING',
's3transfer': 'INFO',
'urllib3': 'WARNING',
'kafka.conn': 'WARNING',
'kafka.client': 'WARNING',
'kafka.consumer.kafka': 'WARNING',
})
# use empty LOGGING dict with --debug=nose,nose.plugins to debug test discovery
# TODO empty logging config (and fix revealed deprecation warnings)
LOGGING = {
'disable_existing_loggers': False,
'version': 1,
'loggers': {},
}
# Required in Python 3 to prevent transient but frequent travis errors.
# Probably is caused by some race condition.
if 'icds-ucr' not in DATABASES:
DATABASES['icds-ucr'] = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'icds_commcarehq',
'USER': 'commcarehq',
'PASSWORD': 'commcarehq',
'HOST': 'localhost',
'PORT': '5432',
'TEST': {
'SERIALIZE': False,
}
}
# Define an aaa-data database if its not already defined
# This is necessary because REPORTING_DATABASES references aaa-data.
# We must have aaa-data in a separate database
# https://github.com/dimagi/commcare-hq/pull/23351#issuecomment-467500691
if 'aaa-data' not in DATABASES:
DATABASES['aaa-data'] = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'aaa_commcarehq',
'USER': 'commcarehq',
'PASSWORD': 'commcarehq',
'HOST': 'localhost',
'PORT': '5432',
'TEST': {
'SERIALIZE': False,
}
}
helper.assign_test_db_names(DATABASES)
REPORTING_DATABASES = {
'default': 'default',
'ucr': 'default',
'icds-ucr': 'icds-ucr',
'icds-ucr-non-dashboard': 'icds-ucr',
'icds-test-ucr': 'icds-ucr',
'aaa-data': 'aaa-data',
}
# See comment under settings.SMS_QUEUE_ENABLED
SMS_QUEUE_ENABLED = False