|
@@ -57,6 +57,9 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 403)
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "This action is not available to guests.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_no_permission(self):
|
|
def test_no_permission(self):
|
|
"""api validates permission to merge"""
|
|
"""api validates permission to merge"""
|
|
@@ -67,42 +70,58 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
json.dumps({}),
|
|
json.dumps({}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(response, "You can't merge posts in this thread.", status_code=403)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 403)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You can't merge posts in this thread.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_empty_data_json(self):
|
|
def test_empty_data_json(self):
|
|
"""api handles empty json data"""
|
|
"""api handles empty json data"""
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
self.api_link, json.dumps({}), content_type="application/json"
|
|
self.api_link, json.dumps({}), content_type="application/json"
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "You have to select at least two posts to merge.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to select at least two posts to merge.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_empty_data_form(self):
|
|
def test_empty_data_form(self):
|
|
"""api handles empty form data"""
|
|
"""api handles empty form data"""
|
|
response = self.client.post(self.api_link, {})
|
|
response = self.client.post(self.api_link, {})
|
|
-
|
|
|
|
- self.assertContains(
|
|
|
|
- response, "You have to select at least two posts to merge.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to select at least two posts to merge.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_invalid_data(self):
|
|
def test_invalid_data(self):
|
|
"""api handles post that is invalid type"""
|
|
"""api handles post that is invalid type"""
|
|
self.override_acl()
|
|
self.override_acl()
|
|
response = self.client.post(self.api_link, '[]', content_type="application/json")
|
|
response = self.client.post(self.api_link, '[]', content_type="application/json")
|
|
- self.assertContains(response, "Invalid data. Expected a dictionary", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Invalid data. Expected a dictionary, but got list.",
|
|
|
|
+ })
|
|
|
|
|
|
self.override_acl()
|
|
self.override_acl()
|
|
response = self.client.post(self.api_link, '123', content_type="application/json")
|
|
response = self.client.post(self.api_link, '123', content_type="application/json")
|
|
- self.assertContains(response, "Invalid data. Expected a dictionary", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Invalid data. Expected a dictionary, but got int.",
|
|
|
|
+ })
|
|
|
|
|
|
self.override_acl()
|
|
self.override_acl()
|
|
response = self.client.post(self.api_link, '"string"', content_type="application/json")
|
|
response = self.client.post(self.api_link, '"string"', content_type="application/json")
|
|
- self.assertContains(response, "Invalid data. Expected a dictionary", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Invalid data. Expected a dictionary, but got str.",
|
|
|
|
+ })
|
|
|
|
|
|
self.override_acl()
|
|
self.override_acl()
|
|
response = self.client.post(self.api_link, 'malformed', content_type="application/json")
|
|
response = self.client.post(self.api_link, 'malformed', content_type="application/json")
|
|
- self.assertContains(response, "JSON parse error", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "JSON parse error - Expecting value: line 1 column 1 (char 0)",
|
|
|
|
+ })
|
|
|
|
|
|
def test_no_posts_ids(self):
|
|
def test_no_posts_ids(self):
|
|
"""api rejects no posts ids"""
|
|
"""api rejects no posts ids"""
|
|
@@ -113,9 +132,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "You have to select at least two posts to merge.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to select at least two posts to merge.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_invalid_posts_data(self):
|
|
def test_invalid_posts_data(self):
|
|
"""api handles invalid data"""
|
|
"""api handles invalid data"""
|
|
@@ -126,9 +146,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "Expected a list of items but got type", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": 'Expected a list of items but got type "str".',
|
|
|
|
+ })
|
|
|
|
|
|
def test_invalid_posts_ids(self):
|
|
def test_invalid_posts_ids(self):
|
|
"""api handles invalid post id"""
|
|
"""api handles invalid post id"""
|
|
@@ -139,9 +160,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "One or more post ids received were invalid.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "One or more post ids received were invalid.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_one_post_id(self):
|
|
def test_one_post_id(self):
|
|
"""api rejects one post id"""
|
|
"""api rejects one post id"""
|
|
@@ -152,9 +174,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "You have to select at least two posts to merge.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to select at least two posts to merge.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_limit(self):
|
|
def test_merge_limit(self):
|
|
"""api rejects more posts than merge limit"""
|
|
"""api rejects more posts than merge limit"""
|
|
@@ -165,9 +188,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "No more than {} posts can be merged".format(POSTS_LIMIT), status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "No more than %s posts can be merged at single time." % POSTS_LIMIT,
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_event(self):
|
|
def test_merge_event(self):
|
|
"""api recjects events"""
|
|
"""api recjects events"""
|
|
@@ -180,7 +204,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(response, "Events can't be merged.", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Events can't be merged.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_notfound_pk(self):
|
|
def test_merge_notfound_pk(self):
|
|
"""api recjects nonexistant pk's"""
|
|
"""api recjects nonexistant pk's"""
|
|
@@ -191,9 +218,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "One or more posts to merge could not be found.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "One or more posts to merge could not be found.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_cross_threads(self):
|
|
def test_merge_cross_threads(self):
|
|
"""api recjects attempt to merge with post made in other thread"""
|
|
"""api recjects attempt to merge with post made in other thread"""
|
|
@@ -207,9 +235,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "One or more posts to merge could not be found.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "One or more posts to merge could not be found.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_authenticated_with_guest_post(self):
|
|
def test_merge_authenticated_with_guest_post(self):
|
|
"""api recjects attempt to merge with post made by deleted user"""
|
|
"""api recjects attempt to merge with post made by deleted user"""
|
|
@@ -222,9 +251,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "Posts made by different users can't be merged.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Posts made by different users can't be merged.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_guest_with_authenticated_post(self):
|
|
def test_merge_guest_with_authenticated_post(self):
|
|
"""api recjects attempt to merge with post made by deleted user"""
|
|
"""api recjects attempt to merge with post made by deleted user"""
|
|
@@ -237,9 +267,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "Posts made by different users can't be merged.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Posts made by different users can't be merged.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_guest_posts_different_usernames(self):
|
|
def test_merge_guest_posts_different_usernames(self):
|
|
"""api recjects attempt to merge posts made by different guests"""
|
|
"""api recjects attempt to merge posts made by different guests"""
|
|
@@ -253,9 +284,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "Posts made by different users can't be merged.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Posts made by different users can't be merged.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_different_visibility(self):
|
|
def test_merge_different_visibility(self):
|
|
"""api recjects attempt to merge posts with different visibility"""
|
|
"""api recjects attempt to merge posts with different visibility"""
|
|
@@ -271,9 +303,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "Posts with different visibility can't be merged.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Posts with different visibility can't be merged.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_merge_different_approval(self):
|
|
def test_merge_different_approval(self):
|
|
"""api recjects attempt to merge posts with different approval"""
|
|
"""api recjects attempt to merge posts with different approval"""
|
|
@@ -289,9 +322,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "Posts with different visibility can't be merged.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Posts with different visibility can't be merged.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_closed_thread(self):
|
|
def test_closed_thread(self):
|
|
"""api validates permission to merge in closed thread"""
|
|
"""api validates permission to merge in closed thread"""
|
|
@@ -308,11 +342,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
json.dumps({'posts': posts}),
|
|
json.dumps({'posts': posts}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response,
|
|
|
|
- "This thread is closed. You can't merge posts in it.",
|
|
|
|
- status_code=400,
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "This thread is closed. You can't merge posts in it.",
|
|
|
|
+ })
|
|
|
|
|
|
# allow closing threads
|
|
# allow closing threads
|
|
self.override_acl({'can_close_threads': 1})
|
|
self.override_acl({'can_close_threads': 1})
|
|
@@ -339,11 +372,10 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
json.dumps({'posts': posts}),
|
|
json.dumps({'posts': posts}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response,
|
|
|
|
- "This category is closed. You can't merge posts in it.",
|
|
|
|
- status_code=400,
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "This category is closed. You can't merge posts in it.",
|
|
|
|
+ })
|
|
|
|
|
|
# allow closing threads
|
|
# allow closing threads
|
|
self.override_acl({'can_close_threads': 1})
|
|
self.override_acl({'can_close_threads': 1})
|
|
@@ -378,7 +410,7 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
|
|
)
|
|
)
|
|
self.assertEqual(response.status_code, 400)
|
|
self.assertEqual(response.status_code, 400)
|
|
self.assertEqual(response.json(), {
|
|
self.assertEqual(response.json(), {
|
|
- 'detail': "Post marked as best answer can't be merged with thread's first post."
|
|
|
|
|
|
+ "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):
|