完善采购审批流程、企业微信通知和采购专用章
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import importlib.util
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_backup_and_restore_snapshot(tmp_path):
|
||||
source = Path(__file__).resolve().parents[1] / 'tools' / 'backup_db.py'
|
||||
spec = importlib.util.spec_from_file_location('backup_tool', source)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
instance = tmp_path / 'instance'
|
||||
instance.mkdir()
|
||||
path = instance / 'po.db'
|
||||
with sqlite3.connect(path) as db:
|
||||
db.execute('CREATE TABLE orders(id INTEGER PRIMARY KEY, amount INTEGER)')
|
||||
db.execute('INSERT INTO orders(amount) VALUES(66)')
|
||||
snapshot = module.backup_database(tmp_path)
|
||||
with sqlite3.connect(path) as db:
|
||||
db.execute('UPDATE orders SET amount=100')
|
||||
with sqlite3.connect(snapshot) as db:
|
||||
assert db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok'
|
||||
assert db.execute('SELECT amount FROM orders').fetchone()[0] == 66
|
||||
with sqlite3.connect(tmp_path / 'restored.db') as restored:
|
||||
db.backup(restored)
|
||||
assert restored.execute('SELECT amount FROM orders').fetchone()[0] == 66
|
||||
Reference in New Issue
Block a user