delete only when not referenced

pull/16/head
posativ 12 years ago
parent af8fcdab19
commit 27801eef26

@ -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

@ -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

@ -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)

Loading…
Cancel
Save