test_synchronizecategories.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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.categories.management.commands import synchronizecategories
  6. from misago.categories.models import Category
  7. from misago.threads import testutils
  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 _ in range(10)]
  13. for thread in threads:
  14. [testutils.reply_thread(thread) for _ 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')