支持供应商简称维护和订单PDF下载命名
This commit is contained in:
+39
-1
@@ -7,6 +7,44 @@ import pytest
|
||||
SCHEMA = Path(__file__).parent / 'fixtures' / 'legacy_schema.sql'
|
||||
|
||||
|
||||
def test_v4_supplier_alias_upgrade_preserves_orders_and_creates_one_backup(tmp_path):
|
||||
from models import Order, OrderVersion, Supplier, init_db
|
||||
path = tmp_path / 'po.db'
|
||||
engine, factory = init_db(str(path))
|
||||
archived = b'%PDF-1.4 immutable before alias update'
|
||||
with factory() as db:
|
||||
db.add(Supplier(name='旧供应商', code='S01', contact='原联系人'))
|
||||
db.add(Order(id=1, order_no='V4-ORDER', status='approved', revision=2,
|
||||
payment_status='partial', invoice_status='received', delivery_status='delivered'))
|
||||
db.flush()
|
||||
db.add(OrderVersion(order_id=1, revision=2, content_json='{}', pdf_data=archived,
|
||||
pdf_sha256='existing-digest', template_version='po-v4'))
|
||||
db.commit()
|
||||
engine.dispose()
|
||||
with sqlite3.connect(path) as con:
|
||||
con.execute('ALTER TABLE suppliers DROP COLUMN short_name')
|
||||
con.execute('PRAGMA user_version=4')
|
||||
old_orders = con.execute('SELECT * FROM orders').fetchall()
|
||||
old_archives = con.execute('SELECT * FROM order_versions').fetchall()
|
||||
engine, factory = init_db(str(path))
|
||||
with factory() as db:
|
||||
supplier = db.query(Supplier).one()
|
||||
assert (supplier.name, supplier.code, supplier.contact, supplier.short_name) == ('旧供应商', 'S01', '原联系人', '')
|
||||
engine.dispose()
|
||||
with sqlite3.connect(path) as con:
|
||||
assert con.execute('PRAGMA user_version').fetchone()[0] == 5
|
||||
assert con.execute('SELECT * FROM orders').fetchall() == old_orders
|
||||
assert con.execute('SELECT * FROM order_versions').fetchall() == old_archives
|
||||
backups = list(tmp_path.glob('*.bak'))
|
||||
assert len(backups) == 1
|
||||
with sqlite3.connect(backups[0]) as con:
|
||||
assert con.execute('PRAGMA user_version').fetchone()[0] == 4
|
||||
assert 'short_name' not in {row[1] for row in con.execute('PRAGMA table_info(suppliers)')}
|
||||
engine, _ = init_db(str(path))
|
||||
engine.dispose()
|
||||
assert len(list(tmp_path.glob('*.bak'))) == 1
|
||||
|
||||
|
||||
def test_v3_tracking_upgrade_preserves_existing_state_and_archives(tmp_path):
|
||||
import hashlib
|
||||
from models import Order, OrderVersion, User, init_db
|
||||
@@ -48,7 +86,7 @@ def test_v3_tracking_upgrade_preserves_existing_state_and_archives(tmp_path):
|
||||
assert con.execute('PRAGMA user_version').fetchone()[0] == 3
|
||||
assert 'payment_status' not in {row[1] for row in con.execute('PRAGMA table_info(orders)')}
|
||||
with sqlite3.connect(path) as con:
|
||||
assert con.execute('PRAGMA user_version').fetchone()[0] == 4
|
||||
assert con.execute('PRAGMA user_version').fetchone()[0] == 5
|
||||
assert con.execute('PRAGMA integrity_check').fetchone()[0] == 'ok'
|
||||
engine, _ = init_db(str(path))
|
||||
engine.dispose()
|
||||
|
||||
Reference in New Issue
Block a user