test_goto_views.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from misago.acl import add_acl
  2. from misago.forums.models import Forum
  3. from misago.users.testutils import AuthenticatedUserTestCase
  4. from misago.threads import goto
  5. from misago.threads.testutils import post_thread, reply_thread
  6. class GotoViewsTests(AuthenticatedUserTestCase):
  7. def setUp(self):
  8. super(GotoViewsTests, self).setUp()
  9. self.forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
  10. self.forum.labels = []
  11. self.thread = post_thread(self.forum)
  12. add_acl(self.user, self.forum)
  13. add_acl(self.user, self.thread)
  14. def test_goto_last(self):
  15. """thread_last link points to last post in thread"""
  16. response = self.client.get(self.thread.get_last_reply_url())
  17. self.assertEqual(response.status_code, 302)
  18. last_link = goto.last(self.thread, self.thread.post_set)
  19. self.assertTrue(response['location'].endswith(last_link))
  20. # add 36 posts to thread
  21. [reply_thread(self.thread) for p in xrange(36)]
  22. response = self.client.get(self.thread.get_last_reply_url())
  23. self.assertEqual(response.status_code, 302)
  24. last_link = goto.last(self.thread, self.thread.post_set)
  25. self.assertTrue(response['location'].endswith(last_link))
  26. def test_goto_new(self):
  27. """thread_new link points to first unread post in thread"""
  28. # add 32 posts to thread
  29. [reply_thread(self.thread) for p in xrange(32)]
  30. # read thread
  31. response = self.client.get(self.thread.get_last_reply_url())
  32. response = self.client.get(response['location'])
  33. # add unread posts
  34. unread_post = reply_thread(self.thread)
  35. [reply_thread(self.thread) for p in xrange(32)]
  36. response = self.client.get(self.thread.get_new_reply_url())
  37. self.assertEqual(response.status_code, 302)
  38. unread_link = goto.new(self.user, self.thread, self.thread.post_set)
  39. self.assertTrue(response['location'].endswith(unread_link))
  40. def test_goto_post(self):
  41. """thread_post link points to specific post in thread"""
  42. # add 32 posts to thread
  43. [reply_thread(self.thread) for p in xrange(32)]
  44. # add target post to thread
  45. target_post = reply_thread(self.thread)
  46. # add 32 more posts to thread
  47. [reply_thread(self.thread) for p in xrange(32)]
  48. # see post link
  49. post_link = goto.post(self.thread, self.thread.post_set, target_post)
  50. response = self.client.get(target_post.get_absolute_url())
  51. self.assertEqual(response.status_code, 302)
  52. self.assertTrue(response['location'].endswith(post_link))