auto-correct wrong/invalid parent to max nesting level of 1
This commit is contained in:
parent
ce14726f2f
commit
1e5878bec3
@ -38,10 +38,10 @@ class Comments:
|
||||
database values.
|
||||
"""
|
||||
|
||||
if "parent" in c:
|
||||
rv = self.db.execute("SELECT parent FROM comments WHERE id=?", (c.get('parent'), )).fetchone()
|
||||
if rv and rv[0] is not None:
|
||||
c["parent"] = None
|
||||
if c.get("parent") is not None:
|
||||
ref = self.get(c["parent"])
|
||||
if ref.get("parent") is not None:
|
||||
c["parent"] = ref["parent"]
|
||||
|
||||
self.db.execute([
|
||||
'INSERT INTO comments (',
|
||||
|
@ -105,6 +105,14 @@ class TestComments(unittest.TestCase):
|
||||
rv = loads(r.data)
|
||||
self.assertEqual(len(rv), 20)
|
||||
|
||||
def testCreateInvalidParent(self):
|
||||
|
||||
self.post('/new?uri=test', data=json.dumps({'text': '...'}))
|
||||
self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 1}))
|
||||
invalid = self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 2}))
|
||||
|
||||
self.assertEqual(loads(invalid.data)["parent"], 1)
|
||||
|
||||
def testVerifyFields(self):
|
||||
|
||||
verify = lambda comment: comments.API.verify(comment)[0]
|
||||
@ -177,18 +185,15 @@ class TestComments(unittest.TestCase):
|
||||
|
|
||||
--- [ comment 2, ref 1 ]
|
||||
|
|
||||
--- [ comment 3, ref 2 ]
|
||||
|
|
||||
--- [ comment 4, ref 2 ]
|
||||
[ comment 5 ]
|
||||
--- [ comment 3, ref 1 ]
|
||||
[ comment 4 ]
|
||||
"""
|
||||
client = JSONClient(self.app, Response)
|
||||
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'First'}))
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Second', 'parent': 1}))
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Third 1', 'parent': 2}))
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Third 2', 'parent': 2}))
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': '...'}))
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Third', 'parent': 1}))
|
||||
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Last'}))
|
||||
|
||||
client.delete('/id/1')
|
||||
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 200)
|
||||
@ -197,8 +202,6 @@ class TestComments(unittest.TestCase):
|
||||
client.delete('/id/3')
|
||||
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 200)
|
||||
client.delete('/id/4')
|
||||
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 200)
|
||||
client.delete('/id/5')
|
||||
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 404)
|
||||
|
||||
def testPathVariations(self):
|
||||
|
Loading…
Reference in New Issue
Block a user