""" Test settings - для запуска тестов. """ from .base import * SECRET_KEY = "django-insecure-test-key-only-for-testing" DEBUG = True STARTUP_CHECKS_ENABLED = False # JWT SIMPLE_JWT["SIGNING_KEY"] = SECRET_KEY ALLOWED_HOSTS = ["localhost", "127.0.0.1", "0.0.0.0", "testserver"] # noqa: S104 # Use in-memory SQLite database for faster tests DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", "TEST": { "NAME": ":memory:", }, } } # Disable migrations for faster tests class DisableMigrations: def __contains__(self, item): return True def __getitem__(self, item): return None MIGRATION_MODULES = DisableMigrations() # Cache configuration for tests (use local memory) CACHES = { "default": { "BACKEND": "django.core.cache.backends.locmem.LocMemCache", } } # Email backend for tests EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" # Celery Configuration for Tests (use eager execution) CELERY_TASK_ALWAYS_EAGER = True CELERY_TASK_EAGER_PROPAGATES = True CELERY_BROKER_URL = "memory://" CELERY_RESULT_BACKEND = "cache+memory://" # Password hashers - use fast hasher for tests PASSWORD_HASHERS = [ "django.contrib.auth.hashers.MD5PasswordHasher", ] # Disable logging during tests LOGGING = { "version": 1, "disable_existing_loggers": False, "handlers": { "null": { "class": "logging.NullHandler", }, }, "root": { "handlers": ["null"], }, "loggers": { "django": { "handlers": ["null"], "propagate": False, }, "django.request": { "handlers": ["null"], "propagate": False, }, }, } # Media files for tests MEDIA_ROOT = "/tmp/test_media" # noqa: S108 # Static files for tests STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" # Disable CSRF for API tests and disable throttling REST_FRAMEWORK = { **globals().get("REST_FRAMEWORK", {}), "DEFAULT_AUTHENTICATION_CLASSES": [ "rest_framework_simplejwt.authentication.JWTAuthentication", ], "TEST_REQUEST_DEFAULT_FORMAT": "json", # Disable throttling for tests "DEFAULT_THROTTLE_CLASSES": [], "DEFAULT_THROTTLE_RATES": {}, } # JWT settings for tests from datetime import timedelta SIMPLE_JWT = { **globals().get("SIMPLE_JWT", {}), "ACCESS_TOKEN_LIFETIME": timedelta(minutes=5), "REFRESH_TOKEN_LIFETIME": timedelta(days=1), "ROTATE_REFRESH_TOKENS": True, }