test_threadparticipants_view.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from django.contrib.auth import get_user_model
  2. from django.core.urlresolvers import reverse
  3. from django.utils import timezone
  4. from misago.acl.testutils import override_acl
  5. from misago.forums.models import Forum
  6. from misago.users.testutils import AuthenticatedUserTestCase
  7. from misago.threads import testutils
  8. from misago.threads.models import ThreadParticipant
  9. class ThreadParticipantsTests(AuthenticatedUserTestCase):
  10. ajax_header = {'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}
  11. def setUp(self):
  12. super(ThreadParticipantsTests, self).setUp()
  13. self.forum = Forum.objects.private_threads()
  14. self.thread = testutils.post_thread(self.forum)
  15. def test_participants_list(self):
  16. """participants list displays thread participants"""
  17. User = get_user_model()
  18. users = (
  19. User.objects.create_user("Bob", "bob@bob.com", "pass123"),
  20. User.objects.create_user("Dam", "dam@bob.com", "pass123")
  21. )
  22. ThreadParticipant.objects.set_owner(self.thread, self.user)
  23. ThreadParticipant.objects.add_participant(self.thread, users[0])
  24. ThreadParticipant.objects.add_participant(self.thread, users[1])
  25. override_acl(self.user, {
  26. 'can_use_private_threads': True,
  27. 'can_moderate_private_threads': True
  28. })
  29. link = reverse('misago:private_thread_participants', kwargs={
  30. 'thread_id': self.thread.id,
  31. 'thread_slug': self.thread.slug
  32. })
  33. response = self.client.get(link, **self.ajax_header)
  34. self.assertEqual(response.status_code, 200)
  35. owner_pos = response.content.find(self.user.get_absolute_url())
  36. for user in users:
  37. participant_pos = response.content.find(user.get_absolute_url())
  38. self.assertTrue(owner_pos < participant_pos)