|
@@ -7,9 +7,9 @@ from ..models import ThreadParticipant
|
|
|
from .test_privatethreads import PrivateThreadsTestCase
|
|
|
|
|
|
|
|
|
-class PrivateThreadsApiTests(PrivateThreadsTestCase):
|
|
|
+class PrivateThreadsApiListTests(PrivateThreadsTestCase):
|
|
|
def setUp(self):
|
|
|
- super(PrivateThreadsApiTests, self).setUp()
|
|
|
+ super(PrivateThreadsApiListTests, self).setUp()
|
|
|
|
|
|
self.api_link = reverse('misago:api:private-thread-list')
|
|
|
|
|
@@ -69,55 +69,73 @@ class PrivateThreadsApiTests(PrivateThreadsTestCase):
|
|
|
self.assertEqual(response_json['results'][1]['id'], visible.id)
|
|
|
|
|
|
|
|
|
-class PrivateThreadsListTests(PrivateThreadsTestCase):
|
|
|
+class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
def setUp(self):
|
|
|
- super(PrivateThreadsListTests, self).setUp()
|
|
|
+ super(PrivateThreadsApiGetTests, self).setUp()
|
|
|
|
|
|
- self.test_link = reverse('misago:private-threads')
|
|
|
+ self.thread = testutils.post_thread(self.category, poster=self.user)
|
|
|
+ self.api_url = self.thread.get_api_url()
|
|
|
|
|
|
- def test_unauthenticated(self):
|
|
|
- """view requires user to sign in and be able to access it"""
|
|
|
+ def test_anonymous(self):
|
|
|
+ """anonymous user can't see private thread"""
|
|
|
self.logout_user()
|
|
|
|
|
|
- response = self.client.get(self.test_link)
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
self.assertContains(response, "sign in to use private threads", status_code=403)
|
|
|
|
|
|
def test_no_permission(self):
|
|
|
- """view requires user to have permission to be able to access it"""
|
|
|
+ """user needs to have permission to see private thread"""
|
|
|
override_acl(self.user, {
|
|
|
'can_use_private_threads': 0
|
|
|
})
|
|
|
|
|
|
- response = self.client.get(self.test_link)
|
|
|
- self.assertContains(response, "use private threads", status_code=403)
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertContains(response, "t use private threads", status_code=403)
|
|
|
|
|
|
- def test_empty_list(self):
|
|
|
- """view has no showstoppers on returning empty list"""
|
|
|
- response = self.client.get(self.test_link)
|
|
|
- self.assertEqual(response.status_code, 200)
|
|
|
- self.assertContains(response, "empty-message")
|
|
|
+ def test_no_participant(self):
|
|
|
+ """user cant see thread he isn't part of"""
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
- def test_thread_visibility(self):
|
|
|
- """only participated threads are returned by private threads view"""
|
|
|
- visible = testutils.post_thread(category=self.category, poster=self.user)
|
|
|
- hidden = testutils.post_thread(category=self.category, poster=self.user)
|
|
|
- reported = testutils.post_thread(category=self.category, poster=self.user)
|
|
|
+ def test_mod_not_reported(self):
|
|
|
+ """moderator can't see private thread that has no reports"""
|
|
|
+ override_acl(self.user, {
|
|
|
+ 'can_moderate_private_threads': 1
|
|
|
+ })
|
|
|
|
|
|
- ThreadParticipant.objects.add_participants(visible, [self.user])
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
- reported.has_reported_posts = True
|
|
|
- reported.save()
|
|
|
+ def test_reported_not_mod(self):
|
|
|
+ """non-mod can't see private thread that has reported posts"""
|
|
|
+ self.thread.has_reported_posts = True
|
|
|
+ self.thread.save()
|
|
|
|
|
|
- response = self.client.get(self.test_link)
|
|
|
- self.assertEqual(response.status_code, 200)
|
|
|
- self.assertContains(response, visible.get_absolute_url())
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
- # threads with reported posts will also show to moderators
|
|
|
+ def test_can_see_owner(self):
|
|
|
+ """user can see thread he is owner of"""
|
|
|
+ ThreadParticipant.objects.set_owner(self.thread, self.user)
|
|
|
+
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertContains(response, self.thread.title)
|
|
|
+
|
|
|
+ def test_can_see_participant(self):
|
|
|
+ """user can see thread he is participant of"""
|
|
|
+ ThreadParticipant.objects.add_participants(self.thread, [self.user])
|
|
|
+
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertContains(response, self.thread.title)
|
|
|
+
|
|
|
+ def test_mod_can_see_reported(self):
|
|
|
+ """moderator can see private thread that has reports"""
|
|
|
override_acl(self.user, {
|
|
|
'can_moderate_private_threads': 1
|
|
|
})
|
|
|
|
|
|
- response = self.client.get(self.test_link)
|
|
|
- self.assertEqual(response.status_code, 200)
|
|
|
- self.assertContains(response, reported.get_absolute_url())
|
|
|
- self.assertContains(response, visible.get_absolute_url())
|
|
|
+ self.thread.has_reported_posts = True
|
|
|
+ self.thread.save()
|
|
|
+
|
|
|
+ response = self.client.get(self.api_url)
|
|
|
+ self.assertContains(response, self.thread.title)
|