26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
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])
|