test_unreadthreads_view.py 2.0 KB

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