Browse Source

Replace assertContains from validate post middleware

rafalp 6 years ago
parent
commit
493f6ec573
1 changed files with 16 additions and 2 deletions
  1. 16 2
      misago/threads/tests/test_validate_post.py

+ 16 - 2
misago/threads/tests/test_validate_post.py

@@ -21,7 +21,10 @@ class ValidatePostTests(AuthenticatedUserTestCase):
                 'post': 'Lorem ipsum dolor met!',
                 'post': 'Lorem ipsum dolor met!',
             }
             }
         )
         )
-        self.assertContains(response, "Don't discuss gambling!", status_code=400)
+        self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            'non_field_errors': ["Don't discuss gambling!"],
+        })
 
 
         # clean title passes validation
         # clean title passes validation
         response = self.client.post(
         response = self.client.post(
@@ -44,7 +47,10 @@ class ValidatePostTests(AuthenticatedUserTestCase):
                 'post': 'Check our l33t CaSiNo!',
                 'post': 'Check our l33t CaSiNo!',
             }
             }
         )
         )
-        self.assertContains(response, "Don't discuss gambling!", status_code=400)
+        self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            'non_field_errors': ["Don't discuss gambling!"],
+        })
 
 
         # clean post passes validation
         # clean post passes validation
         response = self.client.post(
         response = self.client.post(
@@ -65,6 +71,10 @@ class ValidatePostTests(AuthenticatedUserTestCase):
             }
             }
         )
         )
         self.assertEqual(response.status_code, 400)
         self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            'title': ['You have to enter thread title.'],
+            'post': ['You have to enter a message.'],
+        })
 
 
         response = self.client.post(
         response = self.client.post(
             self.api_link, data={
             self.api_link, data={
@@ -74,3 +84,7 @@ class ValidatePostTests(AuthenticatedUserTestCase):
             }
             }
         )
         )
         self.assertEqual(response.status_code, 400)
         self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            'title': ['This field may not be blank.'],
+            'post': ['This field may not be blank.'],
+        })