Files
MathApp/content/tests_ordering.py

23 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.test import TestCase
from content.models import Choice, Grade, Lesson, Node, Question, Unit
class StableOrderTests(TestCase):
"""گزارشِ مالک ۲۰۲۶-۱۰-۱۵: درسِ اولِ جزیره بعد از دیپلوی عوض شد، چون Lesson ترتیبِ صریح نداشت
و Postgres سطرهای ویرایش‌شده را جابه‌جا برمی‌گرداند. SQLite سطرها را به ترتیبِ id برمی‌گرداند و
این باگ را نشان نمی‌دهد؛ پس خودِ ORDER BY را بررسی می‌کنیم."""
def test_content_querysets_have_explicit_order(self):
for qs in (Lesson.objects.all(), Question.objects.all(), Choice.objects.all()):
self.assertIn('ORDER BY', str(qs.query), qs.model.__name__)
self.assertEqual(qs.model._meta.ordering[-1], 'id')
def test_lessons_come_back_in_creation_order_after_updates(self):
grade = Grade.objects.create(title='پایه', number=99)
unit = Unit.objects.create(grade=grade, title='فصل', order=1)
node = Node.objects.create(unit=unit, title='جزیره', order=1)
ids = [Lesson.objects.create(node=node, title=f'درس {i}').id for i in range(5)]
Lesson.objects.filter(pk=ids[0]).update(title='ویرایش‌شده')
self.assertEqual([l.id for l in node.lessons.all()], ids)