Browse Source

Test that best answer is unmarked when its split to other thread

Rafał Pitoń 7 years ago
parent
commit
a6bbf93210
1 changed files with 32 additions and 0 deletions
  1. 32 0
      misago/threads/tests/test_thread_postsplit_api.py

+ 32 - 0
misago/threads/tests/test_thread_postsplit_api.py

@@ -603,6 +603,38 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
         # posts were moved to new thread
         # posts were moved to new thread
         self.assertEqual(split_thread.post_set.filter(pk__in=self.posts).count(), 2)
         self.assertEqual(split_thread.post_set.filter(pk__in=self.posts).count(), 2)
 
 
+    def test_split_best_answer(self):
+        """api splits best answer to new thread"""
+        best_answer = testutils.reply_thread(self.thread)
+
+        self.thread.set_best_answer(self.user, best_answer)
+        self.thread.synchronize()
+        self.thread.save()
+
+        self.refresh_thread()
+        self.assertEqual(self.thread.best_answer, best_answer)
+        self.assertEqual(self.thread.replies, 3)
+
+        response = self.client.post(
+            self.api_link,
+            json.dumps({
+                'posts': [best_answer.pk],
+                'title': 'Split thread.',
+                'category': self.category.id,
+            }),
+            content_type="application/json",
+        )
+        self.assertEqual(response.status_code, 200)
+
+        # best_answer was moved and unmarked
+        self.refresh_thread()
+        self.assertEqual(self.thread.replies, 2)
+        self.assertIsNone(self.thread.best_answer)
+
+        split_thread = self.category.thread_set.get(slug='split-thread')
+        self.assertEqual(split_thread.replies, 0)
+        self.assertIsNone(split_thread.best_answer)
+
     def test_split_kitchensink(self):
     def test_split_kitchensink(self):
         """api splits posts with kitchensink"""
         """api splits posts with kitchensink"""
         self.refresh_thread()
         self.refresh_thread()