test_synchronizeforums.py 992 B

1234567891011121314151617181920212223242526272829303132
  1. from django.test import TestCase
  2. from django.utils.six import StringIO
  3. from misago.threads import testutils
  4. from misago.forums.management.commands import synchronizeforums
  5. from misago.forums.models import Forum
  6. class SynchronizeForumsTests(TestCase):
  7. def test_forumss_sync(self):
  8. """command synchronizes forums"""
  9. forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
  10. threads = [testutils.post_thread(forum) for t in xrange(10)]
  11. for thread in threads:
  12. [testutils.reply_thread(thread) for r in xrange(5)]
  13. forum.threads = 0
  14. forum.posts = 0
  15. command = synchronizeforums.Command()
  16. out = StringIO()
  17. command.execute(stdout=out)
  18. forum = Forum.objects.get(id=forum.id)
  19. self.assertEqual(forum.threads, 10)
  20. self.assertEqual(forum.posts, 60)
  21. command_output = out.getvalue().splitlines()[-1].strip()
  22. self.assertEqual(command_output, 'Synchronized 5 forums')