Browse Source

Remove assertContains from threads editor api tests

rafalp 6 years ago
parent
commit
fffbaae3dd
1 changed files with 72 additions and 36 deletions
  1. 72 36
      misago/threads/tests/test_threads_editor_api.py

+ 72 - 36
misago/threads/tests/test_threads_editor_api.py

@@ -80,21 +80,30 @@ class ThreadPostEditorApiTests(EditorApiTestCase):
         self.logout_user()
         self.logout_user()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "You need to be signed in", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You need to be signed in to start threads.",
+        })
 
 
     def test_category_visibility_validation(self):
     def test_category_visibility_validation(self):
         """endpoint omits non-browseable categories"""
         """endpoint omits non-browseable categories"""
         self.override_acl({'can_browse': 0})
         self.override_acl({'can_browse': 0})
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "No categories that allow new threads", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "No categories that allow new threads are available to you at the moment.",
+        })
 
 
     def test_category_disallowing_new_threads(self):
     def test_category_disallowing_new_threads(self):
         """endpoint omits category disallowing starting threads"""
         """endpoint omits category disallowing starting threads"""
         self.override_acl({'can_start_threads': 0})
         self.override_acl({'can_start_threads': 0})
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "No categories that allow new threads", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "No categories that allow new threads are available to you at the moment.",
+        })
 
 
     def test_category_closed_disallowing_new_threads(self):
     def test_category_closed_disallowing_new_threads(self):
         """endpoint omits closed category"""
         """endpoint omits closed category"""
@@ -104,7 +113,10 @@ class ThreadPostEditorApiTests(EditorApiTestCase):
         self.category.save()
         self.category.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "No categories that allow new threads", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "No categories that allow new threads are available to you at the moment.",
+        })
 
 
     def test_category_closed_allowing_new_threads(self):
     def test_category_closed_allowing_new_threads(self):
         """endpoint adds closed category that allows new threads"""
         """endpoint adds closed category that allows new threads"""
@@ -271,7 +283,10 @@ class ThreadReplyEditorApiTests(EditorApiTestCase):
         self.logout_user()
         self.logout_user()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "You have to sign in to reply threads.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You have to sign in to reply threads.",
+        })
 
 
     def test_thread_visibility(self):
     def test_thread_visibility(self):
         """thread's visibility is validated"""
         """thread's visibility is validated"""
@@ -292,9 +307,10 @@ class ThreadReplyEditorApiTests(EditorApiTestCase):
         self.override_acl({'can_reply_threads': 0})
         self.override_acl({'can_reply_threads': 0})
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response, "You can't reply to threads in this category.", status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You can't reply to threads in this category.",
+        })
 
 
     def test_closed_category(self):
     def test_closed_category(self):
         """permssion to reply in closed category is validated"""
         """permssion to reply in closed category is validated"""
@@ -304,11 +320,10 @@ class ThreadReplyEditorApiTests(EditorApiTestCase):
         self.category.save()
         self.category.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response,
-            "This category is closed. You can't reply to threads in it.",
-            status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "This category is closed. You can't reply to threads in it.",
+        })
 
 
         # allow to post in closed category
         # allow to post in closed category
         self.override_acl({'can_reply_threads': 1, 'can_close_threads': 1})
         self.override_acl({'can_reply_threads': 1, 'can_close_threads': 1})
@@ -324,9 +339,10 @@ class ThreadReplyEditorApiTests(EditorApiTestCase):
         self.thread.save()
         self.thread.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response, "You can't reply to closed threads in this category.", status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You can't reply to closed threads in this category.",
+        })
 
 
         # allow to post in closed thread
         # allow to post in closed thread
         self.override_acl({'can_reply_threads': 1, 'can_close_threads': 1})
         self.override_acl({'can_reply_threads': 1, 'can_close_threads': 1})
@@ -360,7 +376,10 @@ class ThreadReplyEditorApiTests(EditorApiTestCase):
         hidden_reply = testutils.reply_thread(self.thread, is_hidden=True)
         hidden_reply = testutils.reply_thread(self.thread, is_hidden=True)
 
 
         response = self.client.get('{}?reply={}'.format(self.api_link, hidden_reply.pk))
         response = self.client.get('{}?reply={}'.format(self.api_link, hidden_reply.pk))
-        self.assertContains(response, "You can't reply to hidden posts", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You can't reply to hidden posts.",
+        })
 
 
     def test_reply_to_other_thread_post(self):
     def test_reply_to_other_thread_post(self):
         """api validates is replied post belongs to same thread"""
         """api validates is replied post belongs to same thread"""
@@ -377,8 +396,10 @@ class ThreadReplyEditorApiTests(EditorApiTestCase):
         reply_to = testutils.reply_thread(self.thread, is_event=True)
         reply_to = testutils.reply_thread(self.thread, is_event=True)
 
 
         response = self.client.get('{}?reply={}'.format(self.api_link, reply_to.pk))
         response = self.client.get('{}?reply={}'.format(self.api_link, reply_to.pk))
-
-        self.assertContains(response, "You can't reply to events.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You can't reply to events.",
+        })
 
 
     def test_reply_to(self):
     def test_reply_to(self):
         """api includes replied to post details in response"""
         """api includes replied to post details in response"""
@@ -418,7 +439,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.logout_user()
         self.logout_user()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "You have to sign in to edit posts.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You have to sign in to edit posts.",
+        })
 
 
     def test_thread_visibility(self):
     def test_thread_visibility(self):
         """thread's visibility is validated"""
         """thread's visibility is validated"""
@@ -439,7 +463,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.override_acl({'can_edit_posts': 0})
         self.override_acl({'can_edit_posts': 0})
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "You can't edit posts in this category.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You can't edit posts in this category.",
+        })
 
 
     def test_closed_category(self):
     def test_closed_category(self):
         """permssion to edit in closed category is validated"""
         """permssion to edit in closed category is validated"""
@@ -449,9 +476,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.category.save()
         self.category.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response, "This category is closed. You can't edit posts in it.", status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "This category is closed. You can't edit posts in it.",
+        })
 
 
         # allow to edit in closed category
         # allow to edit in closed category
         self.override_acl({'can_edit_posts': 1, 'can_close_threads': 1})
         self.override_acl({'can_edit_posts': 1, 'can_close_threads': 1})
@@ -467,9 +495,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.thread.save()
         self.thread.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response, "This thread is closed. You can't edit posts in it.", status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "This thread is closed. You can't edit posts in it.",
+        })
 
 
         # allow to edit in closed thread
         # allow to edit in closed thread
         self.override_acl({'can_edit_posts': 1, 'can_close_threads': 1})
         self.override_acl({'can_edit_posts': 1, 'can_close_threads': 1})
@@ -485,9 +514,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.post.save()
         self.post.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response, "This post is protected. You can't edit it.", status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "This post is protected. You can't edit it.",
+        })
 
 
         # allow to post in closed thread
         # allow to post in closed thread
         self.override_acl({'can_edit_posts': 1, 'can_protect_posts': 1})
         self.override_acl({'can_edit_posts': 1, 'can_protect_posts': 1})
@@ -503,7 +533,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.post.save()
         self.post.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(response, "This post is hidden, you can't edit it.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "This post is hidden, you can't edit it.",
+        })
 
 
         # allow hidden edition
         # allow hidden edition
         self.override_acl({'can_edit_posts': 1, 'can_hide_posts': 1})
         self.override_acl({'can_edit_posts': 1, 'can_hide_posts': 1})
@@ -538,8 +571,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.post.save()
         self.post.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-
-        self.assertContains(response, "Events can't be edited.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "Events can't be edited.",
+        })
 
 
     def test_other_user_post(self):
     def test_other_user_post(self):
         """api validates if other user's post can be edited"""
         """api validates if other user's post can be edited"""
@@ -549,9 +584,10 @@ class EditReplyEditorApiTests(EditorApiTestCase):
         self.post.save()
         self.post.save()
 
 
         response = self.client.get(self.api_link)
         response = self.client.get(self.api_link)
-        self.assertContains(
-            response, "You can't edit other users posts in this category.", status_code=403
-        )
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "You can't edit other users posts in this category.",
+        })
 
 
         # allow other users post edition
         # allow other users post edition
         self.override_acl({'can_edit_posts': 2})
         self.override_acl({'can_edit_posts': 2})