|
|
@ -1,19 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
import isso
|
|
|
|
|
|
|
|
from isso.models import Comment
|
|
|
|
from isso.models import Comment
|
|
|
|
from isso.db import SQLite
|
|
|
|
from isso.db import SQLite
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def comment(**kw):
|
|
|
|
|
|
|
|
return Comment.fromjson(json.dumps(kw))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSQLite(unittest.TestCase):
|
|
|
|
class TestSQLite(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
@ -23,61 +17,59 @@ class TestSQLite(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def test_get(self):
|
|
|
|
def test_get(self):
|
|
|
|
|
|
|
|
|
|
|
|
rv = self.db.add('/', comment(text='Spam'), '')
|
|
|
|
rv = self.db.add('/', Comment(text='Spam'), '')
|
|
|
|
c = self.db.get('/', rv.id)
|
|
|
|
c = self.db.get('/', rv["id"])
|
|
|
|
|
|
|
|
|
|
|
|
assert c.id == 1
|
|
|
|
assert c["id"] == 1
|
|
|
|
assert c.text == 'Spam'
|
|
|
|
assert c["text"] == 'Spam'
|
|
|
|
|
|
|
|
|
|
|
|
def test_add(self):
|
|
|
|
def test_add(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.db.add('/', comment(text='Foo'), '')
|
|
|
|
self.db.add('/', Comment(text='Foo'), '')
|
|
|
|
self.db.add('/', comment(text='Bar'), '')
|
|
|
|
self.db.add('/', Comment(text='Bar'), '')
|
|
|
|
self.db.add('/path/', comment(text='Baz'), '')
|
|
|
|
self.db.add('/path/', Comment(text='Baz'), '')
|
|
|
|
|
|
|
|
|
|
|
|
rv = list(self.db.retrieve('/'))
|
|
|
|
rv = list(self.db.retrieve('/'))
|
|
|
|
assert rv[0].id == 1
|
|
|
|
assert rv[0]["id"] == 1
|
|
|
|
assert rv[0].path == '/'
|
|
|
|
assert rv[0]["text"] == 'Foo'
|
|
|
|
assert rv[0].text == 'Foo'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert rv[1].id == 2
|
|
|
|
assert rv[1]["id"] == 2
|
|
|
|
assert rv[1].text == 'Bar'
|
|
|
|
assert rv[1]["text"] == 'Bar'
|
|
|
|
|
|
|
|
|
|
|
|
rv = list(self.db.retrieve('/path/'))
|
|
|
|
rv = list(self.db.retrieve('/path/'))
|
|
|
|
assert rv[0].id == 1
|
|
|
|
assert rv[0]["id"] == 1
|
|
|
|
assert rv[0].path == '/path/'
|
|
|
|
assert rv[0]["text"] == 'Baz'
|
|
|
|
assert rv[0].text == 'Baz'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_return(self):
|
|
|
|
def test_add_return(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.db.add('/', comment(text='1'), '')
|
|
|
|
self.db.add('/', Comment(text='1'), '')
|
|
|
|
self.db.add('/', comment(text='2'), '')
|
|
|
|
self.db.add('/', Comment(text='2'), '')
|
|
|
|
|
|
|
|
|
|
|
|
assert self.db.add('/path/', comment(text='1'), '').id == 1
|
|
|
|
assert self.db.add('/path/', Comment(text='1'), '')["id"] == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_update(self):
|
|
|
|
def test_update(self):
|
|
|
|
|
|
|
|
|
|
|
|
rv = self.db.add('/', comment(text='Foo'), '')
|
|
|
|
rv = self.db.add('/', Comment(text='Foo'), '')
|
|
|
|
time.sleep(0.1)
|
|
|
|
time.sleep(0.1)
|
|
|
|
rv = self.db.update('/', rv.id, comment(text='Bla'))
|
|
|
|
rv = self.db.update('/', rv["id"], {"text": "Bla"})
|
|
|
|
c = self.db.get('/', rv.id)
|
|
|
|
c = self.db.get('/', rv["id"])
|
|
|
|
|
|
|
|
|
|
|
|
assert c.id == 1
|
|
|
|
assert c["id"] == 1
|
|
|
|
assert c.text == 'Bla'
|
|
|
|
assert c["text"] == 'Bla'
|
|
|
|
assert c.created < c.modified
|
|
|
|
assert c["created"] < c["modified"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete(self):
|
|
|
|
def test_delete(self):
|
|
|
|
|
|
|
|
|
|
|
|
rv = self.db.add('/', comment(
|
|
|
|
rv = self.db.add('/', Comment(
|
|
|
|
text='F**CK', author='P*NIS', website='http://somebadhost.org/'), '')
|
|
|
|
text='F**CK', author='P*NIS', website='http://somebadhost.org/'), '')
|
|
|
|
assert self.db.delete('/', rv.id) == None
|
|
|
|
assert self.db.delete('/', rv["id"]) == None
|
|
|
|
|
|
|
|
|
|
|
|
def test_recent(self):
|
|
|
|
def test_recent(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.db.add('/path/', comment(text='2'), '')
|
|
|
|
self.db.add('/path/', Comment(text='2'), '')
|
|
|
|
|
|
|
|
|
|
|
|
for x in range(5):
|
|
|
|
for x in range(5):
|
|
|
|
self.db.add('/', comment(text='%i' % (x+1)), '')
|
|
|
|
self.db.add('/', Comment(text='%i' % (x+1)), '')
|
|
|
|
|
|
|
|
|
|
|
|
assert len(list(self.db.recent(mode=7))) == 6
|
|
|
|
assert len(list(self.db.recent(mode=7))) == 6
|
|
|
|
assert len(list(self.db.recent(mode=7, limit=5))) == 5
|
|
|
|
assert len(list(self.db.recent(mode=7, limit=5))) == 5
|
|
|
@ -95,13 +87,13 @@ class TestSQLitePending(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def test_retrieve(self):
|
|
|
|
def test_retrieve(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.db.add('/', comment(text='Foo'), '')
|
|
|
|
self.db.add('/', Comment(text='Foo'), '')
|
|
|
|
assert len(list(self.db.retrieve('/'))) == 0
|
|
|
|
assert len(list(self.db.retrieve('/'))) == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_activate(self):
|
|
|
|
def test_activate(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.db.add('/', comment(text='Foo'), '')
|
|
|
|
self.db.add('/', Comment(text='Foo'), '')
|
|
|
|
self.db.add('/', comment(text='Bar'), '')
|
|
|
|
self.db.add('/', Comment(text='Bar'), '')
|
|
|
|
self.db.activate('/', 2)
|
|
|
|
self.db.activate('/', 2)
|
|
|
|
|
|
|
|
|
|
|
|
assert len(list(self.db.retrieve('/'))) == 1
|
|
|
|
assert len(list(self.db.retrieve('/'))) == 1
|
|
|
|