forked from WeblateOrg/weblate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_test.py
148 lines (124 loc) · 4.5 KB
/
settings_test.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
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Django settings for running testsuite
#
import os
import warnings
from weblate.settings_example import * # noqa
CI_DATABASE = os.environ.get("CI_DATABASE", "")
default_user = "weblate"
default_name = "weblate"
if CI_DATABASE in ("mysql", "mariadb"):
DATABASES["default"]["ENGINE"] = "django.db.backends.mysql"
default_user = "root"
DATABASES["default"]["OPTIONS"] = {
"init_command": (
"SET NAMES utf8mb4, "
"wait_timeout=28800, "
"default_storage_engine=INNODB, "
'sql_mode="STRICT_TRANS_TABLES"'
),
"charset": "utf8",
"isolation_level": "read committed",
}
elif CI_DATABASE == "postgresql":
DATABASES["default"]["ENGINE"] = "django.db.backends.postgresql"
default_user = "postgres"
else:
raise ValueError(f"Not supported database: {CI_DATABASE}")
DATABASES["default"]["HOST"] = os.environ.get("CI_DB_HOST", "")
DATABASES["default"]["NAME"] = os.environ.get("CI_DB_NAME", default_name)
DATABASES["default"]["USER"] = os.environ.get("CI_DB_USER", default_user)
DATABASES["default"]["PASSWORD"] = os.environ.get("CI_DB_PASSWORD", "")
DATABASES["default"]["PORT"] = os.environ.get("CI_DB_PORT", "")
# Configure admins
ADMINS = (("Weblate test", "noreply@weblate.org"),)
# The secret key is needed for tests
SECRET_KEY = "secret key used for tests only"
SITE_DOMAIN = "example.com"
# Different root for test repos
if "CI_BASE_DIR" in os.environ:
BASE_DIR = os.environ["CI_BASE_DIR"]
else:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATA_DIR = os.path.join(BASE_DIR, "data-test")
CACHE_DIR = os.path.join(DATA_DIR, "cache")
MEDIA_ROOT = os.path.join(DATA_DIR, "media")
STATIC_ROOT = os.path.join(DATA_DIR, "static")
CELERY_TASK_ALWAYS_EAGER = True
CELERY_BROKER_URL = "memory://"
CELERY_TASK_EAGER_PROPAGATES = True
CELERY_RESULT_BACKEND = None
VCS_API_DELAY = 0
# Localize CDN addon
LOCALIZE_CDN_URL = "https://cdn.example.com/"
LOCALIZE_CDN_PATH = os.path.join(DATA_DIR, "l10n-cdn")
# Needed for makemessages, otherwise it does not discover all available locales
# and the -a parameter does not work
LOCALE_PATHS = [os.path.join(os.path.dirname(__file__), "locale")]
# Silent logging setup
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
"formatters": {"simple": {"format": "%(levelname)s %(message)s"}},
"handlers": {
"mail_admins": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "simple",
},
},
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True,
},
"weblate": {"handlers": [], "level": "ERROR"},
"social": {"handlers": [], "level": "ERROR"},
},
}
# Reset caches
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
if "CI_REDIS_HOST" in os.environ:
CACHES["avatar"] = {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://{}:{}/0".format(
os.environ["CI_REDIS_HOST"], os.environ.get("CI_REDIS_PORT", "6379")
),
}
# Selenium can not clear HttpOnly cookies in MSIE
SESSION_COOKIE_HTTPONLY = False
# Use database backed sessions for transaction consistency in tests
SESSION_ENGINE = "django.contrib.sessions.backends.db"
# Use weak password hasher in tests, there is no point in spending CPU time
# in hashing test passwords
PASSWORD_HASHERS = ["django.contrib.auth.hashers.CryptPasswordHasher"]
# Test optional apps as well
INSTALLED_APPS += ("weblate.billing", "weblate.legal")
# Test GitHub auth
AUTHENTICATION_BACKENDS = (
"social_core.backends.email.EmailAuth",
"social_core.backends.github.GithubOAuth2",
"weblate.accounts.auth.WeblateUserBackend",
)
# Disable random admin checks trigger
BACKGROUND_ADMIN_CHECKS = False
warnings.filterwarnings(
"error",
r"DateTimeField .* received a naive datetime",
RuntimeWarning,
r"django\.db\.models\.fields",
)
# Generate junit compatible XML for AppVeyor
if "APPVEYOR" in os.environ:
TEST_RUNNER = "xmlrunner.extra.djangotestrunner.XMLTestRunner"
TEST_OUTPUT_FILE_NAME = "junit.xml"