85 lines
3.0 KiB
Python
85 lines
3.0 KiB
Python
"""
|
|
Test for Bug #65 fix: OperationalError (1366) Incorrect string value for emoji in prompt.
|
|
|
|
Verifies that GenerationRecord.prompt can store 4-byte UTF-8 characters (emoji).
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
|
os.environ.setdefault('TESTING', 'true')
|
|
django.setup()
|
|
|
|
from django.test import TestCase
|
|
from django.contrib.auth import get_user_model
|
|
from apps.generation.models import GenerationRecord
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class Bug65EmojiPromptTest(TestCase):
|
|
"""Test that prompts with emoji characters can be saved to the database."""
|
|
|
|
def setUp(self):
|
|
self.user = User.objects.create_user(
|
|
username='testuser_bug65',
|
|
email='bug65@test.com',
|
|
password='testpass123',
|
|
)
|
|
|
|
def test_prompt_with_emoji_saves_successfully(self):
|
|
"""Bug #65: prompt containing 🔊 (4-byte UTF-8) should not raise OperationalError."""
|
|
emoji_prompt = '🔊 这是一个包含emoji的提示词 🎬🎥✨'
|
|
record = GenerationRecord.objects.create(
|
|
user=self.user,
|
|
prompt=emoji_prompt,
|
|
mode='universal',
|
|
model='seedance_2.0',
|
|
aspect_ratio='16:9',
|
|
duration=5,
|
|
)
|
|
record.refresh_from_db()
|
|
self.assertEqual(record.prompt, emoji_prompt)
|
|
|
|
def test_prompt_with_mixed_unicode(self):
|
|
"""Prompt with mixed CJK + emoji + ASCII should save correctly."""
|
|
mixed_prompt = '🔊 大象在草原上奔跑 🐘 — cinematic 4K, slow-motion 🎬'
|
|
record = GenerationRecord.objects.create(
|
|
user=self.user,
|
|
prompt=mixed_prompt,
|
|
mode='universal',
|
|
model='seedance_2.0',
|
|
aspect_ratio='16:9',
|
|
duration=5,
|
|
)
|
|
record.refresh_from_db()
|
|
self.assertEqual(record.prompt, mixed_prompt)
|
|
|
|
def test_prompt_with_only_basic_text(self):
|
|
"""Ensure basic text still works after the charset change."""
|
|
basic_prompt = '一只猫在跑步'
|
|
record = GenerationRecord.objects.create(
|
|
user=self.user,
|
|
prompt=basic_prompt,
|
|
mode='universal',
|
|
model='seedance_2.0',
|
|
aspect_ratio='16:9',
|
|
duration=5,
|
|
)
|
|
record.refresh_from_db()
|
|
self.assertEqual(record.prompt, basic_prompt)
|
|
|
|
def test_settings_mysql_charset(self):
|
|
"""Verify MySQL OPTIONS includes utf8mb4 charset and SET NAMES utf8mb4."""
|
|
from django.conf import settings
|
|
# Only check if MySQL config is present (prod uses MySQL, test uses SQLite)
|
|
db_config = settings.DATABASES.get('default', {})
|
|
if db_config.get('ENGINE', '').endswith('mysql'):
|
|
options = db_config.get('OPTIONS', {})
|
|
self.assertEqual(options.get('charset'), 'utf8mb4')
|
|
self.assertIn('SET NAMES utf8mb4', options.get('init_command', ''))
|