mirror of https://github.com/zulip/zulip.git
tests.py: Add assert_json_error_contains
(imported from commit 5a241af5071b6e711b56f84f56a1ed1f7e7dc262)
This commit is contained in:
parent
3455e37160
commit
16de6e43fe
|
@ -88,15 +88,21 @@ class AuthedTestCase(TestCase):
|
||||||
# empty value.
|
# empty value.
|
||||||
self.assertIn("msg", json)
|
self.assertIn("msg", json)
|
||||||
|
|
||||||
|
def get_json_error(self, result):
|
||||||
|
self.assertEquals(result.status_code, 400)
|
||||||
|
json = simplejson.loads(result.content)
|
||||||
|
self.assertEquals(json.get("result"), "error")
|
||||||
|
return json['msg']
|
||||||
|
|
||||||
def assert_json_error(self, result, msg):
|
def assert_json_error(self, result, msg):
|
||||||
"""
|
"""
|
||||||
Invalid POSTs return a 400 and JSON of the form {"result": "error",
|
Invalid POSTs return a 400 and JSON of the form {"result": "error",
|
||||||
"msg": "reason"}.
|
"msg": "reason"}.
|
||||||
"""
|
"""
|
||||||
self.assertEquals(result.status_code, 400)
|
self.assertEquals(self.get_json_error(result), msg)
|
||||||
json = simplejson.loads(result.content)
|
|
||||||
self.assertEquals(json.get("result"), "error")
|
def assert_json_error_contains(self, result, msg_substring):
|
||||||
self.assertEquals(json.get("msg"), msg)
|
self.assertIn(msg_substring, self.get_json_error(result))
|
||||||
|
|
||||||
class PublicURLTest(TestCase):
|
class PublicURLTest(TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue