test_unreadthreads_view.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from django.core.urlresolvers import reverse
  2. from django.utils.translation import ugettext as _
  3. from misago.forums.models import Forum
  4. from misago.users.testutils import UserTestCase, AuthenticatedUserTestCase
  5. from misago.threads import testutils
  6. class AuthenticatedTests(AuthenticatedUserTestCase):
  7. def test_empty_threads_list(self):
  8. """empty threads list is rendered"""
  9. response = self.client.get(reverse('misago:unread_threads'))
  10. self.assertEqual(response.status_code, 200)
  11. self.assertIn("There are no threads from last", response.content)
  12. def test_filled_threads_list(self):
  13. """filled threads list is rendered"""
  14. forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
  15. threads = [testutils.post_thread(forum) for t in xrange(10)]
  16. # only unread tracker threads are shown on unread list
  17. response = self.client.get(reverse('misago:unread_threads'))
  18. self.assertEqual(response.status_code, 200)
  19. self.assertIn("There are no threads from last", response.content)
  20. # we'll read and reply to first five threads
  21. for thread in threads[5:]:
  22. response = self.client.get(thread.get_absolute_url())
  23. testutils.reply_thread(thread)
  24. # assert that replied threads show on list
  25. response = self.client.get(reverse('misago:unread_threads'))
  26. self.assertEqual(response.status_code, 200)
  27. for thread in threads[5:]:
  28. self.assertIn(thread.get_absolute_url(), response.content)
  29. for thread in threads[:5]:
  30. self.assertNotIn(thread.get_absolute_url(), response.content)
  31. class AnonymousTests(UserTestCase):
  32. def test_anon_access_to_view(self):
  33. """anonymous user has no access to unread threads list"""
  34. response = self.client.get(reverse('misago:unread_threads'))
  35. self.assertEqual(response.status_code, 403)
  36. self.assertIn(_("You have to sign in to see your list of "
  37. "threads with unread replies."),
  38. response.content)