Files
igny8/backend/test_field_rename.py
2025-11-26 15:12:14 +00:00

139 lines
5.4 KiB
Python

#!/usr/bin/env python
"""
Test script to verify field rename is complete
Run after SQL migration: python manage.py shell < test_field_rename.py
"""
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
django.setup()
from igny8_core.business.planning.models import ContentIdeas
from igny8_core.business.content.models import Tasks, Content
from django.db import connection
def test_models():
"""Test that models can access new field names"""
print("\n=== Testing Model Field Access ===")
# Test ContentIdeas
try:
idea = ContentIdeas.objects.first()
if idea:
print(f"✓ ContentIdeas.content_type: {idea.content_type}")
print(f"✓ ContentIdeas.content_structure: {idea.content_structure}")
else:
print("⚠ No ContentIdeas records to test")
except Exception as e:
print(f"✗ ContentIdeas error: {e}")
# Test Tasks
try:
task = Tasks.objects.first()
if task:
print(f"✓ Tasks.content_type: {task.content_type}")
print(f"✓ Tasks.content_structure: {task.content_structure}")
else:
print("⚠ No Tasks records to test")
except Exception as e:
print(f"✗ Tasks error: {e}")
# Test Content
try:
content = Content.objects.first()
if content:
print(f"✓ Content.content_type: {content.content_type}")
print(f"✓ Content.content_structure: {content.content_structure}")
print(f"✓ Content.content_html: {len(content.content_html) if content.content_html else 0} chars")
else:
print("⚠ No Content records to test")
except Exception as e:
print(f"✗ Content error: {e}")
def test_database_columns():
"""Verify database columns exist"""
print("\n=== Testing Database Column Names ===")
with connection.cursor() as cursor:
# Check igny8_content_ideas
cursor.execute("""
SELECT column_name FROM information_schema.columns
WHERE table_name = 'igny8_content_ideas'
AND column_name IN ('content_type', 'content_structure', 'site_entity_type', 'cluster_role')
ORDER BY column_name
""")
cols = [row[0] for row in cursor.fetchall()]
print(f"igny8_content_ideas columns: {cols}")
if 'content_type' in cols and 'content_structure' in cols:
print("✓ ContentIdeas: new columns exist")
if 'site_entity_type' in cols or 'cluster_role' in cols:
print("✗ ContentIdeas: old columns still exist")
# Check igny8_tasks
cursor.execute("""
SELECT column_name FROM information_schema.columns
WHERE table_name = 'igny8_tasks'
AND column_name IN ('content_type', 'content_structure', 'entity_type', 'cluster_role')
ORDER BY column_name
""")
cols = [row[0] for row in cursor.fetchall()]
print(f"igny8_tasks columns: {cols}")
if 'content_type' in cols and 'content_structure' in cols:
print("✓ Tasks: new columns exist")
if 'entity_type' in cols or 'cluster_role' in cols:
print("✗ Tasks: old columns still exist")
# Check igny8_content
cursor.execute("""
SELECT column_name FROM information_schema.columns
WHERE table_name = 'igny8_content'
AND column_name IN ('content_type', 'content_structure', 'content_html', 'entity_type', 'cluster_role', 'html_content')
ORDER BY column_name
""")
cols = [row[0] for row in cursor.fetchall()]
print(f"igny8_content columns: {cols}")
if 'content_type' in cols and 'content_structure' in cols and 'content_html' in cols:
print("✓ Content: new columns exist")
if 'entity_type' in cols or 'cluster_role' in cols or 'html_content' in cols:
print("✗ Content: old columns still exist")
def test_choices():
"""Test that CHOICES are correctly defined"""
print("\n=== Testing Model CHOICES ===")
print(f"ContentIdeas.CONTENT_TYPE_CHOICES: {len(ContentIdeas.CONTENT_TYPE_CHOICES)} types")
print(f"ContentIdeas.CONTENT_STRUCTURE_CHOICES: {len(ContentIdeas.CONTENT_STRUCTURE_CHOICES)} structures")
print(f"Tasks.CONTENT_TYPE_CHOICES: {len(Tasks.CONTENT_TYPE_CHOICES)} types")
print(f"Tasks.CONTENT_STRUCTURE_CHOICES: {len(Tasks.CONTENT_STRUCTURE_CHOICES)} structures")
print(f"Content.CONTENT_TYPE_CHOICES: {len(Content.CONTENT_TYPE_CHOICES)} types")
print(f"Content.CONTENT_STRUCTURE_CHOICES: {len(Content.CONTENT_STRUCTURE_CHOICES)} structures")
# Verify all 14 structures are present
all_structures = [s[0] for s in Tasks.CONTENT_STRUCTURE_CHOICES]
expected = ['article', 'guide', 'comparison', 'review', 'listicle',
'landing_page', 'business_page', 'service_page', 'general', 'cluster_hub',
'product_page', 'category_archive', 'tag_archive', 'attribute_archive']
for struct in expected:
if struct in all_structures:
print(f"{struct}")
else:
print(f"✗ Missing: {struct}")
if __name__ == '__main__':
print("="*60)
print("Field Rename Validation Test")
print("="*60)
test_models()
test_database_columns()
test_choices()
print("\n" + "="*60)
print("Test Complete")
print("="*60)