|
@@ -268,8 +268,8 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
self.api_link,
|
|
self.api_link,
|
|
json.dumps({
|
|
json.dumps({
|
|
'posts': [
|
|
'posts': [
|
|
- testutils.reply_thread(self.thread, poster="Bob", is_hidden=True).pk,
|
|
|
|
- testutils.reply_thread(self.thread, poster="Bob", is_hidden=False).pk,
|
|
|
|
|
|
+ testutils.reply_thread(self.thread, poster=self.user, is_hidden=True).pk,
|
|
|
|
+ testutils.reply_thread(self.thread, poster=self.user, is_hidden=False).pk,
|
|
]
|
|
]
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
@@ -286,8 +286,8 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
self.api_link,
|
|
self.api_link,
|
|
json.dumps({
|
|
json.dumps({
|
|
'posts': [
|
|
'posts': [
|
|
- testutils.reply_thread(self.thread, poster="Bob", is_unapproved=True).pk,
|
|
|
|
- testutils.reply_thread(self.thread, poster="Bob", is_unapproved=False).pk,
|
|
|
|
|
|
+ testutils.reply_thread(self.thread, poster=self.user, is_unapproved=True).pk,
|
|
|
|
+ testutils.reply_thread(self.thread, poster=self.user, is_unapproved=False).pk,
|
|
]
|
|
]
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
@@ -358,6 +358,32 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ def test_merge_best_answer_first_post(self):
|
|
|
|
+ """api recjects attempt to merge best_answer with first post"""
|
|
|
|
+ self.thread.first_post.poster = self.user
|
|
|
|
+ self.thread.first_post.save()
|
|
|
|
+
|
|
|
|
+ self.post.poster = self.user
|
|
|
|
+ self.post.save()
|
|
|
|
+
|
|
|
|
+ self.thread.set_best_answer(self.user, self.post)
|
|
|
|
+ self.thread.save()
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ self.api_link,
|
|
|
|
+ json.dumps({
|
|
|
|
+ 'posts': [
|
|
|
|
+ self.thread.first_post.pk,
|
|
|
|
+ self.post.pk,
|
|
|
|
+ ]
|
|
|
|
+ }),
|
|
|
|
+ content_type="application/json",
|
|
|
|
+ )
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ 'detail': "Post marked as best answer can't be merged with thread's first post."
|
|
|
|
+ })
|
|
|
|
+
|
|
def test_merge_posts(self):
|
|
def test_merge_posts(self):
|
|
"""api merges two posts"""
|
|
"""api merges two posts"""
|
|
post_a = testutils.reply_thread(self.thread, poster=self.user, message="Battęry")
|
|
post_a = testutils.reply_thread(self.thread, poster=self.user, message="Battęry")
|
|
@@ -383,6 +409,20 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
merged_post = Post.objects.get(pk=post_a.pk)
|
|
merged_post = Post.objects.get(pk=post_a.pk)
|
|
self.assertEqual(merged_post.parsed, '{}\n{}'.format(post_a.parsed, post_b.parsed))
|
|
self.assertEqual(merged_post.parsed, '{}\n{}'.format(post_a.parsed, post_b.parsed))
|
|
|
|
|
|
|
|
+ def test_merge_guest_posts(self):
|
|
|
|
+ """api recjects attempt to merge posts made by same guest"""
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ self.api_link,
|
|
|
|
+ json.dumps({
|
|
|
|
+ 'posts': [
|
|
|
|
+ testutils.reply_thread(self.thread, poster="Bob").pk,
|
|
|
|
+ testutils.reply_thread(self.thread, poster="Bob").pk,
|
|
|
|
+ ]
|
|
|
|
+ }),
|
|
|
|
+ content_type="application/json",
|
|
|
|
+ )
|
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
|
+
|
|
def test_merge_hidden_posts(self):
|
|
def test_merge_hidden_posts(self):
|
|
"""api merges two hidden posts"""
|
|
"""api merges two hidden posts"""
|
|
self.override_acl({'can_hide_posts': 1})
|
|
self.override_acl({'can_hide_posts': 1})
|
|
@@ -434,6 +474,51 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
+ def test_merge_best_answer(self):
|
|
|
|
+ """api merges best answer with other post"""
|
|
|
|
+ best_answer = testutils.reply_thread(self.thread, poster="Bob")
|
|
|
|
+
|
|
|
|
+ self.thread.set_best_answer(self.user, best_answer)
|
|
|
|
+ self.thread.save()
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ self.api_link,
|
|
|
|
+ json.dumps({
|
|
|
|
+ 'posts': [
|
|
|
|
+ best_answer.pk,
|
|
|
|
+ testutils.reply_thread(self.thread, poster="Bob").pk,
|
|
|
|
+ ]
|
|
|
|
+ }),
|
|
|
|
+ content_type="application/json",
|
|
|
|
+ )
|
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
|
+
|
|
|
|
+ self.refresh_thread()
|
|
|
|
+ self.assertEqual(self.thread.best_answer, best_answer)
|
|
|
|
+
|
|
|
|
+ def test_merge_best_answer_in(self):
|
|
|
|
+ """api merges best answer into other post"""
|
|
|
|
+ other_post = testutils.reply_thread(self.thread, poster="Bob")
|
|
|
|
+ best_answer = testutils.reply_thread(self.thread, poster="Bob")
|
|
|
|
+
|
|
|
|
+ self.thread.set_best_answer(self.user, best_answer)
|
|
|
|
+ self.thread.save()
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ self.api_link,
|
|
|
|
+ json.dumps({
|
|
|
|
+ 'posts': [
|
|
|
|
+ best_answer.pk,
|
|
|
|
+ other_post.pk,
|
|
|
|
+ ]
|
|
|
|
+ }),
|
|
|
|
+ content_type="application/json",
|
|
|
|
+ )
|
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
|
+
|
|
|
|
+ self.refresh_thread()
|
|
|
|
+ self.assertEqual(self.thread.best_answer, other_post)
|
|
|
|
+
|
|
def test_merge_remove_reads(self):
|
|
def test_merge_remove_reads(self):
|
|
"""two posts merge removes read tracker from post"""
|
|
"""two posts merge removes read tracker from post"""
|
|
post_a = testutils.reply_thread(self.thread, poster=self.user, message="Battęry")
|
|
post_a = testutils.reply_thread(self.thread, poster=self.user, message="Battęry")
|