Browse Source

#910: move readdata together with thread

Rafał Pitoń 7 years ago
parent
commit
584d7741c3
1 changed files with 36 additions and 1 deletions
  1. 36 1
      misago/threads/tests/test_thread_patch_api.py

+ 36 - 1
misago/threads/tests/test_thread_patch_api.py

@@ -5,7 +5,7 @@ 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.readtracker import poststracker
 from misago.threads.models import Thread
 from misago.threads.models import Thread
 
 
 from .test_threads_api import ThreadsApiTestCase
 from .test_threads_api import ThreadsApiTestCase
@@ -548,6 +548,41 @@ class ThreadMoveApiTests(ThreadPatchApiTestCase):
         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)
 
 
+    def test_move_thread_reads(self):
+        """api moves thread reads together with thread"""
+        self.override_acl({'can_move_threads': True})
+        self.override_other_acl({'can_start_threads': 2})
+
+        poststracker.save_read(self.user, self.thread.first_post)
+
+        self.assertEqual(self.user.postread_set.count(), 1)
+        self.user.postread_set.get(category=self.category)
+
+        response = self.patch(
+            self.api_link, [
+                {
+                    'op': 'replace',
+                    'path': 'category',
+                    'value': self.category_b.pk,
+                },
+                {
+                    'op': 'add',
+                    'path': 'top-category',
+                    'value': self.category_b.pk,
+                },
+                {
+                    'op': 'replace',
+                    'path': 'flatten-categories',
+                    'value': None,
+                },
+            ]
+        )
+        self.assertEqual(response.status_code, 200)
+
+        # thread read was moved to new category
+        self.assertEqual(self.user.postread_set.count(), 1)
+        self.user.postread_set.get(category=self.category_b)
+
     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})