remove stale threads after all comments have been deleted
This commit is contained in:
parent
a658021f7e
commit
e08e7be464
@ -20,6 +20,13 @@ class SQLite3:
|
||||
self.threads = Threads(self)
|
||||
self.comments = Comments(self)
|
||||
|
||||
self.execute([
|
||||
'CREATE TRIGGER IF NOT EXISTS remove_stale_threads',
|
||||
'AFTER DELETE ON comments',
|
||||
'BEGIN',
|
||||
' DELETE FROM threads WHERE id NOT IN (SELECT tid FROM comments);',
|
||||
'END'])
|
||||
|
||||
def execute(self, sql, args=()):
|
||||
|
||||
if isinstance(sql, (list, tuple)):
|
||||
|
@ -151,12 +151,14 @@ class TestComments(unittest.TestCase):
|
||||
r = client.delete('/id/1')
|
||||
assert r.status_code == 200
|
||||
assert loads(r.data)['mode'] == 4
|
||||
assert '/path/' in self.app.db.threads
|
||||
|
||||
assert self.get('/?uri=%2Fpath%2F&id=1').status_code == 200
|
||||
assert self.get('/?uri=%2Fpath%2F&id=2').status_code == 200
|
||||
|
||||
r = client.delete('/id/2')
|
||||
assert self.get('/?uri=%2Fpath%2F').status_code == 404
|
||||
assert '/path/' not in self.app.db.threads
|
||||
|
||||
def testDeleteWithMultipleReferences(self):
|
||||
"""
|
||||
@ -270,6 +272,13 @@ class TestComments(unittest.TestCase):
|
||||
self.put('/id/1', data=json.dumps({"text": "Typo"}))
|
||||
assert loads(self.get('/id/1').data)["text"] == "<p>Typo</p>\n"
|
||||
|
||||
def testDeleteCommentRemovesThread(self):
|
||||
|
||||
rv = self.client.post('/new?uri=%2F', data=json.dumps({"text": "..."}))
|
||||
assert '/' in self.app.db.threads
|
||||
self.client.delete('/id/1')
|
||||
assert '/' not in self.app.db.threads
|
||||
|
||||
|
||||
class TestModeratedComments(unittest.TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user