Просмотр исходного кода

tests for delete private thread

Rafał Pitoń 8 лет назад
Родитель
Сommit
845d9c19bb

+ 9 - 9
misago/threads/tests/test_privatethread_view.py

@@ -10,13 +10,13 @@ class PrivateThreadViewTests(PrivateThreadsTestCase):
         super(PrivateThreadViewTests, self).setUp()
 
         self.thread = testutils.post_thread(self.category, poster=self.user)
-        self.thread_url = self.thread.get_absolute_url()
+        self.test_link = self.thread.get_absolute_url()
 
     def test_anonymous(self):
         """anonymous user can't see private thread"""
         self.logout_user()
 
-        response = self.client.get(self.thread_url)
+        response = self.client.get(self.test_link)
         self.assertContains(response, "sign in to use private threads", status_code=403)
 
     def test_no_permission(self):
@@ -25,12 +25,12 @@ class PrivateThreadViewTests(PrivateThreadsTestCase):
             'can_use_private_threads': 0
         })
 
-        response = self.client.get(self.thread_url)
+        response = self.client.get(self.test_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.thread_url)
+        response = self.client.get(self.test_link)
         self.assertEqual(response.status_code, 404)
 
     def test_mod_not_reported(self):
@@ -39,7 +39,7 @@ class PrivateThreadViewTests(PrivateThreadsTestCase):
             'can_moderate_private_threads': 1
         })
 
-        response = self.client.get(self.thread_url)
+        response = self.client.get(self.test_link)
         self.assertEqual(response.status_code, 404)
 
     def test_reported_not_mod(self):
@@ -47,21 +47,21 @@ class PrivateThreadViewTests(PrivateThreadsTestCase):
         self.thread.has_reported_posts = True
         self.thread.save()
 
-        response = self.client.get(self.thread_url)
+        response = self.client.get(self.test_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.thread_url)
+        response = self.client.get(self.test_link)
         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.thread_url)
+        response = self.client.get(self.test_link)
         self.assertContains(response, self.thread.title)
 
     def test_mod_can_see_reported(self):
@@ -73,5 +73,5 @@ class PrivateThreadViewTests(PrivateThreadsTestCase):
         self.thread.has_reported_posts = True
         self.thread.save()
 
-        response = self.client.get(self.thread_url)
+        response = self.client.get(self.test_link)
         self.assertContains(response, self.thread.title)

+ 56 - 14
misago/threads/tests/test_privatethreads_api.py

@@ -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)

+ 12 - 12
misago/threads/tests/test_threads_api.py

@@ -153,18 +153,6 @@ class ThreadRetrieveApiTests(ThreadsApiTestCase):
 
 
 class ThreadDeleteApiTests(ThreadsApiTestCase):
-    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)
-
     def test_delete_thread_no_permission(self):
         """DELETE to API link with no permission to delete fails"""
         self.override_acl({
@@ -184,3 +172,15 @@ class ThreadDeleteApiTests(ThreadsApiTestCase):
 
         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)