#!/usr/bin/env python """Test Django settings with apps added incrementally""" import os import sys from pathlib import Path # Base settings template base_settings = """ import os from pathlib import Path BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = 'test-key' DEBUG = True ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', {apps} ] DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'test.db.sqlite3', } } """ # Apps to test apps_to_test = [ "'dokumente'", "'abschnitte'", "'stichworte'", "'referenzen'", "'rollen'", "'mptt'", "'pages'", "'nested_admin'", "'revproxy'", ] # Test apps incrementally current_apps = "" for i, app in enumerate(apps_to_test): print(f"\n=== Testing with apps {i+1}/{len(apps_to_test)}: {app} ===") # Add the next app if current_apps: current_apps += ",\n " + app else: current_apps = app # Write settings file settings_content = base_settings.format(apps=current_apps) with open('test_settings.py', 'w') as f: f.write(settings_content) # Test the settings os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings') try: # Clear Django's internal cache if 'django.conf' in sys.modules: del sys.modules['django.conf'] if 'django.conf.settings' in sys.modules: del sys.modules['django.conf.settings'] if 'test_settings' in sys.modules: del sys.modules['test_settings'] import django from django.conf import settings # Reset Django if hasattr(settings, '_wrapped'): settings._wrapped = None django.setup() print(f"✓ SUCCESS: Apps up to {app} work fine") except Exception as e: print(f"✗ FAILED: Error with {app}: {e}") break # Clean up import os if os.path.exists('test_settings.py'): os.remove('test_settings.py') if os.path.exists('test.db.sqlite3'): os.remove('test.db.sqlite3')