|
@@ -6,6 +6,8 @@ from django.utils import six, timezone
|
|
from misago.acl.testutils import override_acl
|
|
from misago.acl.testutils import override_acl
|
|
from misago.categories.models import Category
|
|
from misago.categories.models import Category
|
|
|
|
|
|
|
|
+from misago.threads.models import Thread
|
|
|
|
+
|
|
from .test_threads_api import ThreadsApiTestCase
|
|
from .test_threads_api import ThreadsApiTestCase
|
|
|
|
|
|
|
|
|
|
@@ -60,6 +62,9 @@ class ThreadChangeTitleApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertEqual(response_json['title'], "Lorem ipsum change!")
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['title'], "Lorem ipsum change!")
|
|
self.assertEqual(thread_json['title'], "Lorem ipsum change!")
|
|
|
|
|
|
@@ -143,6 +148,9 @@ class ThreadPinGloballyApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertEqual(response_json['weight'], 2)
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['weight'], 2)
|
|
self.assertEqual(thread_json['weight'], 2)
|
|
|
|
|
|
@@ -167,6 +175,9 @@ class ThreadPinGloballyApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertEqual(response_json['weight'], 0)
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['weight'], 0)
|
|
self.assertEqual(thread_json['weight'], 0)
|
|
|
|
|
|
@@ -239,6 +250,9 @@ class ThreadPinLocallyApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertEqual(response_json['weight'], 1)
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['weight'], 1)
|
|
self.assertEqual(thread_json['weight'], 1)
|
|
|
|
|
|
@@ -263,6 +277,9 @@ class ThreadPinLocallyApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertEqual(response_json['weight'], 0)
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['weight'], 0)
|
|
self.assertEqual(thread_json['weight'], 0)
|
|
|
|
|
|
@@ -385,14 +402,14 @@ class ThreadMoveApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertEqual(reponse_json['category'], self.category_b.pk)
|
|
|
|
+
|
|
self.override_other_acl({})
|
|
self.override_other_acl({})
|
|
|
|
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['category']['id'], self.category_b.pk)
|
|
self.assertEqual(thread_json['category']['id'], self.category_b.pk)
|
|
|
|
|
|
- reponse_json = response.json()
|
|
|
|
- self.assertEqual(reponse_json['category'], self.category_b.pk)
|
|
|
|
-
|
|
|
|
def test_move_thread_with_top(self):
|
|
def test_move_thread_with_top(self):
|
|
"""api moves thread to other category, sets top"""
|
|
"""api moves thread to other category, sets top"""
|
|
self.override_acl({'can_move_threads': True})
|
|
self.override_acl({'can_move_threads': True})
|
|
@@ -419,14 +436,14 @@ class ThreadMoveApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertEqual(reponse_json['category'], self.category_b.pk)
|
|
|
|
+
|
|
self.override_other_acl({})
|
|
self.override_other_acl({})
|
|
|
|
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertEqual(thread_json['category']['id'], self.category_b.pk)
|
|
self.assertEqual(thread_json['category']['id'], self.category_b.pk)
|
|
|
|
|
|
- reponse_json = response.json()
|
|
|
|
- self.assertEqual(reponse_json['category'], self.category_b.pk)
|
|
|
|
-
|
|
|
|
def test_move_thread_no_permission(self):
|
|
def test_move_thread_no_permission(self):
|
|
"""api move thread to other category with no permission fails"""
|
|
"""api move thread to other category with no permission fails"""
|
|
self.override_acl({'can_move_threads': False})
|
|
self.override_acl({'can_move_threads': False})
|
|
@@ -563,6 +580,9 @@ class ThreadCloseApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertTrue(response_json['is_closed'])
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertTrue(thread_json['is_closed'])
|
|
self.assertTrue(thread_json['is_closed'])
|
|
|
|
|
|
@@ -587,6 +607,9 @@ class ThreadCloseApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertFalse(response_json['is_closed'])
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertFalse(thread_json['is_closed'])
|
|
self.assertFalse(thread_json['is_closed'])
|
|
|
|
|
|
@@ -646,9 +669,15 @@ class ThreadCloseApiTests(ThreadPatchApiTestCase):
|
|
class ThreadApproveApiTests(ThreadPatchApiTestCase):
|
|
class ThreadApproveApiTests(ThreadPatchApiTestCase):
|
|
def test_approve_thread(self):
|
|
def test_approve_thread(self):
|
|
"""api makes it possible to approve thread"""
|
|
"""api makes it possible to approve thread"""
|
|
- self.thread.is_unapproved = True
|
|
|
|
|
|
+ self.thread.first_post.is_unapproved = True
|
|
|
|
+ self.thread.first_post.save()
|
|
|
|
+
|
|
|
|
+ self.thread.synchronize()
|
|
self.thread.save()
|
|
self.thread.save()
|
|
|
|
|
|
|
|
+ self.assertTrue(self.thread.is_unapproved)
|
|
|
|
+ self.assertTrue(self.thread.has_unapproved_posts)
|
|
|
|
+
|
|
self.override_acl({'can_approve_content': 1})
|
|
self.override_acl({'can_approve_content': 1})
|
|
|
|
|
|
response = self.patch(
|
|
response = self.patch(
|
|
@@ -662,8 +691,17 @@ class ThreadApproveApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ response_json = response.json()
|
|
|
|
+ self.assertFalse(response_json['is_unapproved'])
|
|
|
|
+ self.assertFalse(response_json['has_unapproved_posts'])
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertFalse(thread_json['is_unapproved'])
|
|
self.assertFalse(thread_json['is_unapproved'])
|
|
|
|
+ self.assertFalse(thread_json['has_unapproved_posts'])
|
|
|
|
+
|
|
|
|
+ thread = Thread.objects.get(pk=self.thread.pk)
|
|
|
|
+ self.assertFalse(thread.is_unapproved)
|
|
|
|
+ self.assertFalse(thread.has_unapproved_posts)
|
|
|
|
|
|
def test_unapprove_thread(self):
|
|
def test_unapprove_thread(self):
|
|
"""api returns permission error on approval removal"""
|
|
"""api returns permission error on approval removal"""
|
|
@@ -700,6 +738,9 @@ class ThreadHideApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertTrue(reponse_json['is_hidden'])
|
|
|
|
+
|
|
self.override_acl({'can_hide_threads': 1})
|
|
self.override_acl({'can_hide_threads': 1})
|
|
|
|
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
@@ -728,6 +769,9 @@ class ThreadHideApiTests(ThreadPatchApiTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertFalse(reponse_json['is_hidden'])
|
|
|
|
+
|
|
self.override_acl({'can_hide_threads': 1})
|
|
self.override_acl({'can_hide_threads': 1})
|
|
|
|
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
@@ -795,6 +839,9 @@ class ThreadSubscribeApiTests(ThreadPatchApiTestCase):
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertFalse(reponse_json['subscription'])
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertFalse(thread_json['subscription'])
|
|
self.assertFalse(thread_json['subscription'])
|
|
|
|
|
|
@@ -815,6 +862,9 @@ class ThreadSubscribeApiTests(ThreadPatchApiTestCase):
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertTrue(reponse_json['subscription'])
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertTrue(thread_json['subscription'])
|
|
self.assertTrue(thread_json['subscription'])
|
|
|
|
|
|
@@ -835,6 +885,9 @@ class ThreadSubscribeApiTests(ThreadPatchApiTestCase):
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ reponse_json = response.json()
|
|
|
|
+ self.assertIsNone(reponse_json['subscription'])
|
|
|
|
+
|
|
thread_json = self.get_thread_json()
|
|
thread_json = self.get_thread_json()
|
|
self.assertIsNone(thread_json['subscription'])
|
|
self.assertIsNone(thread_json['subscription'])
|
|
|
|
|