mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
pytest: allow db_query to manipulate db.
Needed for the next test. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
c5b5f74965
commit
6e10237d10
@@ -379,13 +379,16 @@ class LightningNode(object):
|
|||||||
def getactivechannels(self):
|
def getactivechannels(self):
|
||||||
return [c for c in self.rpc.listchannels()['channels'] if c['active']]
|
return [c for c in self.rpc.listchannels()['channels'] if c['active']]
|
||||||
|
|
||||||
def db_query(self, query):
|
def db_query(self, query, use_copy=True):
|
||||||
from shutil import copyfile
|
|
||||||
orig = os.path.join(self.daemon.lightning_dir, "lightningd.sqlite3")
|
orig = os.path.join(self.daemon.lightning_dir, "lightningd.sqlite3")
|
||||||
copy = os.path.join(self.daemon.lightning_dir, "lightningd-copy.sqlite3")
|
if use_copy:
|
||||||
copyfile(orig, copy)
|
from shutil import copyfile
|
||||||
|
copy = os.path.join(self.daemon.lightning_dir, "lightningd-copy.sqlite3")
|
||||||
|
copyfile(orig, copy)
|
||||||
|
db = sqlite3.connect(copy)
|
||||||
|
else:
|
||||||
|
db = sqlite3.connect(orig)
|
||||||
|
|
||||||
db = sqlite3.connect(copy)
|
|
||||||
db.row_factory = sqlite3.Row
|
db.row_factory = sqlite3.Row
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
c.execute(query)
|
c.execute(query)
|
||||||
@@ -395,6 +398,7 @@ class LightningNode(object):
|
|||||||
for row in rows:
|
for row in rows:
|
||||||
result.append(dict(zip(row.keys(), row)))
|
result.append(dict(zip(row.keys(), row)))
|
||||||
|
|
||||||
|
db.commit()
|
||||||
c.close()
|
c.close()
|
||||||
db.close()
|
db.close()
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user