test_synchronizecategories.py 1.1 KB

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