Files
MathApp/ai_tutor/tests_plain_history.py

34 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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])
class ToPlainSubscriptTests(TestCase):
def test_bare_subscripts_are_unicode(self):
from rag.services.mathtext import to_plain
out = to_plain('S_n = n/2 × (a_1 + a_n)')
self.assertNotIn('_', out)
self.assertIn('Sₙ', out)