test_goto_views.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. self.assertTrue(
  19. response['location'].endswith(goto.last(self.user, self.thread)))
  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. self.assertTrue(
  25. response['location'].endswith(goto.last(self.user, self.thread)))
  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. unread_post_link = goto.new(self.user, self.thread)
  37. response = self.client.get(self.thread.get_new_reply_url())
  38. self.assertEqual(response.status_code, 302)
  39. self.assertTrue(response['location'].endswith(unread_post_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.user, self.thread, 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))