test_updatepostschecksums.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.core.management import call_command
  2. from django.test import TestCase
  3. from django.utils.six import StringIO
  4. from misago.categories.models import Category
  5. from misago.threads import testutils
  6. from misago.threads.management.commands import updatepostschecksums
  7. from misago.threads.models import Post
  8. class UpdatePostsChecksumsTests(TestCase):
  9. def test_no_posts_to_update(self):
  10. """command works when there are no posts"""
  11. command = updatepostschecksums.Command()
  12. out = StringIO()
  13. call_command(command, stdout=out)
  14. command_output = out.getvalue().strip()
  15. self.assertEqual(command_output, "No posts were found")
  16. def test_posts_update(self):
  17. """command updates posts checksums"""
  18. category = Category.objects.all_categories()[:1][0]
  19. threads = [testutils.post_thread(category) for _ in range(5)]
  20. for _, thread in enumerate(threads):
  21. [testutils.reply_thread(thread) for _ in range(3)]
  22. thread.save()
  23. Post.objects.update(parsed='Hello world!')
  24. for post in Post.objects.all():
  25. self.assertFalse(post.is_valid)
  26. command = updatepostschecksums.Command()
  27. out = StringIO()
  28. call_command(command, stdout=out)
  29. command_output = out.getvalue().splitlines()[-1].strip()
  30. self.assertEqual(command_output, "Updated 20 posts checksums")
  31. for post in Post.objects.all():
  32. self.assertTrue(post.is_valid)