#!/usr/bin/env python """ Prostoy test skript dlya proverki ConfigurableKitOptionAttribute bez Unicode simvolov """ import os import sys import django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') django.setup() from products.models.kits import ( ConfigurableKitProduct, ConfigurableKitOption, ConfigurableKitProductAttribute, ConfigurableKitOptionAttribute, ProductKit ) from django_tenants.utils import tenant_context from tenants.models import Client try: client = Client.objects.get(schema_name='grach') print(f"OK: Found tenant: {client.name} (schema: {client.schema_name})\n") except Client.DoesNotExist: print("ERROR: Tenant 'grach' not found") print("Available tenants:") for c in Client.objects.all(): print(f" - {c.name} ({c.schema_name})") sys.exit(1) with tenant_context(client): print("=" * 70) print("TEST: ConfigurableKitOptionAttribute M2M Model") print("=" * 70) # Test 1: Check models exist print("\n1. Checking if models exist...") try: # Try to get a ConfigurableKitProduct products = ConfigurableKitProduct.objects.filter(name__icontains="test").first() if products: print(f" OK: Found ConfigurableKitProduct: {products.name}") else: print(" INFO: No test ConfigurableKitProduct found") # Check ConfigurableKitProductAttribute exists attrs = ConfigurableKitProductAttribute.objects.all() print(f" OK: ConfigurableKitProductAttribute model exists. Count: {attrs.count()}") # Check ConfigurableKitOptionAttribute exists opt_attrs = ConfigurableKitOptionAttribute.objects.all() print(f" OK: ConfigurableKitOptionAttribute model exists. Count: {opt_attrs.count()}") except Exception as e: print(f" ERROR: {e}") import traceback traceback.print_exc() sys.exit(1) # Test 2: Check M2M relationships print("\n2. Checking M2M relationships...") try: # Get a sample variant option = ConfigurableKitOption.objects.first() if option: print(f" OK: Found option: {option.id} for parent: {option.parent.name}") # Check if we can access attributes_set attr_set = option.attributes_set.all() print(f" OK: Can access attributes_set. Count: {attr_set.count()}") # Check if we can reverse access if attr_set.exists(): opt_attr = attr_set.first() print(f" OK: Can access option_attr.option: {opt_attr.option.id}") print(f" OK: Can access option_attr.attribute: {opt_attr.attribute.id}") else: print(" INFO: No ConfigurableKitOption found") except Exception as e: print(f" ERROR: {e}") import traceback traceback.print_exc() sys.exit(1) # Test 3: Check form validation logic print("\n3. Checking form validation setup...") try: from products.forms import ConfigurableKitOptionForm # Create a test form with instance option = ConfigurableKitOption.objects.filter( parent__parent_attributes__isnull=False ).first() if option: form = ConfigurableKitOptionForm(instance=option) print(f" OK: Form created for option with parent: {option.parent.name}") # Check dynamically generated fields dynamic_fields = [f for f in form.fields if f.startswith('attribute_')] print(f" OK: Found {len(dynamic_fields)} dynamic attribute fields:") for field_name in dynamic_fields: print(f" - {field_name}") else: print(" INFO: No option with parent attributes found") except Exception as e: print(f" ERROR: {e}") import traceback traceback.print_exc() sys.exit(1) # Test 4: Check view integration print("\n4. Checking view imports...") try: from products.views.configurablekit_views import ( ConfigurableKitProductCreateView, ConfigurableKitProductUpdateView ) print(" OK: Views imported successfully") print(" OK: ConfigurableKitProductCreateView available") print(" OK: ConfigurableKitProductUpdateView available") except Exception as e: print(f" ERROR: {e}") import traceback traceback.print_exc() sys.exit(1) print("\n" + "=" * 70) print("OK: ALL TESTS PASSED! Implementation is ready for testing.") print("=" * 70)