Lower line-length to default and don't add from __future__ import annotations to everything
This commit is contained in:
parent
dcc4cecb8d
commit
1118c03c1b
46 changed files with 2338 additions and 1085 deletions
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
|
@ -39,7 +37,11 @@ def env_int(key: str, default: int) -> int:
|
|||
|
||||
|
||||
DEBUG: bool = env_bool(key="DEBUG", default=True)
|
||||
TESTING: bool = env_bool(key="TESTING", default=False) or "test" in sys.argv or "PYTEST_VERSION" in os.environ
|
||||
TESTING: bool = (
|
||||
env_bool(key="TESTING", default=False)
|
||||
or "test" in sys.argv
|
||||
or "PYTEST_VERSION" in os.environ
|
||||
)
|
||||
|
||||
|
||||
def get_data_dir() -> Path:
|
||||
|
|
@ -118,28 +120,11 @@ if not DEBUG:
|
|||
LOGGING: dict[str, Any] = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"handlers": {
|
||||
"console": {
|
||||
"level": "DEBUG",
|
||||
"class": "logging.StreamHandler",
|
||||
},
|
||||
},
|
||||
"handlers": {"console": {"level": "DEBUG", "class": "logging.StreamHandler"}},
|
||||
"loggers": {
|
||||
"": {
|
||||
"handlers": ["console"],
|
||||
"level": "INFO",
|
||||
"propagate": True,
|
||||
},
|
||||
"ttvdrops": {
|
||||
"handlers": ["console"],
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
"django": {
|
||||
"handlers": ["console"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
"": {"handlers": ["console"], "level": "INFO", "propagate": True},
|
||||
"ttvdrops": {"handlers": ["console"], "level": "DEBUG", "propagate": False},
|
||||
"django": {"handlers": ["console"], "level": "INFO", "propagate": False},
|
||||
"django.utils.autoreload": {
|
||||
"handlers": ["console"],
|
||||
"level": "INFO",
|
||||
|
|
@ -179,12 +164,7 @@ TEMPLATES: list[dict[str, Any]] = [
|
|||
]
|
||||
|
||||
DATABASES: dict[str, dict[str, Any]] = (
|
||||
{
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": ":memory:",
|
||||
},
|
||||
}
|
||||
{"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
|
||||
if TESTING
|
||||
else {
|
||||
"default": {
|
||||
|
|
@ -196,19 +176,13 @@ DATABASES: dict[str, dict[str, Any]] = (
|
|||
"PORT": env_int("POSTGRES_PORT", 5432),
|
||||
"CONN_MAX_AGE": env_int("CONN_MAX_AGE", 60),
|
||||
"CONN_HEALTH_CHECKS": env_bool("CONN_HEALTH_CHECKS", default=True),
|
||||
"OPTIONS": {
|
||||
"connect_timeout": env_int("DB_CONNECT_TIMEOUT", 10),
|
||||
},
|
||||
"OPTIONS": {"connect_timeout": env_int("DB_CONNECT_TIMEOUT", 10)},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if not TESTING:
|
||||
INSTALLED_APPS = [
|
||||
*INSTALLED_APPS,
|
||||
"debug_toolbar",
|
||||
"silk",
|
||||
]
|
||||
INSTALLED_APPS = [*INSTALLED_APPS, "debug_toolbar", "silk"]
|
||||
MIDDLEWARE = [
|
||||
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||
"silk.middleware.SilkyMiddleware",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import os
|
||||
import sys
|
||||
|
|
@ -42,7 +40,10 @@ def reload_settings_module() -> Generator[Callable[..., ModuleType]]:
|
|||
|
||||
def _reload(**env_overrides: str | None) -> ModuleType:
|
||||
env: dict[str, str] = os.environ.copy()
|
||||
env.setdefault("DJANGO_SECRET_KEY", original_env.get("DJANGO_SECRET_KEY", "test-secret-key"))
|
||||
env.setdefault(
|
||||
"DJANGO_SECRET_KEY",
|
||||
original_env.get("DJANGO_SECRET_KEY", "test-secret-key"),
|
||||
)
|
||||
|
||||
for key, value in env_overrides.items():
|
||||
if value is None:
|
||||
|
|
@ -95,7 +96,10 @@ def test_env_int_returns_default(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
assert settings.env_int("MAX_COUNT", 3) == 3
|
||||
|
||||
|
||||
def test_get_data_dir_uses_platformdirs(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
def test_get_data_dir_uses_platformdirs(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""get_data_dir should use platformdirs and create the directory."""
|
||||
fake_dir: Path = tmp_path / "data_dir"
|
||||
|
||||
|
|
@ -112,7 +116,9 @@ def test_get_data_dir_uses_platformdirs(monkeypatch: pytest.MonkeyPatch, tmp_pat
|
|||
assert path.is_dir() is True
|
||||
|
||||
|
||||
def test_allowed_hosts_when_debug_false(reload_settings_module: Callable[..., ModuleType]) -> None:
|
||||
def test_allowed_hosts_when_debug_false(
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""When DEBUG is false, ALLOWED_HOSTS should use the production host."""
|
||||
reloaded: ModuleType = reload_settings_module(DEBUG="false")
|
||||
|
||||
|
|
@ -120,7 +126,9 @@ def test_allowed_hosts_when_debug_false(reload_settings_module: Callable[..., Mo
|
|||
assert reloaded.ALLOWED_HOSTS == ["ttvdrops.lovinator.space"]
|
||||
|
||||
|
||||
def test_allowed_hosts_when_debug_true(reload_settings_module: Callable[..., ModuleType]) -> None:
|
||||
def test_allowed_hosts_when_debug_true(
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""When DEBUG is true, development hostnames should be allowed."""
|
||||
reloaded: ModuleType = reload_settings_module(DEBUG="1")
|
||||
|
||||
|
|
@ -128,7 +136,9 @@ def test_allowed_hosts_when_debug_true(reload_settings_module: Callable[..., Mod
|
|||
assert reloaded.ALLOWED_HOSTS == [".localhost", "127.0.0.1", "[::1]", "testserver"]
|
||||
|
||||
|
||||
def test_debug_defaults_true_when_missing(reload_settings_module: Callable[..., ModuleType]) -> None:
|
||||
def test_debug_defaults_true_when_missing(
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""DEBUG should default to True when the environment variable is missing."""
|
||||
reloaded: ModuleType = reload_settings_module(DEBUG=None)
|
||||
|
||||
|
|
@ -172,7 +182,9 @@ def test_testing_true_when_sys_argv_contains_test(
|
|||
assert reloaded.TESTING is True
|
||||
|
||||
|
||||
def test_testing_true_when_pytest_version_set(reload_settings_module: Callable[..., ModuleType]) -> None:
|
||||
def test_testing_true_when_pytest_version_set(
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""TESTING should be true when PYTEST_VERSION is set in the env."""
|
||||
reloaded: ModuleType = reload_settings_module(PYTEST_VERSION="7.0.0")
|
||||
|
||||
|
|
@ -212,7 +224,9 @@ def test_missing_secret_key_causes_system_exit(monkeypatch: pytest.MonkeyPatch)
|
|||
__import__("config.settings")
|
||||
|
||||
|
||||
def test_email_settings_from_env(reload_settings_module: Callable[..., ModuleType]) -> None:
|
||||
def test_email_settings_from_env(
|
||||
reload_settings_module: Callable[..., ModuleType],
|
||||
) -> None:
|
||||
"""EMAIL_* values should be read from the environment and cast correctly."""
|
||||
reloaded: ModuleType = reload_settings_module(
|
||||
EMAIL_HOST="smtp.example.com",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.conf import settings
|
||||
|
|
@ -21,10 +19,7 @@ urlpatterns: list[URLPattern | URLResolver] = [
|
|||
|
||||
# Serve media in development
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(
|
||||
settings.MEDIA_URL,
|
||||
document_root=settings.MEDIA_ROOT,
|
||||
)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
if not settings.TESTING:
|
||||
from debug_toolbar.toolbar import debug_toolbar_urls
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue