test_goto_views.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from misago.acl import add_acl
  2. from misago.acl.testutils import override_acl
  3. from misago.forums.models import Forum
  4. from misago.users.testutils import AuthenticatedUserTestCase
  5. from misago.threads import goto
  6. from misago.threads.testutils import post_thread, reply_thread
  7. class GotoViewsTests(AuthenticatedUserTestCase):
  8. def setUp(self):
  9. super(GotoViewsTests, self).setUp()
  10. self.forum = Forum.objects.all_forums().filter(role="forum")[:1][0]
  11. self.forum.labels = []
  12. self.thread = post_thread(self.forum)
  13. add_acl(self.user, self.forum)
  14. add_acl(self.user, self.thread)
  15. def override_acl(self, new_acl):
  16. new_acl.update({'can_see': True, 'can_browse': True})
  17. forums_acl = self.user.acl
  18. forums_acl['visible_forums'].append(self.forum.pk)
  19. forums_acl['forums'][self.forum.pk].update(new_acl)
  20. override_acl(self.user, forums_acl)
  21. def test_goto_last(self):
  22. """thread_last link points to last post in thread"""
  23. response = self.client.get(self.thread.get_last_reply_url())
  24. self.assertEqual(response.status_code, 302)
  25. self.assertTrue(
  26. response['location'].endswith(goto.last(self.user, self.thread)))
  27. # add 36 posts to thread
  28. [reply_thread(self.thread) for p in xrange(36)]
  29. response = self.client.get(self.thread.get_last_reply_url())
  30. self.assertEqual(response.status_code, 302)
  31. self.assertTrue(
  32. response['location'].endswith(goto.last(self.user, self.thread)))
  33. def test_goto_new(self):
  34. """thread_new link points to first unread post in thread"""
  35. # add 32 posts to thread
  36. [reply_thread(self.thread) for p in xrange(32)]
  37. # read thread
  38. response = self.client.get(self.thread.get_last_reply_url())
  39. response = self.client.get(response['location'])
  40. # add unread posts
  41. unread_post = reply_thread(self.thread)
  42. [reply_thread(self.thread) for p in xrange(32)]
  43. unread_post_link = goto.new(self.user, self.thread)
  44. response = self.client.get(self.thread.get_new_reply_url())
  45. self.assertEqual(response.status_code, 302)
  46. self.assertTrue(response['location'].endswith(unread_post_link))
  47. def test_goto_reported(self):
  48. """thread_reported link points to first reported post in thread"""
  49. # add 32 posts to thread
  50. [reply_thread(self.thread) for p in xrange(32)]
  51. # add reported post to thread
  52. reported_post = reply_thread(self.thread, is_reported=True)
  53. # add 32 more posts to thread
  54. [reply_thread(self.thread) for p in xrange(32)]
  55. # see reported post link
  56. self.override_acl({'can_see_reports': 1})
  57. reported_post_link = goto.post(self.user, self.thread, reported_post)
  58. self.override_acl({'can_see_reports': 1})
  59. response = self.client.get(self.thread.get_reported_reply_url())
  60. self.assertEqual(response.status_code, 302)
  61. self.assertTrue(response['location'].endswith(reported_post_link))
  62. def test_goto_moderated(self):
  63. """thread_moderated link points to first moderated post in thread"""
  64. # add 32 posts to thread
  65. [reply_thread(self.thread) for p in xrange(32)]
  66. # add moderated post to thread
  67. moderated_post = reply_thread(self.thread, is_moderated=True)
  68. # add 32 more posts to thread
  69. [reply_thread(self.thread) for p in xrange(32)]
  70. # see moderated post link
  71. self.override_acl({'can_review_moderated_content': 1})
  72. moderated_post_link = goto.post(self.user, self.thread, moderated_post)
  73. response = self.client.get(self.thread.get_moderated_reply_url())
  74. self.assertEqual(response.status_code, 302)
  75. self.assertTrue(response['location'].endswith(moderated_post_link))
  76. def test_goto_post(self):
  77. """thread_post link points to specific post in thread"""
  78. # add 32 posts to thread
  79. [reply_thread(self.thread) for p in xrange(32)]
  80. # add target post to thread
  81. target_post = reply_thread(self.thread)
  82. # add 32 more posts to thread
  83. [reply_thread(self.thread) for p in xrange(32)]
  84. # see post link
  85. post_link = goto.post(self.user, self.thread, target_post)
  86. response = self.client.get(target_post.get_absolute_url())
  87. self.assertEqual(response.status_code, 302)
  88. self.assertTrue(response['location'].endswith(post_link))