test_synchronizecategories.py 1.0 KB

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