-test_unreadthreads_view.py 2.4 KB

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