1
0
mirror of http://git.k-space.ee/arti/doors.git synced 2024-11-12 15:30:59 +02:00

Teach DB to create schema in existing connection

This commit is contained in:
Arti Zirk 2020-10-08 20:43:48 +03:00
parent ea3d617e9c
commit 7878cadb30
2 changed files with 10 additions and 1 deletions

View File

@ -51,7 +51,10 @@ class DB:
@staticmethod
def create_db(dbfile):
db = sqlite3.connect(dbfile)
if type(dbfile) is DB:
db = dbfile.db
else:
db = sqlite3.connect(dbfile)
db.executescript("""
create table versions (
version integer,

View File

@ -4,9 +4,15 @@ from kdoorweb.db import DB
class TestDB(unittest.TestCase):
def setUp(self) -> None:
self.db = DB()
def test_create_db_in_memory(self):
DB.create_db(dbfile=":memory:")
def test_create_db_in_connection(self):
DB.create_db(dbfile=self.db)
if __name__ == '__main__':
unittest.main()