forked from dimagi/commcare-hq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsettings.py
164 lines (135 loc) · 5.43 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
158
159
160
161
162
163
164
import os
from copy import deepcopy
import settingshelper as helper
from settings import *
# to enable v7 ES tests
if os.environ.get('ELASTICSEARCH_7_PORT'):
ELASTICSEARCH_PORT = int(os.environ.get('ELASTICSEARCH_7_PORT'))
if os.environ.get('ELASTICSEARCH_MAJOR_VERSION'):
ELASTICSEARCH_MAJOR_VERSION = int(os.environ.get('ELASTICSEARCH_MAJOR_VERSION'))
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.patches.PatchesPlugin',
'corehq.tests.noseplugins.redislocks.RedisLockTimeoutPlugin',
'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': 'scripts',
'DD_DOGSTATSD_DISABLE': 'true',
'DD_TRACE_ENABLED': 'false',
}.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.
'alembic': 'WARNING',
'auditcare': 'INFO',
'boto3': 'WARNING',
'botocore': 'INFO',
'couchdbkit.request': 'INFO',
'couchdbkit.designer': 'WARNING',
'datadog': 'WARNING',
'elasticsearch': 'ERROR',
'kafka.conn': 'WARNING',
'kafka.client': 'WARNING',
'kafka.consumer.kafka': 'WARNING',
'kafka.metrics': 'WARNING',
'kafka.protocol.parser': 'WARNING',
'kafka.producer': 'WARNING',
'quickcache': 'INFO',
'requests.packages.urllib3': 'WARNING',
's3transfer': 'INFO',
'urllib3': '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': {},
}
# Default custom databases to use the same configuration as the default
# This is so that all devs don't have to run citus locally
if 'icds-ucr' not in DATABASES:
DATABASES['icds-ucr'] = deepcopy(DATABASES['default'])
# use a different name otherwise migrations don't get run
DATABASES['icds-ucr']['NAME'] = 'commcarehq_icds_ucr'
del DATABASES['icds-ucr']['TEST']['NAME'] # gets set by `helper.assign_test_db_names`
helper.assign_test_db_names(DATABASES)
# See comment under settings.SMS_QUEUE_ENABLED
SMS_QUEUE_ENABLED = False
# use all providers in tests
METRICS_PROVIDERS = [
'corehq.util.metrics.datadog.DatadogMetrics',
'corehq.util.metrics.prometheus.PrometheusMetrics',
]
# timeout faster in tests
ES_SEARCH_TIMEOUT = 5
# icds version = ab702b37a1 (to force a build)
if os.path.exists("extensions/icds/custom/icds"):
icds_apps = [
"custom.icds",
"custom.icds_reports"
]
for app in icds_apps:
if app not in INSTALLED_APPS:
INSTALLED_APPS = (app,) + tuple(INSTALLED_APPS)
if "custom.icds.commcare_extensions" not in COMMCARE_EXTENSIONS:
COMMCARE_EXTENSIONS.append("custom.icds.commcare_extensions")
CUSTOM_DB_ROUTING["icds_reports"] = "icds-ucr-citus"