Browse Source

Remove assertContains from markdown api tests

rafalp 6 years ago
parent
commit
1dc5c072cd
1 changed files with 40 additions and 14 deletions
  1. 40 14
      misago/markup/tests/test_api.py

+ 40 - 14
misago/markup/tests/test_api.py

@@ -14,46 +14,72 @@ class ParseMarkupApiTests(AuthenticatedUserTestCase):
         self.logout_user()
         self.logout_user()
 
 
         response = self.client.post(self.api_link)
         response = self.client.post(self.api_link)
-        self.assertContains(response, "This action is not available to guests.", status_code=403)
+        self.assertEqual(response.status_code, 403)
+        self.assertEqual(response.json(), {
+            "detail": "This action is not available to guests.",
+        })
 
 
     def test_no_data(self):
     def test_no_data(self):
         """api handles no data"""
         """api handles no data"""
         response = self.client.post(self.api_link)
         response = self.client.post(self.api_link)
-        self.assertContains(response, "You have to enter a message.", status_code=400)
+        self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            "detail": "You have to enter a message.",
+        })
 
 
     def test_invalid_data(self):
     def test_invalid_data(self):
         """api handles post that is invalid type"""
         """api handles post that is invalid type"""
         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.",
+        })
 
 
         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.",
+        })
 
 
         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.",
+        })
 
 
         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_empty_post(self):
     def test_empty_post(self):
         """api handles empty post"""
         """api handles empty post"""
         response = self.client.post(self.api_link, {'post': ''})
         response = self.client.post(self.api_link, {'post': ''})
-        self.assertContains(response, "You have to enter a message.", status_code=400)
+        self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            "detail": "You have to enter a message.",
+        })
 
 
         # regression test for #929
         # regression test for #929
         response = self.client.post(self.api_link, {'post': '\n'})
         response = self.client.post(self.api_link, {'post': '\n'})
-        self.assertContains(response, "You have to enter a message.", status_code=400)
+        self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            "detail": "You have to enter a message.",
+        })
 
 
     def test_invalid_post(self):
     def test_invalid_post(self):
         """api handles invalid post type"""
         """api handles invalid post type"""
         response = self.client.post(self.api_link, {'post': 123})
         response = self.client.post(self.api_link, {'post': 123})
-        self.assertContains(
-            response,
-            "Posted message should be at least 5 characters long (it has 3).",
-            status_code=400
-        )
+        self.assertEqual(response.status_code, 400)
+        self.assertEqual(response.json(), {
+            "detail": "Posted message should be at least 5 characters long (it has 3).",
+        })
 
 
     def test_valid_post(self):
     def test_valid_post(self):
         """api returns parsed markup for valid post"""
         """api returns parsed markup for valid post"""
         response = self.client.post(self.api_link, {'post': 'Lorem ipsum dolor met!'})
         response = self.client.post(self.api_link, {'post': 'Lorem ipsum dolor met!'})
-        self.assertContains(response, "<p>Lorem ipsum dolor met!</p>")
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.json(), {
+            "parsed": "<p>Lorem ipsum dolor met!</p>",
+        })