Add Chzzk campaign and reward models, import command, and schemas
Some checks failed
Deploy to Server / deploy (push) Failing after 19s
Some checks failed
Deploy to Server / deploy (push) Failing after 19s
This commit is contained in:
parent
c852134338
commit
677aedf42b
14 changed files with 650 additions and 9 deletions
|
|
@ -140,10 +140,11 @@ INSTALLED_APPS: list[str] = [
|
|||
"django.contrib.staticfiles",
|
||||
"django.contrib.postgres",
|
||||
# Internal apps
|
||||
"twitch.apps.TwitchConfig",
|
||||
"kick.apps.KickConfig",
|
||||
"youtube.apps.YoutubeConfig",
|
||||
"chzzk.apps.ChzzkConfig",
|
||||
"core.apps.CoreConfig",
|
||||
"kick.apps.KickConfig",
|
||||
"twitch.apps.TwitchConfig",
|
||||
"youtube.apps.YoutubeConfig",
|
||||
# Third-party apps
|
||||
"django_celery_results",
|
||||
"django_celery_beat",
|
||||
|
|
@ -171,10 +172,35 @@ TEMPLATES: list[dict[str, Any]] = [
|
|||
},
|
||||
]
|
||||
|
||||
DATABASES: dict[str, dict[str, Any]] = (
|
||||
{"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
|
||||
if TESTING
|
||||
else {
|
||||
|
||||
def configure_databases(*, testing: bool, base_dir: Path) -> dict[str, dict[str, Any]]:
|
||||
"""Configure Django databases based on environment variables and testing mode.
|
||||
|
||||
Args:
|
||||
testing (bool): Whether the application is running in testing mode.
|
||||
base_dir (Path): The base directory of the project, used for SQLite file location.
|
||||
|
||||
Returns:
|
||||
dict[str, dict[str, Any]]: The DATABASES setting for Django.
|
||||
"""
|
||||
use_sqlite: bool = env_bool("USE_SQLITE", default=False)
|
||||
|
||||
if testing:
|
||||
return {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": ":memory:",
|
||||
},
|
||||
}
|
||||
if use_sqlite:
|
||||
return {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": str(base_dir / "db.sqlite3"),
|
||||
},
|
||||
}
|
||||
# Default: PostgreSQL
|
||||
return {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"NAME": os.getenv("POSTGRES_DB", "ttvdrops"),
|
||||
|
|
@ -187,6 +213,11 @@ DATABASES: dict[str, dict[str, Any]] = (
|
|||
"OPTIONS": {"connect_timeout": env_int("DB_CONNECT_TIMEOUT", 10)},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
DATABASES: dict[str, dict[str, Any]] = configure_databases(
|
||||
testing=TESTING,
|
||||
base_dir=BASE_DIR,
|
||||
)
|
||||
|
||||
if not TESTING:
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import os
|
|||
import sys
|
||||
from contextlib import contextmanager
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from django.contrib.sessions.models import Session
|
||||
|
|
@ -249,14 +250,14 @@ def test_email_settings_from_env(
|
|||
assert reloaded.SERVER_EMAIL == "me@example.com"
|
||||
|
||||
|
||||
def test_database_settings_when_not_testing(
|
||||
def test_database_settings_when_use_sqlite_enabled(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""When not running tests, DATABASES should use the Postgres configuration."""
|
||||
# Ensure the module believes it's not running tests
|
||||
"""When USE_SQLITE=1 and not testing, DATABASES should use SQLite file."""
|
||||
monkeypatch.setattr("sys.argv", ["manage.py", "runserver"])
|
||||
monkeypatch.delenv("PYTEST_VERSION", raising=False)
|
||||
monkeypatch.setenv("USE_SQLITE", "1")
|
||||
|
||||
reloaded: ModuleType = reload_settings_module(
|
||||
TESTING=None,
|
||||
|
|
@ -271,7 +272,36 @@ def test_database_settings_when_not_testing(
|
|||
)
|
||||
|
||||
assert reloaded.TESTING is False
|
||||
db_cfg = reloaded.DATABASES["default"]
|
||||
db_cfg: dict[str, Any] = reloaded.DATABASES["default"]
|
||||
assert db_cfg["ENGINE"] == "django.db.backends.sqlite3"
|
||||
# Should use a file, not in-memory
|
||||
assert db_cfg["NAME"].endswith("db.sqlite3")
|
||||
|
||||
|
||||
def test_database_settings_when_not_testing(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""When not running tests, DATABASES should use the Postgres configuration."""
|
||||
# Ensure the module believes it's not running tests and USE_SQLITE is unset
|
||||
monkeypatch.setattr("sys.argv", ["manage.py", "runserver"])
|
||||
monkeypatch.delenv("PYTEST_VERSION", raising=False)
|
||||
monkeypatch.setenv("USE_SQLITE", "0")
|
||||
|
||||
reloaded: ModuleType = reload_settings_module(
|
||||
TESTING=None,
|
||||
PYTEST_VERSION=None,
|
||||
POSTGRES_DB="prod_db",
|
||||
POSTGRES_USER="prod_user",
|
||||
POSTGRES_PASSWORD="secret",
|
||||
POSTGRES_HOST="db.host",
|
||||
POSTGRES_PORT="5433",
|
||||
CONN_MAX_AGE="120",
|
||||
CONN_HEALTH_CHECKS="0",
|
||||
)
|
||||
|
||||
assert reloaded.TESTING is False
|
||||
db_cfg: dict[str, Any] = reloaded.DATABASES["default"]
|
||||
assert db_cfg["ENGINE"] == "django.db.backends.postgresql"
|
||||
assert db_cfg["NAME"] == "prod_db"
|
||||
assert db_cfg["USER"] == "prod_user"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue