No LaTeX/markdown anywhere students read (seed, import, DB migration 0021, tutor history, frontend guard); quiz of an island is fixed per user again

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 12:15:28 +03:30
parent dd10ff83f4
commit e662914efc
11 changed files with 855 additions and 670 deletions

View File

@@ -0,0 +1,25 @@
from django.core.cache import cache
from django.test import TestCase
from accounts.authentication import issue_access_token
from accounts.models import User
from ai_tutor.models import Conversation, Message
class HistoryNeverShowsLatexTests(TestCase):
def test_old_latex_message_is_cleaned_on_read(self):
cache.clear()
user = User.objects.create(phone='09120000042')
conv = Conversation.objects.create(user_id=user.id)
Message.objects.create(conversation=conv, role='user', text='حل کن $x^{2}=4$')
Message.objects.create(conversation=conv, role='assistant', text=r'جواب: \( \frac{1}{2} \vec{a} \) و **مهم** x^2')
auth = {'HTTP_AUTHORIZATION': f'Bearer {issue_access_token(user.id)}'}
r = self.client.get(f'/api/ai/conversations/{conv.id}/messages', **auth)
self.assertEqual(r.status_code, 200, r.content)
texts = [m['text'] for m in r.json()['messages']]
for t in texts:
self.assertNotIn('\\', t)
self.assertNotIn('**', t)
self.assertNotIn('^', t)
self.assertNotIn('$', t)
self.assertIn('x²', texts[0])