mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:51:09 -05:00
Refactor test utilities and enhance ASGI settings
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
This commit is contained in:
@@ -5,11 +5,10 @@ Local development settings for thrillwiki project.
|
||||
import logging
|
||||
from .base import *
|
||||
from ..settings import database
|
||||
|
||||
# Import the module and use its members, e.g., email.EMAIL_HOST
|
||||
from ..settings import email
|
||||
|
||||
# Import the module and use its members, e.g., security.SECURE_HSTS_SECONDS
|
||||
from ..settings import security
|
||||
from .base import env # Import env for environment variable access
|
||||
|
||||
# Import database configuration
|
||||
DATABASES = database.DATABASES
|
||||
@@ -18,7 +17,7 @@ DATABASES = database.DATABASES
|
||||
DEBUG = True
|
||||
|
||||
# For local development, allow all hosts
|
||||
ALLOWED_HOSTS = ['*']
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
# CSRF trusted origins for local development
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
@@ -51,7 +50,7 @@ CACHES = {
|
||||
"LOCATION": "api-cache",
|
||||
"TIMEOUT": 300, # 5 minutes
|
||||
"OPTIONS": {"MAX_ENTRIES": 2000},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
# Development-friendly cache settings
|
||||
@@ -68,10 +67,10 @@ CSRF_COOKIE_SECURE = False
|
||||
|
||||
# Development monitoring tools
|
||||
DEVELOPMENT_APPS = [
|
||||
'silk',
|
||||
'debug_toolbar',
|
||||
'nplusone.ext.django',
|
||||
'django_extensions',
|
||||
"silk",
|
||||
"debug_toolbar",
|
||||
"nplusone.ext.django",
|
||||
"django_extensions",
|
||||
]
|
||||
|
||||
# Add development apps if available
|
||||
@@ -81,11 +80,11 @@ for app in DEVELOPMENT_APPS:
|
||||
|
||||
# Development middleware
|
||||
DEVELOPMENT_MIDDLEWARE = [
|
||||
'silk.middleware.SilkyMiddleware',
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'nplusone.ext.django.NPlusOneMiddleware',
|
||||
'core.middleware.performance_middleware.PerformanceMiddleware',
|
||||
'core.middleware.performance_middleware.QueryCountMiddleware',
|
||||
"silk.middleware.SilkyMiddleware",
|
||||
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||
"nplusone.ext.django.NPlusOneMiddleware",
|
||||
"core.middleware.performance_middleware.PerformanceMiddleware",
|
||||
"core.middleware.performance_middleware.QueryCountMiddleware",
|
||||
]
|
||||
|
||||
# Add development middleware
|
||||
@@ -94,14 +93,15 @@ for middleware in DEVELOPMENT_MIDDLEWARE:
|
||||
MIDDLEWARE.insert(1, middleware) # Insert after security middleware
|
||||
|
||||
# Debug toolbar configuration
|
||||
INTERNAL_IPS = ['127.0.0.1', '::1']
|
||||
INTERNAL_IPS = ["127.0.0.1", "::1"]
|
||||
|
||||
# Silk configuration for development
|
||||
# Disable profiler to avoid silk_profile installation issues
|
||||
SILKY_PYTHON_PROFILER = False
|
||||
SILKY_PYTHON_PROFILER_BINARY = False # Disable binary profiler
|
||||
SILKY_PYTHON_PROFILER_RESULT_PATH = BASE_DIR / \
|
||||
'profiles' # Not needed when profiler is disabled
|
||||
SILKY_PYTHON_PROFILER_RESULT_PATH = (
|
||||
BASE_DIR / "profiles"
|
||||
) # Not needed when profiler is disabled
|
||||
SILKY_AUTHENTICATION = True # Require login to access Silk
|
||||
SILKY_AUTHORISATION = True # Enable authorization
|
||||
SILKY_MAX_REQUEST_BODY_SIZE = -1 # Don't limit request body size
|
||||
@@ -110,77 +110,80 @@ SILKY_MAX_RESPONSE_BODY_SIZE = 1024
|
||||
SILKY_META = True # Record metadata about requests
|
||||
|
||||
# NPlusOne configuration
|
||||
NPLUSONE_LOGGER = logging.getLogger('nplusone')
|
||||
NPLUSONE_LOGGER = logging.getLogger("nplusone")
|
||||
NPLUSONE_LOG_LEVEL = logging.WARN
|
||||
|
||||
# Enhanced development logging
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
|
||||
'style': '{',
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"verbose": {
|
||||
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
'json': {
|
||||
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
||||
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
|
||||
"json": {
|
||||
"()": "pythonjsonlogger.jsonlogger.JsonFormatter",
|
||||
"format": (
|
||||
"%(levelname)s %(asctime)s %(module)s %(process)d "
|
||||
"%(thread)d %(message)s"
|
||||
),
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose',
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "verbose",
|
||||
},
|
||||
'file': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': BASE_DIR / 'logs' / 'thrillwiki.log',
|
||||
'maxBytes': 1024*1024*10, # 10MB
|
||||
'backupCount': 5,
|
||||
'formatter': 'json',
|
||||
"file": {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": BASE_DIR / "logs" / "thrillwiki.log",
|
||||
"maxBytes": 1024 * 1024 * 10, # 10MB
|
||||
"backupCount": 5,
|
||||
"formatter": "json",
|
||||
},
|
||||
'performance': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': BASE_DIR / 'logs' / 'performance.log',
|
||||
'maxBytes': 1024*1024*10, # 10MB
|
||||
'backupCount': 5,
|
||||
'formatter': 'json',
|
||||
"performance": {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": BASE_DIR / "logs" / "performance.log",
|
||||
"maxBytes": 1024 * 1024 * 10, # 10MB
|
||||
"backupCount": 5,
|
||||
"formatter": "json",
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'level': 'INFO',
|
||||
'handlers': ['console'],
|
||||
"root": {
|
||||
"level": "INFO",
|
||||
"handlers": ["console"],
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['file'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
"loggers": {
|
||||
"django": {
|
||||
"handlers": ["file"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
'django.db.backends': {
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
"django.db.backends": {
|
||||
"handlers": ["console"],
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
'thrillwiki': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
"thrillwiki": {
|
||||
"handlers": ["console", "file"],
|
||||
"level": "DEBUG",
|
||||
"propagate": False,
|
||||
},
|
||||
'performance': {
|
||||
'handlers': ['performance'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
"performance": {
|
||||
"handlers": ["performance"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
'query_optimization': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'WARNING',
|
||||
'propagate': False,
|
||||
"query_optimization": {
|
||||
"handlers": ["console", "file"],
|
||||
"level": "WARNING",
|
||||
"propagate": False,
|
||||
},
|
||||
'nplusone': {
|
||||
'handlers': ['console'],
|
||||
'level': 'WARNING',
|
||||
'propagate': False,
|
||||
"nplusone": {
|
||||
"handlers": ["console"],
|
||||
"level": "WARNING",
|
||||
"propagate": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user