mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:11:09 -05:00
Add comprehensive tests for Parks API and models
- Implemented extensive test cases for the Parks API, covering endpoints for listing, retrieving, creating, updating, and deleting parks. - Added tests for filtering, searching, and ordering parks in the API. - Created tests for error handling in the API, including malformed JSON and unsupported methods. - Developed model tests for Park, ParkArea, Company, and ParkReview models, ensuring validation and constraints are enforced. - Introduced utility mixins for API and model testing to streamline assertions and enhance test readability. - Included integration tests to validate complete workflows involving park creation, retrieval, updating, and deletion.
This commit is contained in:
176
config/django/local.py
Normal file
176
config/django/local.py
Normal file
@@ -0,0 +1,176 @@
|
||||
"""
|
||||
Local development settings for thrillwiki project.
|
||||
"""
|
||||
|
||||
from .base import *
|
||||
from ..settings import database
|
||||
from ..settings import email # Import the module and use its members, e.g., email.EMAIL_HOST
|
||||
from ..settings import security # Import the module and use its members, e.g., security.SECURE_HSTS_SECONDS
|
||||
from .base import env # Import env for environment variable access
|
||||
|
||||
# Development-specific settings
|
||||
DEBUG = True
|
||||
|
||||
# For local development, allow all hosts
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# CSRF trusted origins for local development
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
"http://localhost:8000",
|
||||
"http://127.0.0.1:8000",
|
||||
"https://beta.thrillwiki.com",
|
||||
]
|
||||
|
||||
# GeoDjango Settings for macOS development
|
||||
GDAL_LIBRARY_PATH = env('GDAL_LIBRARY_PATH', default="/opt/homebrew/lib/libgdal.dylib")
|
||||
GEOS_LIBRARY_PATH = env('GEOS_LIBRARY_PATH', default="/opt/homebrew/lib/libgeos_c.dylib")
|
||||
|
||||
# Local cache configuration
|
||||
LOC_MEM_CACHE_BACKEND = "django.core.cache.backends.locmem.LocMemCache"
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": LOC_MEM_CACHE_BACKEND,
|
||||
"LOCATION": "unique-snowflake",
|
||||
"TIMEOUT": 300, # 5 minutes
|
||||
"OPTIONS": {"MAX_ENTRIES": 1000},
|
||||
},
|
||||
"sessions": {
|
||||
"BACKEND": LOC_MEM_CACHE_BACKEND,
|
||||
"LOCATION": "sessions-cache",
|
||||
"TIMEOUT": 86400, # 24 hours (same as SESSION_COOKIE_AGE)
|
||||
"OPTIONS": {"MAX_ENTRIES": 5000},
|
||||
},
|
||||
"api": {
|
||||
"BACKEND": LOC_MEM_CACHE_BACKEND,
|
||||
"LOCATION": "api-cache",
|
||||
"TIMEOUT": 300, # 5 minutes
|
||||
"OPTIONS": {"MAX_ENTRIES": 2000},
|
||||
}
|
||||
}
|
||||
|
||||
# Development-friendly cache settings
|
||||
CACHE_MIDDLEWARE_SECONDS = 1 # Very short cache for development
|
||||
CACHE_MIDDLEWARE_KEY_PREFIX = "thrillwiki_dev"
|
||||
|
||||
# Development email backend
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
# Security settings for development
|
||||
SECURE_SSL_REDIRECT = False
|
||||
SESSION_COOKIE_SECURE = False
|
||||
CSRF_COOKIE_SECURE = False
|
||||
|
||||
# Development monitoring tools
|
||||
DEVELOPMENT_APPS = [
|
||||
'silk',
|
||||
'debug_toolbar',
|
||||
'nplusone.ext.django',
|
||||
]
|
||||
|
||||
# Add development apps if available
|
||||
for app in DEVELOPMENT_APPS:
|
||||
if app not in INSTALLED_APPS:
|
||||
INSTALLED_APPS.append(app)
|
||||
|
||||
# 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',
|
||||
]
|
||||
|
||||
# Add development middleware
|
||||
for middleware in DEVELOPMENT_MIDDLEWARE:
|
||||
if middleware not in MIDDLEWARE:
|
||||
MIDDLEWARE.insert(1, middleware) # Insert after security middleware
|
||||
|
||||
# Debug toolbar configuration
|
||||
INTERNAL_IPS = ['127.0.0.1', '::1']
|
||||
|
||||
# Silk configuration for development
|
||||
SILKY_PYTHON_PROFILER = True
|
||||
SILKY_PYTHON_PROFILER_BINARY = True
|
||||
SILKY_PYTHON_PROFILER_RESULT_PATH = BASE_DIR / 'profiles'
|
||||
SILKY_AUTHENTICATION = True
|
||||
SILKY_AUTHORISATION = True
|
||||
|
||||
# NPlusOne configuration
|
||||
import logging
|
||||
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': '{',
|
||||
},
|
||||
'json': {
|
||||
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
||||
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
|
||||
},
|
||||
},
|
||||
'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',
|
||||
},
|
||||
'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'],
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['file'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'django.db.backends': {
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
},
|
||||
'thrillwiki': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
},
|
||||
'performance': {
|
||||
'handlers': ['performance'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'query_optimization': {
|
||||
'handlers': ['console', 'file'],
|
||||
'level': 'WARNING',
|
||||
'propagate': False,
|
||||
},
|
||||
'nplusone': {
|
||||
'handlers': ['console'],
|
||||
'level': 'WARNING',
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user