-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_settings.py
More file actions
105 lines (91 loc) · 3.41 KB
/
test_settings.py
File metadata and controls
105 lines (91 loc) · 3.41 KB
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
"""
Test-only Django settings.
Imports base settings, then overrides for isolated tests.
Tests always use PostgreSQL (same as CI and production) so behavior matches
JSONB, case-sensitive ILIKE, connection pooling, and transaction semantics.
SQLite is not used: it can hide bugs that only appear on Postgres.
"""
import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
from .settings import * # noqa: F401, F403
from .settings import DATABASES # explicit import for ruff F405 (after star import)
# Never run workspace orphan cleanup during tests (CoreConfig.ready).
WORKSPACE_ORPHAN_CLEANUP_ENABLED = False
if not (os.environ.get("DATABASE_URL") or "").strip():
raise ImproperlyConfigured(
"config.test_settings requires DATABASE_URL (PostgreSQL). "
"Start the local test database: "
"docker compose -f docker-compose.test.yml up -d "
"then set DATABASE_URL, for example: "
"postgres://postgres:postgres@127.0.0.1:5433/postgres "
"See README.md → Running tests."
)
# Prefer short-lived connections and a bounded connect timeout so flaky
# networking fails fast instead of hanging pytest.
_default_db = DATABASES.get("default", {})
_engine = (_default_db.get("ENGINE") or "").lower()
if "postgresql" not in _engine:
raise ImproperlyConfigured(
"config.test_settings requires PostgreSQL. "
f"Got DATABASES['default']['ENGINE']={_default_db.get('ENGINE')!r}; "
"use a postgres:// or postgresql:// DATABASE_URL. "
"See README.md → Running tests."
)
_opts = dict(_default_db.get("OPTIONS") or {})
_opts.setdefault("connect_timeout", 15)
_default_db["OPTIONS"] = _opts
_default_db["CONN_MAX_AGE"] = 0
DATABASES["default"] = _default_db
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {"format": "{levelname} {message}", "style": "{"},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "simple",
},
},
"root": {
"handlers": ["console"],
"level": "WARNING",
},
}
BASE_DIR = Path(__file__).resolve().parent.parent
_test_dir = BASE_DIR / ".test_artifacts"
_test_dir.mkdir(exist_ok=True)
WORKSPACE_DIR = _test_dir / "workspace"
WORKSPACE_DIR.mkdir(exist_ok=True)
for _slug in (
"github_activity_tracker",
"boost_library_tracker",
"clang_github_tracker",
"discord_activity_tracker",
"shared",
):
(WORKSPACE_DIR / _slug).mkdir(parents=True, exist_ok=True)
# Base settings computed DISCORD_CONTEXT_REPO_PATH before WORKSPACE_DIR was overridden above.
DISCORD_CONTEXT_REPO_PATH = (
WORKSPACE_DIR / "discord_activity_tracker" / "discord-cplusplus-together-context"
).resolve()
LOG_DIR = _test_dir / "logs"
LOG_DIR.mkdir(exist_ok=True)
GITHUB_TOKEN = ""
GITHUB_TOKENS_SCRAPING = []
GITHUB_TOKEN_WRITE = ""
# Clang GitHub Tracker (tests use defaults)
CLANG_GITHUB_OWNER = "llvm"
CLANG_GITHUB_REPO = "llvm-project"
# Do not inherit publish target from developer .env (avoids real git / token in tests).
CLANG_GITHUB_CONTEXT_REPO_OWNER = ""
CLANG_GITHUB_CONTEXT_REPO_NAME = ""
CLANG_GITHUB_CONTEXT_REPO_BRANCH = ""
# Tests patch a single subprocess.Popen for DiscordChatExporter.
DISCORD_CHAT_EXPORTER_SEQUENTIAL_EXPORT = False