replace db.initialize with db.__init__
This commit is contained in:
parent
98c4b6ccb2
commit
8301f0af78
@ -26,7 +26,7 @@ from werkzeug.serving import run_simple
|
|||||||
from werkzeug.wrappers import Request, Response
|
from werkzeug.wrappers import Request, Response
|
||||||
from werkzeug.exceptions import HTTPException, NotFound, NotImplemented, InternalServerError
|
from werkzeug.exceptions import HTTPException, NotFound, NotImplemented, InternalServerError
|
||||||
|
|
||||||
from isso import admin, comments
|
from isso import admin, comments, db
|
||||||
|
|
||||||
url_map = Map([
|
url_map = Map([
|
||||||
# moderation panel
|
# moderation panel
|
||||||
@ -42,8 +42,8 @@ url_map = Map([
|
|||||||
class Isso:
|
class Isso:
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
|
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
self.db = db.SQLite(conf)
|
||||||
|
|
||||||
def dispatch(self, request, start_response):
|
def dispatch(self, request, start_response):
|
||||||
adapter = url_map.bind_to_environ(request.environ)
|
adapter = url_map.bind_to_environ(request.environ)
|
||||||
|
@ -3,8 +3,6 @@ import abc
|
|||||||
import time
|
import time
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from os.path import join
|
|
||||||
|
|
||||||
from isso.models import Comment
|
from isso.models import Comment
|
||||||
|
|
||||||
|
|
||||||
@ -13,7 +11,7 @@ class Abstract:
|
|||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def initialize(self, conf):
|
def __init__(self, conf):
|
||||||
return
|
return
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@ -48,7 +46,7 @@ class SQLite(Abstract):
|
|||||||
'text', 'author', 'email', 'website', 'parent', 'mode'
|
'text', 'author', 'email', 'website', 'parent', 'mode'
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialize(self, conf):
|
def __init__(self, conf):
|
||||||
|
|
||||||
self.dbpath = conf['SQLITE']
|
self.dbpath = conf['SQLITE']
|
||||||
self.mode = 1 if conf.get('MODERATION') else 0
|
self.mode = 1 if conf.get('MODERATION') else 0
|
||||||
@ -82,7 +80,7 @@ class SQLite(Abstract):
|
|||||||
with sqlite3.connect(self.dbpath) as con:
|
with sqlite3.connect(self.dbpath) as con:
|
||||||
keys = ','.join(self.fields)
|
keys = ','.join(self.fields)
|
||||||
values = ','.join('?'*len(self.fields))
|
values = ','.join('?'*len(self.fields))
|
||||||
x = con.execute('INSERT INTO comments (%s) VALUES (%s);' % (keys, values), (
|
con.execute('INSERT INTO comments (%s) VALUES (%s);' % (keys, values), (
|
||||||
0, path, c.created, c.modified, c.text, c.author, c.email, c.website,
|
0, path, c.created, c.modified, c.text, c.author, c.email, c.website,
|
||||||
c.parent, self.mode)
|
c.parent, self.mode)
|
||||||
)
|
)
|
||||||
|
@ -18,8 +18,7 @@ class TestSQLite(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
fd, self.path = tempfile.mkstemp()
|
fd, self.path = tempfile.mkstemp()
|
||||||
self.db = SQLite()
|
self.db = SQLite({'SQLITE': self.path})
|
||||||
self.db.initialize({'SQLITE': self.path})
|
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user