diff --git a/isso/db.py b/isso/db.py index bc6cb94..ad67f41 100644 --- a/isso/db.py +++ b/isso/db.py @@ -118,9 +118,9 @@ class SQLite(Abstract): def delete(self, path, id): with sqlite3.connect(self.dbpath) as con: - refs = con.execute('SELECT id FROM comments WHERE id=?', (id, )).fetchone() + refs = con.execute('SELECT * FROM comments WHERE parent=?', (id, )).fetchone() - if len(refs) == 0: + if refs is None: con.execute('DELETE FROM comments WHERE path=? AND id=?', (path, id)) return None diff --git a/specs/test_comment.py b/specs/test_comment.py index 7c47249..b2de96c 100644 --- a/specs/test_comment.py +++ b/specs/test_comment.py @@ -84,7 +84,9 @@ class TestComments(unittest.TestCase): def testDelete(self): self.post('/comment/path/new', data=json.dumps(comment(text='Lorem ipsum ...'))) - assert self.delete('/comment/path/1').status_code == 200 + r = self.delete('/comment/path/1') + assert r.status_code == 200 + assert json.loads(r.data) == None assert self.get('/comment/path/1').status_code == 404 def testDeleteWithReference(self): @@ -92,6 +94,9 @@ class TestComments(unittest.TestCase): self.post('/comment/path/new', data=json.dumps(comment(text='First'))) self.post('/comment/path/new', data=json.dumps(comment(text='Second', parent=1))) - r = self.delete('/comment/path/2') + r = self.delete('/comment/path/1') assert r.status_code == 200 assert Comment(**json.loads(r.data)).deleted + + assert self.get('/comment/path/1').status_code == 200 + assert self.get('/comment/path/2').status_code == 200 diff --git a/specs/test_db.py b/specs/test_db.py index 9e4a46d..93e2b73 100644 --- a/specs/test_db.py +++ b/specs/test_db.py @@ -60,14 +60,7 @@ class TestSQLite(unittest.TestCase): rv = self.db.add('/', comment( text='F**CK', author='P*NIS', website='http://somebadhost.org/')) - - self.db.delete('/', rv.id) - c = self.db.get('/', rv.id) - - assert c.id == 1 - assert c.text == '' - assert c.author is None - assert c.website is None + assert self.db.delete('/', rv.id) == None def tearDown(self): os.unlink(self.path)