import os import sys import django import logging # Настройка логирования logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') # Добавляем путь к проекту sys.path.insert(0, 'C:/Users/team_/Desktop/test_qwen/myproject') # Настройка Django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') django.setup() from tenants.models import TenantRegistration, Client from django.contrib.auth import get_user_model from django.db import connection from tenants.admin import TenantRegistrationAdmin # Создаём новую заявку registration = TenantRegistration.objects.create( shop_name='Test Shop 5', schema_name='shop5', owner_email='shop5@example.com', owner_name='Jane Doe', phone='+375291234567', status=TenantRegistration.STATUS_PENDING ) print(f"\n=== Testing Superuser Creation ===") print(f"Created registration: {registration.id} for {registration.schema_name}\n") # Одобряем заявку admin = TenantRegistrationAdmin(TenantRegistration, None) User = get_user_model() # Получаем системного пользователя public_tenant = Client.objects.get(schema_name='public') connection.set_tenant(public_tenant) try: admin_user = User.objects.get(email='admin@localhost') except User.DoesNotExist: admin_user = User.objects.create_superuser( email='admin@localhost', name='Admin', password='admin' ) try: print("Approving registration...") admin._approve_registration(registration, admin_user) print("\nApproval completed!\n") # Проверяем, был ли создан суперпользователь в новом тенанте registration.refresh_from_db() tenant = registration.tenant print(f"Tenant created: {tenant.name} ({tenant.schema_name})") # Переключаемся на новый тенант и проверяем пользователей connection.set_tenant(tenant) superusers = User.objects.filter(is_superuser=True) print(f"\nSuperusers in {tenant.schema_name} schema:") if superusers.exists(): for su in superusers: print(f" OK: {su.email} ({su.name})") else: print(" FAIL: No superusers found!") # Проверим ВСЕ пользователей all_users = User.objects.all() print(f"\nAll users in {tenant.schema_name} schema:") if all_users.exists(): for u in all_users: print(f" - {u.email} (superuser={u.is_superuser})") else: print(" - No users found at all!") except Exception as e: print(f"Error during approval: {str(e)}") import traceback traceback.print_exc()