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

#912: added tests for thread move keeping subscriptions

Rafał Pitoń 7 лет назад
Родитель
Сommit
b31dcba252
1 измененных файлов с 40 добавлено и 0 удалено
  1. 40 0
      misago/threads/tests/test_thread_patch_api.py

+ 40 - 0
misago/threads/tests/test_thread_patch_api.py

@@ -583,6 +583,46 @@ class ThreadMoveApiTests(ThreadPatchApiTestCase):
         self.assertEqual(self.user.postread_set.count(), 1)
         self.user.postread_set.get(category=self.category_b)
 
+    def test_move_thread_subscriptions(self):
+        """api moves thread subscriptions together with thread"""
+        self.override_acl({'can_move_threads': True})
+        self.override_other_acl({'can_start_threads': 2})
+
+        self.user.subscription_set.create(
+            thread=self.thread,
+            category=self.thread.category,
+            last_read_on=self.thread.last_post_on,
+            send_email=False,
+        )
+
+        self.assertEqual(self.user.subscription_set.count(), 1)
+        self.user.subscription_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.subscription_set.count(), 1)
+        self.user.subscription_set.get(category=self.category_b)
+
     def test_move_thread_no_permission(self):
         """api move thread to other category with no permission fails"""
         self.override_acl({'can_move_threads': False})