test_synchronizecategories.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from django.core.management import call_command
  2. from django.test import TestCase
  3. from django.utils.six import StringIO
  4. from django.utils.six.moves import range
  5. from misago.threads import testutils
  6. from ..management.commands import synchronizecategories
  7. from ..models import Category
  8. class SynchronizeCategoriesTests(TestCase):
  9. def test_categories_sync(self):
  10. """command synchronizes categories"""
  11. category = Category.objects.all_categories()[:1][0]
  12. threads = [testutils.post_thread(category) for t in range(10)]
  13. for thread in threads:
  14. [testutils.reply_thread(thread) for r in range(5)]
  15. category.threads = 0
  16. category.posts = 0
  17. command = synchronizecategories.Command()
  18. out = StringIO()
  19. call_command(command, stdout=out)
  20. category = Category.objects.get(id=category.id)
  21. self.assertEqual(category.threads, 10)
  22. self.assertEqual(category.posts, 60)
  23. command_output = out.getvalue().splitlines()[-1].strip()
  24. self.assertEqual(command_output, 'Synchronized 3 categories')