|
@@ -3,13 +3,13 @@ from django.urls import reverse
|
|
|
from misago.acl.testutils import override_acl
|
|
|
|
|
|
from .. import testutils
|
|
|
-from ..models import ThreadParticipant
|
|
|
+from ..models import Thread, ThreadParticipant
|
|
|
from .test_privatethreads import PrivateThreadsTestCase
|
|
|
|
|
|
|
|
|
-class PrivateThreadsApiListTests(PrivateThreadsTestCase):
|
|
|
+class PrivateThreadsListApiTests(PrivateThreadsTestCase):
|
|
|
def setUp(self):
|
|
|
- super(PrivateThreadsApiListTests, self).setUp()
|
|
|
+ super(PrivateThreadsListApiTests, self).setUp()
|
|
|
|
|
|
self.api_link = reverse('misago:api:private-thread-list')
|
|
|
|
|
@@ -69,18 +69,18 @@ class PrivateThreadsApiListTests(PrivateThreadsTestCase):
|
|
|
self.assertEqual(response_json['results'][1]['id'], visible.id)
|
|
|
|
|
|
|
|
|
-class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
+class PrivateThreadRetrieveApiTests(PrivateThreadsTestCase):
|
|
|
def setUp(self):
|
|
|
- super(PrivateThreadsApiGetTests, self).setUp()
|
|
|
+ super(PrivateThreadRetrieveApiTests, self).setUp()
|
|
|
|
|
|
self.thread = testutils.post_thread(self.category, poster=self.user)
|
|
|
- self.api_url = self.thread.get_api_url()
|
|
|
+ self.api_link = self.thread.get_api_url()
|
|
|
|
|
|
def test_anonymous(self):
|
|
|
"""anonymous user can't see private thread"""
|
|
|
self.logout_user()
|
|
|
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertContains(response, "sign in to use private threads", status_code=403)
|
|
|
|
|
|
def test_no_permission(self):
|
|
@@ -89,12 +89,12 @@ class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
'can_use_private_threads': 0
|
|
|
})
|
|
|
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertContains(response, "t use private threads", status_code=403)
|
|
|
|
|
|
def test_no_participant(self):
|
|
|
"""user cant see thread he isn't part of"""
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
def test_mod_not_reported(self):
|
|
@@ -103,7 +103,7 @@ class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
'can_moderate_private_threads': 1
|
|
|
})
|
|
|
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
def test_reported_not_mod(self):
|
|
@@ -111,14 +111,14 @@ class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
self.thread.has_reported_posts = True
|
|
|
self.thread.save()
|
|
|
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
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)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
response_json = response.json()
|
|
@@ -137,7 +137,7 @@ class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
"""user can see thread he is participant of"""
|
|
|
ThreadParticipant.objects.add_participants(self.thread, [self.user])
|
|
|
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
response_json = response.json()
|
|
@@ -161,9 +161,51 @@ class PrivateThreadsApiGetTests(PrivateThreadsTestCase):
|
|
|
self.thread.has_reported_posts = True
|
|
|
self.thread.save()
|
|
|
|
|
|
- response = self.client.get(self.api_url)
|
|
|
+ response = self.client.get(self.api_link)
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
response_json = response.json()
|
|
|
self.assertEqual(response_json['title'], self.thread.title)
|
|
|
self.assertEqual(response_json['participants'], [])
|
|
|
+
|
|
|
+
|
|
|
+class PrivateThreadDeleteApiTests(PrivateThreadsTestCase):
|
|
|
+ def setUp(self):
|
|
|
+ super(PrivateThreadDeleteApiTests, self).setUp()
|
|
|
+
|
|
|
+ self.thread = testutils.post_thread(self.category, poster=self.user)
|
|
|
+ self.api_link = self.thread.get_api_url()
|
|
|
+
|
|
|
+ ThreadParticipant.objects.add_participants(self.thread, [self.user])
|
|
|
+
|
|
|
+ def test_delete_thread_no_permission(self):
|
|
|
+ """DELETE to API link with no permission to delete fails"""
|
|
|
+ self.override_acl({
|
|
|
+ 'can_hide_threads': 1
|
|
|
+ })
|
|
|
+
|
|
|
+ response = self.client.delete(self.api_link)
|
|
|
+ self.assertEqual(response.status_code, 403)
|
|
|
+
|
|
|
+ self.override_acl({
|
|
|
+ 'can_hide_threads': 0
|
|
|
+ })
|
|
|
+
|
|
|
+ response_json = response.json()
|
|
|
+ self.assertEqual(response_json['detail'],
|
|
|
+ "You don't have permission to delete this thread.")
|
|
|
+
|
|
|
+ response = self.client.delete(self.api_link)
|
|
|
+ self.assertEqual(response.status_code, 403)
|
|
|
+
|
|
|
+ def test_delete_thread(self):
|
|
|
+ """DELETE to API link with permission deletes thread"""
|
|
|
+ self.override_acl({
|
|
|
+ 'can_hide_threads': 2
|
|
|
+ })
|
|
|
+
|
|
|
+ response = self.client.delete(self.api_link)
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
+
|
|
|
+ with self.assertRaises(Thread.DoesNotExist):
|
|
|
+ Thread.objects.get(pk=self.thread.pk)
|