From 16d085c9d1201475042a150880c3868408e6a4c0 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Tue, 4 Feb 2014 15:34:02 +0100 Subject: [PATCH] improve tests for comment field validation --- specs/test_comments.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/specs/test_comments.py b/specs/test_comments.py index fa81c9e..9291cf6 100644 --- a/specs/test_comments.py +++ b/specs/test_comments.py @@ -107,10 +107,22 @@ class TestComments(unittest.TestCase): def testVerifyFields(self): - rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': ''})) - self.assertEqual(rv.status_code, 400) - rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': "\n\n\n"})) - self.assertEqual(rv.status_code, 400) + verify = lambda comment: comments.API.verify(comment)[0] + + # text is missing + 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): @@ -230,7 +242,7 @@ class TestComments(unittest.TestCase): 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) rv = loads(rv.data)