improve tests for comment field validation
This commit is contained in:
parent
5efa81b57e
commit
16d085c9d1
@ -107,10 +107,22 @@ class TestComments(unittest.TestCase):
|
|||||||
|
|
||||||
def testVerifyFields(self):
|
def testVerifyFields(self):
|
||||||
|
|
||||||
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': ''}))
|
verify = lambda comment: comments.API.verify(comment)[0]
|
||||||
self.assertEqual(rv.status_code, 400)
|
|
||||||
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': "\n\n\n"}))
|
# text is missing
|
||||||
self.assertEqual(rv.status_code, 400)
|
self.assertFalse(verify({}))
|
||||||
|
|
||||||
|
# invalid types
|
||||||
|
self.assertFalse(verify({"text": "...", "parent": "xxx"}))
|
||||||
|
for key in ("author", "website", "email"):
|
||||||
|
self.assertFalse(verify({"text": True, key: 3.14}))
|
||||||
|
|
||||||
|
# text too short and/or blank
|
||||||
|
for text in ("", "\n\n\n"):
|
||||||
|
self.assertFalse(verify({"text": text}))
|
||||||
|
|
||||||
|
# email length
|
||||||
|
self.assertFalse(verify({"text": "...", "email": "*"*1024}))
|
||||||
|
|
||||||
def testGetInvalid(self):
|
def testGetInvalid(self):
|
||||||
|
|
||||||
@ -230,7 +242,7 @@ class TestComments(unittest.TestCase):
|
|||||||
|
|
||||||
def testVisibleFields(self):
|
def testVisibleFields(self):
|
||||||
|
|
||||||
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({"text": "..."}))
|
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({"text": "...", "invalid": "field"}))
|
||||||
self.assertEqual(rv.status_code, 201)
|
self.assertEqual(rv.status_code, 201)
|
||||||
|
|
||||||
rv = loads(rv.data)
|
rv = loads(rv.data)
|
||||||
|
Loading…
Reference in New Issue
Block a user