|
@@ -96,38 +96,57 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
|
|
|
|
response = self.client.post(self.api_link, json.dumps({}), content_type="application/json")
|
|
response = self.client.post(self.api_link, json.dumps({}), 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 split"""
|
|
"""api validates permission to split"""
|
|
self.override_acl({'can_move_posts': 0})
|
|
self.override_acl({'can_move_posts': 0})
|
|
|
|
|
|
response = self.client.post(self.api_link, json.dumps({}), content_type="application/json")
|
|
response = self.client.post(self.api_link, json.dumps({}), content_type="application/json")
|
|
- self.assertContains(response, "You can't split posts from this thread.", status_code=403)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 403)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You can't split posts from this thread.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_empty_data(self):
|
|
def test_empty_data(self):
|
|
"""api handles empty data"""
|
|
"""api handles empty data"""
|
|
response = self.client.post(self.api_link)
|
|
response = self.client.post(self.api_link)
|
|
- self.assertContains(
|
|
|
|
- response, "You have to specify at least one post to split.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to specify at least one post to split.",
|
|
|
|
+ })
|
|
|
|
|
|
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(), {
|
|
|
|
+ "non_field_errors": ["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(), {
|
|
|
|
+ "non_field_errors": ["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(), {
|
|
|
|
+ "non_field_errors": ["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"""
|
|
@@ -136,10 +155,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
json.dumps({}),
|
|
json.dumps({}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "You have to specify at least one post to split.", status_code=400
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to specify at least one post to split.",
|
|
|
|
+ })
|
|
def test_empty_posts_ids(self):
|
|
def test_empty_posts_ids(self):
|
|
"""api rejects empty posts ids list"""
|
|
"""api rejects empty posts ids list"""
|
|
response = self.client.post(
|
|
response = self.client.post(
|
|
@@ -149,9 +168,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "You have to specify at least one post to split.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You have to specify at least one post to split.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_invalid_posts_data(self):
|
|
def test_invalid_posts_data(self):
|
|
"""api handles invalid data"""
|
|
"""api handles invalid data"""
|
|
@@ -162,9 +182,10 @@ class ThreadPostSplitApiTestCase(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"""
|
|
@@ -175,9 +196,10 @@ class ThreadPostSplitApiTestCase(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_split_limit(self):
|
|
def test_split_limit(self):
|
|
"""api rejects more posts than split limit"""
|
|
"""api rejects more posts than split limit"""
|
|
@@ -188,9 +210,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "No more than {} posts can be split".format(POSTS_LIMIT), status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "No more than %s posts can be split at single time." % POSTS_LIMIT,
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_invisible(self):
|
|
def test_split_invisible(self):
|
|
"""api validates posts visibility"""
|
|
"""api validates posts visibility"""
|
|
@@ -201,9 +224,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "One or more posts to split could not be found.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "One or more posts to split could not be found.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_event(self):
|
|
def test_split_event(self):
|
|
"""api rejects events split"""
|
|
"""api rejects events split"""
|
|
@@ -214,7 +238,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(response, "Events can't be split.", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "Events can't be split.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_first_post(self):
|
|
def test_split_first_post(self):
|
|
"""api rejects first post split"""
|
|
"""api rejects first post split"""
|
|
@@ -225,7 +252,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(response, "You can't split thread's first post.", status_code=400)
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You can't split thread's first post.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_hidden_posts(self):
|
|
def test_split_hidden_posts(self):
|
|
"""api recjects attempt to split urneadable hidden post"""
|
|
"""api recjects attempt to split urneadable hidden post"""
|
|
@@ -236,9 +266,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "You can't split posts the content you can't see.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "You can't split posts the content you can't see.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_posts_closed_thread_no_permission(self):
|
|
def test_split_posts_closed_thread_no_permission(self):
|
|
"""api recjects attempt to split posts from closed thread"""
|
|
"""api recjects attempt to split posts from closed thread"""
|
|
@@ -254,9 +285,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "This thread is closed. You can't split posts in it.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "This thread is closed. You can't split posts in it.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_posts_closed_category_no_permission(self):
|
|
def test_split_posts_closed_category_no_permission(self):
|
|
"""api recjects attempt to split posts from closed thread"""
|
|
"""api recjects attempt to split posts from closed thread"""
|
|
@@ -272,9 +304,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "This category is closed. You can't split posts in it.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "This category is closed. You can't split posts in it.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_other_thread_posts(self):
|
|
def test_split_other_thread_posts(self):
|
|
"""api recjects attempt to split other thread's post"""
|
|
"""api recjects attempt to split other thread's post"""
|
|
@@ -287,9 +320,10 @@ class ThreadPostSplitApiTestCase(AuthenticatedUserTestCase):
|
|
}),
|
|
}),
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
- self.assertContains(
|
|
|
|
- response, "One or more posts to split could not be found.", status_code=400
|
|
|
|
- )
|
|
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+ self.assertEqual(response.json(), {
|
|
|
|
+ "detail": "One or more posts to split could not be found.",
|
|
|
|
+ })
|
|
|
|
|
|
def test_split_empty_new_thread_data(self):
|
|
def test_split_empty_new_thread_data(self):
|
|
"""api handles empty form data"""
|
|
"""api handles empty form data"""
|