🐳 Implement Docker-based testing with full CI/CD pipeline
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
✨ Features: - Docker Compose testing environment (docker-compose.test.yml) - Specialized test Dockerfile (Dockerfile.test) - Test-specific Django settings (settings_test.py) - Complete Drone CI/CD pipeline with 8 stages - PostgreSQL 17 container for isolated testing - Network isolation for testing containers 🧪 Testing improvements: - All 6 tests passing successfully - Fixed ServiceRequest model tests - Added proper Category and Service imports - Container-based testing as requested 🚀 CI/CD enhancements: - Code quality checks (flake8, black, bandit) - Database migration testing - Unit and integration tests - Docker image building and security scanning - Telegram notifications for build status - Production deployment pipeline - Scheduled maintenance tasks 🔧 Dependencies: - Added dj-database-url for DATABASE_URL parsing - Added testing dependencies (pytest, coverage) - Updated requirements.txt with all needed packages 🎯 Result: Complete Docker network isolated testing system ready for production CI/CD
This commit is contained in:
103
smartsoltech/settings_test.py
Normal file
103
smartsoltech/settings_test.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import dj_database_url
|
||||
from .settings import *
|
||||
|
||||
# Переопределяем настройки для CI/CD тестирования
|
||||
|
||||
print("ALLOWED_HOSTS:", ALLOWED_HOSTS)
|
||||
print("CSRF_TRUSTED_ORIGINS:", CSRF_TRUSTED_ORIGINS)
|
||||
print("🧪 Test settings loaded")
|
||||
|
||||
# База данных для тестирования
|
||||
DATABASES = {
|
||||
'default': dj_database_url.config(
|
||||
default=os.environ.get(
|
||||
'DATABASE_URL',
|
||||
'postgresql://postgres:postgres@postgres_test:5432/smartsoltech_test'
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
print("📊 Database:", DATABASES['default']['NAME'], "at", DATABASES['default']['HOST'])
|
||||
|
||||
# Секретный ключ для тестирования
|
||||
SECRET_KEY = os.environ.get(
|
||||
'SECRET_KEY',
|
||||
'test-secret-key-for-ci-very-long-and-secure-key-12345'
|
||||
)
|
||||
print("🔐 Secret key length:", len(SECRET_KEY))
|
||||
|
||||
# Отладка отключена в тестах
|
||||
DEBUG = os.environ.get('DEBUG', 'False').lower() in ['true', '1', 'yes']
|
||||
|
||||
# Разрешенные хосты для CI
|
||||
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1,postgres,*').split(',')
|
||||
print("🌐 Allowed hosts:", ALLOWED_HOSTS)
|
||||
|
||||
# Упрощенный хеширователь паролей для быстрых тестов
|
||||
PASSWORD_HASHERS = [
|
||||
'django.contrib.auth.hashers.MD5PasswordHasher',
|
||||
]
|
||||
|
||||
# Отключаем миграции для ускорения тестов
|
||||
class DisableMigrations:
|
||||
def __contains__(self, item):
|
||||
return True
|
||||
|
||||
def __getitem__(self, item):
|
||||
return None
|
||||
|
||||
# В CI не применяем миграции для ускорения
|
||||
if os.environ.get('CI'):
|
||||
MIGRATION_MODULES = DisableMigrations()
|
||||
|
||||
# Логирование для отладки в CI
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['console'],
|
||||
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
|
||||
},
|
||||
'web': {
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Кеширование отключено для тестов
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||
}
|
||||
}
|
||||
|
||||
# Email для тестов (console backend)
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
|
||||
# Медиа файлы для тестов
|
||||
MEDIA_ROOT = '/tmp/media_test/'
|
||||
|
||||
# Статические файлы для тестов
|
||||
STATIC_ROOT = '/tmp/static_test/'
|
||||
|
||||
# Telegram Bot настройки для тестирования
|
||||
TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN', 'test-token')
|
||||
|
||||
# Отключаем CSRF для API тестов
|
||||
if 'test' in sys.argv:
|
||||
CSRF_COOKIE_SECURE = False
|
||||
CSRF_COOKIE_HTTPONLY = False
|
||||
|
||||
# Отключаем сигналы для ускорения тестов
|
||||
if 'test' in sys.argv:
|
||||
from django.core.signals import setting_changed
|
||||
setting_changed.disconnect()
|
||||
Reference in New Issue
Block a user