test_updatepostschecksums.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from io import StringIO
  2. from django.core.management import call_command
  3. from django.test import TestCase
  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)