test_synchronizethreads.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from django.test import TestCase
  2. from django.utils.six import StringIO
  3. from misago.forums.models import Forum
  4. from misago.threads import testutils
  5. from misago.threads.management.commands import synchronizethreads
  6. class SynchronizeThreadsTests(TestCase):
  7. def test_no_threads_sync(self):
  8. """command works when there are no threads"""
  9. command = synchronizethreads.Command()
  10. out = StringIO()
  11. command.execute(stdout=out)
  12. command_output = out.getvalue().strip()
  13. self.assertEqual(command_output, 'No threads were found')
  14. def test_threads_sync(self):
  15. """command synchronizes threads"""
  16. forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
  17. threads = [testutils.post_thread(forum) for t in xrange(10)]
  18. for i, thread in enumerate(threads):
  19. [testutils.reply_thread(thread) for r in xrange(i)]
  20. thread.replies = 0
  21. thread.save()
  22. command = synchronizethreads.Command()
  23. out = StringIO()
  24. command.execute(stdout=out)
  25. for i, thread in enumerate(threads):
  26. db_thread = forum.thread_set.get(id=thread.id)
  27. self.assertEqual(db_thread.replies, i)
  28. command_output = out.getvalue().splitlines()[-1].strip()
  29. self.assertEqual(command_output, 'Synchronized 10 threads')